Adds commands and queries validators unit tests

This commit is contained in:
BinaryAlley committed 2026-08-15 06:35:07 -07:00
1 parent 7f335b70f1
commit f393b93ce7
25 files changed
+1553 -307

No files matched your search

@@ -0,0 +1,216 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Commands.AddLibrary;
/// <summary>
/// Contains unit tests for the <see cref="AddLibraryCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddLibraryCommandValidatorTests
{
private readonly AddLibraryCommandValidator _validator = new();
private readonly AddLibraryCommandFixture _addLibraryCommandFixture = new();
[Fact]
public void Validate_WhenLibraryTypeIsNull_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { LibraryType = null! };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryTypeCannotBeNull);
}
[Fact]
public void Validate_WhenLibraryTypeIsUnknown_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { LibraryType = "UnknownLibraryType" };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.UnknownLibraryType);
}
[Fact]
public void Validate_WhenLibraryTypeIsValid_ShouldNotHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { LibraryType = "Book" };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.UnknownLibraryType);
}
[Fact]
public void Validate_WhenContentLocationsIsNull_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { ContentLocations = null! };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.PathsListCannotBeNull);
}
[Fact]
public void Validate_WhenContentLocationsIsEmpty_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { ContentLocations = [] };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.PathsListCannotBeEmpty);
}
[Fact]
public void Validate_WhenContentLocationIsEmpty_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { ContentLocations = [string.Empty] };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
public void Validate_WhenContentLocationExceeds260Characters_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { ContentLocations = [new string('a', 261)] };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathMustBeMaximum260CharactersLong);
}
[Fact]
public void Validate_WhenContentLocationsAreValid_ShouldNotHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.PathsListCannotBeNull);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleIsNull_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { Title = null! };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleIsEmpty_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { Title = string.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleIsWhitespace_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { Title = " " };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleExceeds255Characters_ShouldHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
command = command with { Title = new string('a', 256) };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleMustBeMaximum255CharactersLong);
}
[Fact]
public void Validate_WhenTitleIsValid_ShouldNotHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.TitleCannotBeEmpty);
result.ShouldNotHaveValidationError(Errors.Library.TitleMustBeMaximum255CharactersLong);
}
[Fact]
public void Validate_WhenCommandIsValid_ShouldNotHaveValidationError()
{
// Arrange
AddLibraryCommand command = _addLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,89 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
/// <summary>
/// Contains unit tests for the <see cref="CancelLibraryScanCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CancelLibraryScanCommandValidatorTests
{
private readonly CancelLibraryScanCommandValidator _validator = new();
private readonly CancelLibraryScanCommandFixture _cancelLibraryScanCommandFixture = new();
[Fact]
public void Validate_WhenLibraryIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
command = command with { LibraryId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenLibraryIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenScanIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
command = command with { ScanId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.LibraryScanning.ScanIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenScanIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.LibraryScanning.ScanIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenCommandIsValid_ShouldNotHaveValidationError()
{
// Arrange
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary;
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.DeleteLibrary;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Commands.DeleteLibrary;
/// <summary>
/// Contains unit tests for the <see cref="DeleteLibraryCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteLibraryCommandValidatorTests
{
private readonly DeleteLibraryCommandValidator _validator = new();
private readonly DeleteLibraryCommandFixture _deleteLibraryCommandFixture = new();
[Fact]
public void Validate_WhenIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
command = command with { Id = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.ScanLibrary;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Commands.ScanLibrary;
/// <summary>
/// Contains unit tests for the <see cref="ScanLibraryCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ScanLibraryCommandValidatorTests
{
private readonly ScanLibraryCommandValidator _validator = new();
private readonly ScanLibraryCommandFixture _scanLibraryCommandFixture = new();
[Fact]
public void Validate_WhenIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
command = command with { Id = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,271 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.UpdateLibrary;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Commands.UpdateLibrary;
/// <summary>
/// Contains unit tests for the <see cref="UpdateLibraryCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateLibraryCommandValidatorTests
{
private readonly UpdateLibraryCommandValidator _validator = new();
private readonly UpdateLibraryCommandFixture _updateLibraryCommandFixture = new();
[Fact]
public void Validate_WhenIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { Id = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenOwnerIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { OwnerId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenOwnerIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenLibraryTypeIsNull_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { LibraryType = null! };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryTypeCannotBeNull);
}
[Fact]
public void Validate_WhenLibraryTypeIsUnknown_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { LibraryType = "UnknownLibraryType" };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.UnknownLibraryType);
}
[Fact]
public void Validate_WhenLibraryTypeIsValid_ShouldNotHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { LibraryType = "Book" };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.UnknownLibraryType);
}
[Fact]
public void Validate_WhenContentLocationsIsNull_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { ContentLocations = null! };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.PathsListCannotBeNull);
}
[Fact]
public void Validate_WhenContentLocationsIsEmpty_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { ContentLocations = [] };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.PathsListCannotBeEmpty);
}
[Fact]
public void Validate_WhenContentLocationIsEmpty_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { ContentLocations = [string.Empty] };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
public void Validate_WhenContentLocationExceeds260Characters_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { ContentLocations = [new string('a', 261)] };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathMustBeMaximum260CharactersLong);
}
[Fact]
public void Validate_WhenContentLocationsAreValid_ShouldNotHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.PathsListCannotBeNull);
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleIsNull_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { Title = null! };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleIsEmpty_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { Title = string.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleIsWhitespace_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { Title = " " };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleCannotBeEmpty);
}
[Fact]
public void Validate_WhenTitleExceeds255Characters_ShouldHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
command = command with { Title = new string('a', 256) };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Library.TitleMustBeMaximum255CharactersLong);
}
[Fact]
public void Validate_WhenTitleIsValid_ShouldNotHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.TitleCannotBeEmpty);
result.ShouldNotHaveValidationError(Errors.Library.TitleMustBeMaximum255CharactersLong);
}
[Fact]
public void Validate_WhenCommandIsValid_ShouldNotHaveValidationError()
{
// Arrange
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibrary;
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Queries.GetLibrary;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Queries.GetLibrary;
/// <summary>
/// Contains unit tests for the <see cref="GetLibraryQueryValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryQueryValidatorTests
{
private readonly GetLibraryQueryValidator _validator = new();
private readonly GetLibraryQueryFixture _getLibraryQueryFixture = new();
[Fact]
public void Validate_WhenIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetLibraryQuery query = _getLibraryQueryFixture.Create();
query = query with { Id = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetLibraryQuery query = _getLibraryQueryFixture.Create();
// Act
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,89 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryScanProgress;
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Queries.GetLibraryScanProgress;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Queries.GetLibraryScanProgress;
/// <summary>
/// Contains unit tests for the <see cref="GetLibraryScanProgressQueryValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryScanProgressQueryValidatorTests
{
private readonly GetLibraryScanProgressQueryValidator _validator = new();
private readonly GetLibraryScanProgressQueryFixture _getLibraryScanProgressQueryFixture = new();
[Fact]
public void Validate_WhenLibraryIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
query = query with { LibraryId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenLibraryIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
// Act
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationError(Errors.Library.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenScanIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
query = query with { ScanId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldHaveValidationError(Errors.LibraryScanning.LibraryScanIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenScanIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
// Act
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveValidationError(Errors.LibraryScanning.LibraryScanIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenQueryIsValid_ShouldNotHaveValidationError()
{
// Arrange
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
// Act
List<Error> result = _validator.TestValidate(query);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,104 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
using Lumina.Application.Fixtures.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
/// <summary>
/// Contains unit tests for the <see cref="ReorderLibraryMetadataProvidersCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderLibraryMetadataProvidersCommandValidatorTests
{
private readonly ReorderLibraryMetadataProvidersCommandValidator _validator = new();
private readonly ReorderLibraryMetadataProvidersCommandFixture _reorderLibraryMetadataProvidersCommandFixture = new();
[Fact]
public void Validate_WhenLibraryIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
ReorderLibraryMetadataProvidersCommand command = _reorderLibraryMetadataProvidersCommandFixture.Create();
command = command with { LibraryId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Plugins.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenLibraryIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
ReorderLibraryMetadataProvidersCommand command = _reorderLibraryMetadataProvidersCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Plugins.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenPluginIdsIsNull_ShouldHaveValidationError()
{
// Arrange
ReorderLibraryMetadataProvidersCommand command = _reorderLibraryMetadataProvidersCommandFixture.Create();
command = command with { PluginIds = null! };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Plugins.PluginIdsListCannotBeNull);
}
[Fact]
public void Validate_WhenPluginIdsIsEmpty_ShouldHaveValidationError()
{
// Arrange
ReorderLibraryMetadataProvidersCommand command = _reorderLibraryMetadataProvidersCommandFixture.Create();
command = command with { PluginIds = [] };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Plugins.PluginIdsListCannotBeEmpty);
}
[Fact]
public void Validate_WhenPluginIdsAreValid_ShouldNotHaveValidationError()
{
// Arrange
ReorderLibraryMetadataProvidersCommand command = _reorderLibraryMetadataProvidersCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Plugins.PluginIdsListCannotBeNull);
result.ShouldNotHaveValidationError(Errors.Plugins.PluginIdsListCannotBeEmpty);
}
[Fact]
public void Validate_WhenCommandIsValid_ShouldNotHaveValidationError()
{
// Arrange
ReorderLibraryMetadataProvidersCommand command = _reorderLibraryMetadataProvidersCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,89 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
using Lumina.Application.Fixtures.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
/// <summary>
/// Contains unit tests for the <see cref="SetLibraryMetadataProviderEnabledCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryMetadataProviderEnabledCommandValidatorTests
{
private readonly SetLibraryMetadataProviderEnabledCommandValidator _validator = new();
private readonly SetLibraryMetadataProviderEnabledCommandFixture _setLibraryMetadataProviderEnabledCommandFixture = new();
[Fact]
public void Validate_WhenLibraryIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
SetLibraryMetadataProviderEnabledCommand command = _setLibraryMetadataProviderEnabledCommandFixture.Create();
command = command with { LibraryId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Plugins.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenLibraryIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
SetLibraryMetadataProviderEnabledCommand command = _setLibraryMetadataProviderEnabledCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Plugins.LibraryIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenPluginIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
SetLibraryMetadataProviderEnabledCommand command = _setLibraryMetadataProviderEnabledCommandFixture.Create();
command = command with { PluginId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Plugins.PluginIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenPluginIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
SetLibraryMetadataProviderEnabledCommand command = _setLibraryMetadataProviderEnabledCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveValidationError(Errors.Plugins.PluginIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenCommandIsValid_ShouldNotHaveValidationError()
{
// Arrange
SetLibraryMetadataProviderEnabledCommand command = _setLibraryMetadataProviderEnabledCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
using Lumina.Application.Fixtures.Core.Plugins.Commands.UpdatePluginSettings;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.Plugins.Commands.UpdatePluginSettings;
/// <summary>
/// Contains unit tests for the <see cref="UpdatePluginSettingsCommandValidator"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdatePluginSettingsCommandValidatorTests
{
private readonly UpdatePluginSettingsCommandValidator _validator = new();
private readonly UpdatePluginSettingsCommandFixture _updatePluginSettingsCommandFixture = new();
[Fact]
public void Validate_WhenPluginIdIsEmpty_ShouldHaveValidationError()
{
// Arrange
UpdatePluginSettingsCommand command = _updatePluginSettingsCommandFixture.Create();
command = command with { PluginId = Guid.Empty };
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldHaveValidationError(Errors.Plugins.PluginIdCannotBeEmpty);
}
[Fact]
public void Validate_WhenPluginIdIsValid_ShouldNotHaveValidationError()
{
// Arrange
UpdatePluginSettingsCommand command = _updatePluginSettingsCommandFixture.Create();
// Act
List<Error> result = _validator.TestValidate(command);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}
@@ -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
);
}
}
@@ -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!);
}
}
@@ -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>