mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12: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
+216
@@ -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();
|
||||
}
|
||||
}
|
||||
+89
@@ -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();
|
||||
}
|
||||
}
|
||||
+49
@@ -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();
|
||||
}
|
||||
}
|
||||
+49
@@ -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();
|
||||
}
|
||||
}
|
||||
+271
@@ -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();
|
||||
}
|
||||
}
|
||||
+49
@@ -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();
|
||||
}
|
||||
}
|
||||
+89
@@ -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();
|
||||
}
|
||||
}
|
||||
+104
@@ -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();
|
||||
}
|
||||
}
|
||||
+89
@@ -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();
|
||||
}
|
||||
}
|
||||
+49
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user