mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Adds commands and queries validators unit tests
This commit is contained in:
1 parent
7f335b70f1
commit
f393b93ce7
25 files changed
+1553
-307
No files matched your search
-157
@@ -1,157 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Plugins.Contracts.Core.Metadata;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins.Settings;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.UnitTests.Common.Fakes;
|
||||
|
||||
/// <summary>
|
||||
/// A fake book metadata provider used to exercise the plugin contracts from outside.
|
||||
/// </summary>
|
||||
public sealed class FakeBookMetadataProvider : IPlugin, IPluginServiceRegistrator, IRemoteMetadataProvider<BookMetadataLookupDto, BookMetadataDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the stable unique identifier of the plugin, used to persist its state.
|
||||
/// </summary>
|
||||
public Guid Id { get; } = Guid.Parse("11111111-1111-1111-1111-111111111111");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display name of the plugin.
|
||||
/// </summary>
|
||||
public string Name { get; } = "Fake Book Metadata Provider";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the author of the plugin.
|
||||
/// </summary>
|
||||
public string Author { get; } = "Lumina";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version of the plugin.
|
||||
/// </summary>
|
||||
public Version Version { get; } = new(1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description of the plugin.
|
||||
/// </summary>
|
||||
public string Description { get; } = "A fake metadata provider used to exercise the plugin contracts.";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media library type this metadata provider supports.
|
||||
/// </summary>
|
||||
public LibraryType SupportedLibraryType { get; } = LibraryType.Book;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this metadata provider requires access to the web to retrieve metadata.
|
||||
/// </summary>
|
||||
public bool RequiresWebAccess { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the settings schema of the plugin, used by the host to render the plugin settings page.
|
||||
/// </summary>
|
||||
/// <returns>The collection of setting descriptors declared by the plugin.</returns>
|
||||
public IReadOnlyList<PluginSettingDescriptor> GetSettingsSchema()
|
||||
{
|
||||
return
|
||||
[
|
||||
new PluginSettingDescriptor(
|
||||
Key: "preferredLanguage",
|
||||
Label: "Preferred Language",
|
||||
Type: PluginSettingType.Text,
|
||||
DefaultValue: "en"
|
||||
),
|
||||
new PluginSettingDescriptor(
|
||||
Key: "selectionStrategy",
|
||||
Label: "Selection Strategy",
|
||||
Type: PluginSettingType.Select,
|
||||
DefaultValue: "first",
|
||||
AllowedValues: ["first", "best"]
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers the services of the plugin into the host dependency injection container.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection to which the plugin services are added.</param>
|
||||
public void RegisterServices(IServiceCollection services)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches for the metadata of the media item described by <paramref name="lookup"/>.
|
||||
/// </summary>
|
||||
/// <param name="lookup">The lookup describing the media item to search for.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The collection of metadata candidates found for the media item.</returns>
|
||||
public Task<IReadOnlyList<BookMetadataDto>> GetSearchResultsAsync(BookMetadataLookupDto lookup, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult<IReadOnlyList<BookMetadataDto>>(
|
||||
[
|
||||
CreateMetadata("The Fellowship of the Ring", "3")
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the metadata of the media item described by <paramref name="lookup"/>.
|
||||
/// </summary>
|
||||
/// <param name="lookup">The lookup describing the media item to get the metadata for.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The metadata of the media item, or <see langword="null"/> when no metadata was found.</returns>
|
||||
public Task<BookMetadataDto?> GetMetadataAsync(BookMetadataLookupDto lookup, CancellationToken cancellationToken)
|
||||
{
|
||||
if (lookup.Title is null)
|
||||
return Task.FromResult<BookMetadataDto?>(null);
|
||||
return Task.FromResult<BookMetadataDto?>(CreateMetadata(lookup.Title, "3"));
|
||||
}
|
||||
|
||||
private static BookMetadataDto CreateMetadata(string title, string goodreadsId)
|
||||
{
|
||||
return new BookMetadataDto(
|
||||
Title: title,
|
||||
OriginalTitle: title,
|
||||
Description: "A test description.",
|
||||
ReleaseInfo: new ReleaseInfoDto(
|
||||
OriginalReleaseDate: new DateOnly(1954, 7, 29),
|
||||
OriginalReleaseYear: 1954,
|
||||
ReReleaseDate: null,
|
||||
ReReleaseYear: null,
|
||||
ReleaseCountry: "uk",
|
||||
ReleaseVersion: null
|
||||
),
|
||||
Genres: [new GenreDto("fantasy")],
|
||||
Tags: [new TagDto("epic fantasy")],
|
||||
Language: new LanguageInfoDto("en", "English", "English"),
|
||||
OriginalLanguage: null,
|
||||
Publisher: "Houghton Mifflin",
|
||||
PageCount: 398,
|
||||
Format: BookFormat.Paperback,
|
||||
Edition: null,
|
||||
VolumeNumber: 1,
|
||||
Series: null,
|
||||
ASIN: null,
|
||||
GoodreadsId: goodreadsId,
|
||||
LCCN: null,
|
||||
OCLCNumber: null,
|
||||
OpenLibraryId: null,
|
||||
LibraryThingId: null,
|
||||
GoogleBooksId: null,
|
||||
BarnesAndNobleId: null,
|
||||
AppleBooksId: null,
|
||||
Isbns: null,
|
||||
Contributors: null,
|
||||
Ratings: null,
|
||||
CoverImageUrl: null
|
||||
);
|
||||
}
|
||||
}
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Plugins.Contracts.Core.Metadata;
|
||||
using Lumina.Plugins.Contracts.UnitTests.Common.Fakes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.UnitTests.Core.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IRemoteMetadataProvider"/> contracts.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RemoteMetadataProviderTests
|
||||
{
|
||||
private readonly IRemoteMetadataProvider _sut = new FakeBookMetadataProvider();
|
||||
|
||||
[Fact]
|
||||
public async Task GetMetadataAsync_WhenCalledThroughNonGenericInterface_ShouldReturnTypedMetadata()
|
||||
{
|
||||
// Arrange
|
||||
MetadataLookupDto lookup = new BookMetadataLookupDto(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
Path: "/books/the-fellowship-of-the-ring.epub",
|
||||
Title: "The Fellowship of the Ring");
|
||||
|
||||
// Act
|
||||
MetadataDto? result = await _sut.GetMetadataAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
BookMetadataDto bookMetadata = Assert.IsType<BookMetadataDto>(result);
|
||||
Assert.Equal("The Fellowship of the Ring", bookMetadata.Title);
|
||||
Assert.Equal("3", bookMetadata.GoodreadsId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetMetadataAsync_WhenNoMetadataFound_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
MetadataLookupDto lookup = new BookMetadataLookupDto(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
Path: "/books/unknown.epub");
|
||||
|
||||
// Act
|
||||
MetadataDto? result = await _sut.GetMetadataAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSearchResultsAsync_WhenCalledThroughNonGenericInterface_ShouldReturnTypedResults()
|
||||
{
|
||||
// Arrange
|
||||
MetadataLookupDto lookup = new BookMetadataLookupDto(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
Path: "/books/the-fellowship-of-the-ring.epub",
|
||||
Title: "The Fellowship of the Ring");
|
||||
|
||||
// Act
|
||||
IReadOnlyList<MetadataDto> result = await _sut.GetSearchResultsAsync(lookup, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
BookMetadataDto bookMetadata = Assert.IsType<BookMetadataDto>(result[0]);
|
||||
Assert.Equal("The Fellowship of the Ring", bookMetadata.Title);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins.Settings;
|
||||
using Lumina.Plugins.Contracts.UnitTests.Common.Fakes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.UnitTests.Core.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IPlugin"/> contract.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginTests
|
||||
{
|
||||
private readonly IPlugin _sut = new FakeBookMetadataProvider();
|
||||
|
||||
[Fact]
|
||||
public void GetSettingsSchema_WhenCalled_ShouldReturnDeclaredSettings()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
IReadOnlyList<PluginSettingDescriptor> schema = _sut.GetSettingsSchema();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, schema.Count);
|
||||
Assert.Equal("preferredLanguage", schema[0].Key);
|
||||
Assert.Equal(PluginSettingType.Text, schema[0].Type);
|
||||
Assert.Equal("en", schema[0].DefaultValue);
|
||||
Assert.Equal("selectionStrategy", schema[1].Key);
|
||||
Assert.Equal(PluginSettingType.Select, schema[1].Type);
|
||||
Assert.Contains("first", schema[1].AllowedValues!);
|
||||
}
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="Xunit.CollectionBehaviorAttribute">
|
||||
<_Parameter1>DisableTestParallelization = true</_Parameter1>
|
||||
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Plugins.Contracts\Lumina.Plugins.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user