mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 16:11:10 +00:00
Replaces MVC with FastEndpoints in Lumina.Presentation.Api
This commit is contained in:
1 parent
b1a20716df
commit
c7b8bc2f1c
519 files changed
+15329
-8539
No files matched your search
-168
@@ -1,168 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectoryTree.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetTreeDirectories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeDirectoriesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeDirectoriesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IDirectoryService _mockDirectoryService;
|
||||
private readonly GetTreeDirectoriesQueryHandler _sut;
|
||||
private readonly GetTreeDirectoriesQueryFixture _getTreeDirectoriesQueryFixture;
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockDirectoryService = Substitute.For<IDirectoryService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetTreeDirectoriesQueryHandler(_mockDirectoryService, _mockMapper);
|
||||
_getTreeDirectoriesQueryFixture = new GetTreeDirectoriesQueryFixture();
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalledWithValidQueryWithoutFilesIncluded_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery getDirectoriesQuery = GetTreeDirectoriesQueryFixture.CreateGetTreeDirectoryQuery(false);
|
||||
|
||||
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
|
||||
IEnumerable<FileSystemTreeNodeResponse> directoryResponses = _fileSystemTreeNodeResponseFixture.CreateMany(directories.Count());
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories))
|
||||
.Returns(directoryResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(directoryResponses);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalledWithValidQueryWithFilesIncluded_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery getDirectoriesQuery = GetTreeDirectoriesQueryFixture.CreateGetTreeDirectoryQuery(true);
|
||||
|
||||
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
|
||||
IEnumerable<FileSystemTreeNodeResponse> directoryResponses = _fileSystemTreeNodeResponseFixture.CreateMany(directories.Count());
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories))
|
||||
.Returns(directoryResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(directoryResponses);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenDirectoryServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery query = _fixture.Create<GetTreeDirectoriesQuery>();
|
||||
Error error = Error.Failure("DirectoryService.Error", "An error occurred");
|
||||
_mockDirectoryService.GetSubdirectories(query.Path, query.IncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path, query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenDirectoryServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery query = _fixture.Create<GetTreeDirectoriesQuery>();
|
||||
ErrorOr<IEnumerable<Directory>> emptyList = ErrorOrFactory.From(Enumerable.Empty<Directory>());
|
||||
_mockDirectoryService.GetSubdirectories(query.Path, query.IncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path, query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalledWithNestedDirectories_ShouldReturnCorrectlyNestedResponse()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery query = GetTreeDirectoriesQueryFixture.CreateGetTreeDirectoryQuery(true);
|
||||
IEnumerable<Directory> nestedDirectories = _directoryFixture.CreateManyNested();
|
||||
IEnumerable<FileSystemTreeNodeResponse> nestedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(2, 2, 2);
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(query.Path, query.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(nestedDirectories));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == nestedDirectories))
|
||||
.Returns(nestedResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(nestedResponses, options => options.IncludingNestedObjects());
|
||||
result.Value.Any(r => r.Children.Count != 0).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -3,15 +3,15 @@ using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Directory"/> class.
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="DirectoryResponse"/> class.
|
||||
+9
-9
@@ -1,15 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Models.FileManagement;
|
||||
using Lumina.Contracts.Entities.FileSystemManagement;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemItemModel"/> class.
|
||||
/// Fixture class for the <see cref="FileSystemItemEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemItemModelFixture
|
||||
@@ -17,12 +17,12 @@ public class FileSystemItemModelFixture
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FileSystemItemModel"/>.
|
||||
/// Creates a random valid <see cref="FileSystemItemEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="FileSystemItemModel"/>.</returns>
|
||||
public FileSystemItemModel Create()
|
||||
/// <returns>The created <see cref="FileSystemItemEntity"/>.</returns>
|
||||
public FileSystemItemEntity Create()
|
||||
{
|
||||
return new FileSystemItemModel(
|
||||
return new FileSystemItemEntity(
|
||||
_faker.System.FilePath(),
|
||||
_faker.System.FileName(),
|
||||
_faker.Date.Past(),
|
||||
@@ -31,11 +31,11 @@ public class FileSystemItemModelFixture
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FileSystemItemModel"/>.
|
||||
/// Creates a list of <see cref="FileSystemItemEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<FileSystemItemModel> CreateMany(int count = 3)
|
||||
public List<FileSystemItemEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
|
||||
}
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemTreeNodeResponse"/> class.
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectories.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetDirectoriesQuery"/> class.
|
||||
+44
-33
@@ -3,13 +3,12 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectories.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,7 +18,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoriesQueryHandler"/> class.
|
||||
@@ -28,11 +27,9 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.G
|
||||
public class GetDirectoriesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IDirectoryService _mockDirectoryService;
|
||||
private readonly GetDirectoriesQueryHandler _sut;
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
private readonly DirectoryResponseFixture _directoryResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesQueryHandlerTests"/> class.
|
||||
@@ -41,10 +38,8 @@ public class GetDirectoriesQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockDirectoryService = Substitute.For<IDirectoryService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService, _mockMapper);
|
||||
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService);
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
_directoryResponseFixture = new DirectoryResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -54,23 +49,31 @@ public class GetDirectoriesQueryHandlerTests
|
||||
GetDirectoriesQuery getDirectoriesQuery = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery(false);
|
||||
|
||||
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
|
||||
IEnumerable<DirectoryResponse> directoryResponses = _directoryResponseFixture.CreateMany(directories.Count());
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements)
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
_mockMapper.Map<IEnumerable<DirectoryResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories))
|
||||
.Returns(directoryResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<DirectoryResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(directoryResponses);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<DirectoryResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories));
|
||||
result.Value.Should().HaveCount(directories.Count());
|
||||
|
||||
List<DirectoryResponse> resultList = result.Value.ToList();
|
||||
List<Directory> directoriesList = directories.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(directoriesList[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(directoriesList[i].Name);
|
||||
resultList[i].DateCreated.Should().Be(directoriesList[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(directoriesList[i].DateModified.Value);
|
||||
resultList[i].Items.Should().BeEmpty(); // since files are not included
|
||||
}
|
||||
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -80,23 +83,31 @@ public class GetDirectoriesQueryHandlerTests
|
||||
GetDirectoriesQuery getDirectoriesQuery = GetDirectoriesQueryFixture.CreateGetDirectoriesQuery(true);
|
||||
|
||||
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
|
||||
IEnumerable<DirectoryResponse> directoryResponses = _directoryResponseFixture.CreateMany(directories.Count());
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements)
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
_mockMapper.Map<IEnumerable<DirectoryResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories))
|
||||
.Returns(directoryResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<DirectoryResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(directoryResponses);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path, getDirectoriesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<DirectoryResponse>>(Arg.Is<IEnumerable<Directory>>(d => d == directories));
|
||||
result.Value.Should().HaveCount(directories.Count());
|
||||
|
||||
List<DirectoryResponse> resultList = result.Value.ToList();
|
||||
List<Directory> directoriesList = directories.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(directoriesList[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(directoriesList[i].Name);
|
||||
resultList[i].DateCreated.Should().Be(directoriesList[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(directoriesList[i].DateModified.Value);
|
||||
resultList[i].Items.Should().HaveCount(directoriesList[i].Items.Count);
|
||||
}
|
||||
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,7 +116,7 @@ public class GetDirectoriesQueryHandlerTests
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _fixture.Create<GetDirectoriesQuery>();
|
||||
Error error = Error.Failure("DirectoryService.Error", "An error occurred");
|
||||
_mockDirectoryService.GetSubdirectories(query.Path, query.IncludeHiddenElements)
|
||||
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -114,7 +125,7 @@ public class GetDirectoriesQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path, query.IncludeHiddenElements);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -123,7 +134,7 @@ public class GetDirectoriesQueryHandlerTests
|
||||
// Arrange
|
||||
GetDirectoriesQuery query = _fixture.Create<GetDirectoriesQuery>();
|
||||
ErrorOr<IEnumerable<Directory>> emptyList = ErrorOrFactory.From(Enumerable.Empty<Directory>());
|
||||
_mockDirectoryService.GetSubdirectories(query.Path, query.IncludeHiddenElements)
|
||||
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
@@ -132,6 +143,6 @@ public class GetDirectoriesQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path, query.IncludeHiddenElements);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectories.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoriesQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class GetDirectoriesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetDirectoriesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class GetDirectoriesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectoryTree.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetDirectoryTreeQuery"/> class.
|
||||
+26
-32
@@ -1,18 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectoryTree.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -21,7 +19,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoryTreeQueryHandler"/> class.
|
||||
@@ -29,13 +27,11 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.G
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoryTreeQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IDriveService _mockDriveService;
|
||||
private readonly IDirectoryService _mockDirectoryService;
|
||||
private readonly IFileService _mockFileService;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly GetDirectoryTreeQueryHandler _sut;
|
||||
private readonly GetDirectoryTreeQueryFixture _getDirectoryTreeQueryFixture;
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture;
|
||||
private readonly FileFixture _fileFixture;
|
||||
@@ -45,13 +41,11 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
/// </summary>
|
||||
public GetDirectoryTreeQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockDriveService = Substitute.For<IDriveService>();
|
||||
_mockDirectoryService = Substitute.For<IDirectoryService>();
|
||||
_mockFileService = Substitute.For<IFileService>();
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_sut = new GetDirectoryTreeQueryHandler(_mockDriveService, _mockDirectoryService, _mockFileService, _mockPathService);
|
||||
_getDirectoryTreeQueryFixture = new GetDirectoryTreeQueryFixture();
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
_pathSegmentFixture = new PathSegmentFixture();
|
||||
_fileFixture = new FileFixture();
|
||||
@@ -79,7 +73,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
IEnumerable<File> files = _fileFixture.CreateMany(2);
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.CombinePath(Arg.Is<string>(x => true), Arg.Is<string>(y => true)).Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
|
||||
_mockDirectoryService.GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements).Returns(ErrorOrFactory.From(subdirectories));
|
||||
_mockFileService.GetFiles(Arg.Any<string>(), query.IncludeHiddenElements).Returns(ErrorOrFactory.From(files));
|
||||
@@ -92,7 +86,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
result.Value.Should().NotBeEmpty();
|
||||
result.Value.First().Children.Should().NotBeEmpty();
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockPathService.Received(1).ParsePath(query.Path);
|
||||
_mockPathService.Received(1).ParsePath(query.Path!);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements);
|
||||
_mockFileService.Received(0).GetFiles(Arg.Any<string>(), query.IncludeHiddenElements);
|
||||
}
|
||||
@@ -119,7 +113,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
IEnumerable<File> files = _fileFixture.CreateMany(2);
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.CombinePath(Arg.Is<string>(x => true), Arg.Is<string>(y => true)).Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
|
||||
_mockDirectoryService.GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements).Returns(ErrorOrFactory.From(subdirectories));
|
||||
_mockFileService.GetFiles(Arg.Any<string>(), query.IncludeHiddenElements).Returns(ErrorOrFactory.From(files));
|
||||
@@ -132,7 +126,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
result.Value.Should().NotBeEmpty();
|
||||
result.Value.First().Children.Should().NotBeEmpty();
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockPathService.Received(1).ParsePath(query.Path);
|
||||
_mockPathService.Received(1).ParsePath(query.Path!);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements);
|
||||
_mockFileService.Received(1).GetFiles(Arg.Any<string>(), query.IncludeHiddenElements);
|
||||
}
|
||||
@@ -166,7 +160,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(error);
|
||||
_mockPathService.ParsePath(query.Path!).Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
@@ -175,7 +169,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockPathService.Received(1).ParsePath(query.Path);
|
||||
_mockPathService.Received(1).ParsePath(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -192,7 +186,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.CombinePath(Arg.Any<string>(), Arg.Any<string>()).Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -202,7 +196,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockPathService.Received(1).ParsePath(query.Path);
|
||||
_mockPathService.Received(1).ParsePath(query.Path!);
|
||||
_mockPathService.Received(1).CombinePath(Arg.Any<string>(), Arg.Any<string>());
|
||||
}
|
||||
|
||||
@@ -220,7 +214,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
Error error = Error.Failure("DirectoryService.Error", "An error occurred");
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.CombinePath(Arg.Is<string>(x => true), Arg.Is<string>(y => true)).Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
|
||||
_mockDirectoryService.GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements).Returns(error);
|
||||
|
||||
@@ -231,7 +225,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockPathService.Received(1).ParsePath(query.Path);
|
||||
_mockPathService.Received(1).ParsePath(query.Path!);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
@@ -250,7 +244,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
Error error = Error.Failure("FileService.Error", "An error occurred");
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From(pathSegments));
|
||||
_mockPathService.CombinePath(Arg.Is<string>(x => true), Arg.Is<string>(y => true)).Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
|
||||
_mockDirectoryService.GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements).Returns(ErrorOrFactory.From(subdirectories));
|
||||
_mockFileService.GetFiles(Arg.Any<string>(), query.IncludeHiddenElements).Returns(error);
|
||||
@@ -262,7 +256,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockPathService.Received(1).ParsePath(query.Path);
|
||||
_mockPathService.Received(1).ParsePath(query.Path!);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(Arg.Any<string>(), query.IncludeHiddenElements);
|
||||
_mockFileService.Received(1).GetFiles(Arg.Any<string>(), query.IncludeHiddenElements);
|
||||
}
|
||||
@@ -307,7 +301,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
];
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)pathSegments));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)pathSegments));
|
||||
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(true);
|
||||
_mockPathService.CombinePath(Arg.Any<string>(), Arg.Any<string>())
|
||||
.Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
|
||||
@@ -347,7 +341,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(true);
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)pathSegments));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)pathSegments));
|
||||
_mockPathService.CombinePath(Arg.Any<string>(), Arg.Any<string>())
|
||||
.Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
|
||||
_mockDirectoryService.GetSubdirectories(Arg.Any<string>(), Arg.Any<bool>())
|
||||
@@ -373,7 +367,7 @@ public class GetDirectoryTreeQueryHandlerTests
|
||||
PathSegment rootSegment = _pathSegmentFixture.CreatePathSegment(name: "C:", isDrive: true);
|
||||
|
||||
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
|
||||
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)[rootSegment]));
|
||||
_mockPathService.ParsePath(query.Path!).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)[rootSegment]));
|
||||
|
||||
IEnumerable<Directory> visibleDirectories = _directoryFixture.CreateMany(2);
|
||||
_mockDirectoryService.GetSubdirectories(Arg.Any<string>(), false).Returns(ErrorOrFactory.From(visibleDirectories));
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectoryTree.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoryTreeQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class GetDirectoryTreeQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetDirectoryTreeQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class GetDirectoryTreeQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetTreeDirectories.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetTreeDirectoriesQuery"/> class.
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories.Fixtures;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeDirectoriesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeDirectoriesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IDirectoryService _mockDirectoryService;
|
||||
private readonly GetTreeDirectoriesQueryHandler _sut;
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockDirectoryService = Substitute.For<IDirectoryService>();
|
||||
_sut = new GetTreeDirectoriesQueryHandler(_mockDirectoryService);
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalledWithValidQueryWithoutFilesIncluded_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery getDirectoriesQuery = GetTreeDirectoriesQueryFixture.CreateGetTreeDirectoryQuery(false);
|
||||
|
||||
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().HaveCount(directories.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
|
||||
List<Directory> directoriesList = directories.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(directoriesList[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(directoriesList[i].Name);
|
||||
resultList[i].ItemType.Should().Be(FileSystemItemType.Directory);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
resultList[i].Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalledWithValidQueryWithFilesIncluded_ShouldReturnSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery getDirectoriesQuery = GetTreeDirectoriesQueryFixture.CreateGetTreeDirectoryQuery(true);
|
||||
|
||||
IEnumerable<Directory> directories = _directoryFixture.CreateManyNested();
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().HaveCount(directories.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
|
||||
List<Directory> directoriesList = directories.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
FileSystemTreeNodeResponse response = resultList[i];
|
||||
Directory directory = directoriesList[i];
|
||||
|
||||
response.Path.Should().Be(directory.Id.Path);
|
||||
response.Name.Should().Be(directory.Name);
|
||||
response.ItemType.Should().Be(FileSystemItemType.Directory);
|
||||
response.IsExpanded.Should().BeFalse();
|
||||
response.ChildrenLoaded.Should().BeFalse();
|
||||
response.Children.Should().HaveCount(directory.Items.Count);
|
||||
|
||||
List<FileSystemTreeNodeResponse> childResponses = [.. response.Children];
|
||||
List<FileSystemItem> directoryItems = [.. directory.Items];
|
||||
|
||||
for (int j = 0; j < childResponses.Count; j++)
|
||||
{
|
||||
FileSystemTreeNodeResponse childResponse = childResponses[j];
|
||||
FileSystemItem item = directoryItems[j];
|
||||
|
||||
childResponse.Path.Should().Be(item.Id.Path);
|
||||
childResponse.Name.Should().Be(item.Name);
|
||||
childResponse.ItemType.Should().Be(item.Type);
|
||||
childResponse.IsExpanded.Should().BeFalse();
|
||||
childResponse.ChildrenLoaded.Should().BeFalse();
|
||||
|
||||
if (item is Directory)
|
||||
childResponse.Children.Should().NotBeNull();
|
||||
else
|
||||
childResponse.Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenDirectoryServiceReturnsError_ShouldReturnFailureResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery query = GetTreeDirectoriesQueryFixture.CreateGetTreeDirectoryQuery();
|
||||
Error error = Error.Failure("DirectoryService.Error", "An error occurred");
|
||||
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenDirectoryServiceReturnsEmptyList_ShouldReturnEmptySuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery query = _fixture.Create<GetTreeDirectoriesQuery>();
|
||||
ErrorOr<IEnumerable<Directory>> emptyList = ErrorOrFactory.From(Enumerable.Empty<Directory>());
|
||||
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenCalledWithNestedDirectories_ShouldReturnCorrectlyNestedResponse()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesQuery query = GetTreeDirectoriesQueryFixture.CreateGetTreeDirectoryQuery(true);
|
||||
IEnumerable<Directory> nestedDirectories = _directoryFixture.CreateManyNested(2, 2, 2);
|
||||
|
||||
_mockDirectoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(nestedDirectories));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().HaveCount(2); // top level directories
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
|
||||
List<Directory> directoriesList = nestedDirectories.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
FileSystemTreeNodeResponse response = resultList[i];
|
||||
Directory directory = directoriesList[i];
|
||||
|
||||
response.Path.Should().Be(directory.Id.Path);
|
||||
response.Name.Should().Be(directory.Name);
|
||||
response.ItemType.Should().Be(FileSystemItemType.Directory);
|
||||
response.IsExpanded.Should().BeFalse();
|
||||
response.ChildrenLoaded.Should().BeFalse();
|
||||
response.Children.Should().HaveCount(directory.Items.Count);
|
||||
|
||||
// check first level of children
|
||||
for (int j = 0; j < response.Children.Count; j++)
|
||||
{
|
||||
FileSystemTreeNodeResponse childResponse = response.Children[j];
|
||||
FileSystemItem childItem = directory.Items.ElementAt(j);
|
||||
|
||||
childResponse.Path.Should().Be(childItem.Id.Path);
|
||||
childResponse.Name.Should().Be(childItem.Name);
|
||||
childResponse.ItemType.Should().Be(childItem.Type);
|
||||
childResponse.IsExpanded.Should().BeFalse();
|
||||
childResponse.ChildrenLoaded.Should().BeFalse();
|
||||
|
||||
if (childItem is Directory dir)
|
||||
{
|
||||
childResponse.Children.Should().NotBeNull();
|
||||
childResponse.Children.Should().HaveCount(dir.Items.Count);
|
||||
}
|
||||
else
|
||||
childResponse.Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
result.Value.Any(r => r.Children.Count != 0).Should().BeTrue();
|
||||
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetTreeDirectories.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeDirectoriesQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class GetTreeDirectoriesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetTreeDirectoriesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class GetTreeDirectoriesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Drives.Queries.GetDrives.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Drives.Queries.GetDrives.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetDrivesQueryFixture"/> class.
|
||||
+26
-24
@@ -3,13 +3,12 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Drives.Queries.GetDrives;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Drives.Queries.GetDrives.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -18,7 +17,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Drives.Queries.GetDrives;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Drives.Queries.GetDrives;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDrivesQueryHandler"/> class.
|
||||
@@ -27,10 +26,8 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Drives.Queries.GetDri
|
||||
public class GetDrivesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IDriveService _mockDriveService;
|
||||
private readonly GetDrivesQueryHandler _sut;
|
||||
private readonly GetDrivesQueryFixture _getDrivesQueryFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDrivesQueryHandlerTests"/> class.
|
||||
@@ -39,9 +36,7 @@ public class GetDrivesQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockDriveService = Substitute.For<IDriveService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetDrivesQueryHandler(_mockDriveService, _mockMapper);
|
||||
_getDrivesQueryFixture = new GetDrivesQueryFixture();
|
||||
_sut = new GetDrivesQueryHandler(_mockDriveService);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -56,23 +51,34 @@ public class GetDrivesQueryHandlerTests
|
||||
WindowsRootItem.Create("D:\\", "D:").Value
|
||||
];
|
||||
|
||||
List<FileSystemTreeNodeResponse> driveResponses = _getDrivesQueryFixture.CreateMany();
|
||||
|
||||
_mockDriveService.GetDrives()
|
||||
.Returns(ErrorOrFactory.From(drives));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<FileSystemItem>>(d => d == drives))
|
||||
.Returns(driveResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDrivesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(driveResponses);
|
||||
result.Value.Should().HaveCount(drives.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
|
||||
List<FileSystemItem> drivesList = drives.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
FileSystemTreeNodeResponse response = resultList[i];
|
||||
WindowsRootItem drive = (WindowsRootItem)drivesList[i];
|
||||
|
||||
response.Path.Should().Be(drive.Id.Path);
|
||||
response.Name.Should().Be(drive.Name);
|
||||
response.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
response.IsExpanded.Should().BeFalse();
|
||||
response.ChildrenLoaded.Should().BeFalse();
|
||||
response.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<FileSystemItem>>(d => d == drives));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -102,9 +108,6 @@ public class GetDrivesQueryHandlerTests
|
||||
_mockDriveService.GetDrives()
|
||||
.Returns(emptyList);
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Any<IEnumerable<FileSystemItem>>())
|
||||
.Returns([]);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
@@ -112,6 +115,5 @@ public class GetDrivesQueryHandlerTests
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockDriveService.Received(1).GetDrives();
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Any<IEnumerable<FileSystemItem>>());
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UnixRootItem"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UnixRootItemFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UnixRootItem"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="UnixRootItem"/>.</returns>
|
||||
public UnixRootItem Create()
|
||||
{
|
||||
ErrorOr<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
|
||||
_faker.PickRandom<FileSystemItemStatus>()
|
||||
);
|
||||
if (unixRootItemResult.IsError)
|
||||
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", unixRootItemResult.Errors));
|
||||
return unixRootItemResult.Value;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="WindowsRootItem"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WindowsRootItemFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="WindowsRootItem"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="WindowsRootItem"/>.</returns>
|
||||
public WindowsRootItem Create()
|
||||
{
|
||||
ErrorOr<WindowsRootItem> windowsRootItemResult = WindowsRootItem.Create(
|
||||
_faker.System.FilePath(),
|
||||
_faker.System.FileName(),
|
||||
_faker.PickRandom<FileSystemItemStatus>()
|
||||
);
|
||||
if (windowsRootItemResult.IsError)
|
||||
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", windowsRootItemResult.Errors));
|
||||
return windowsRootItemResult.Value;
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -2,10 +2,10 @@
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSystem;
|
||||
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Strategies.Platform;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -13,7 +13,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.FileSystem.Queries.GetFileSystem;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFileSystemQueryHandler"/> class.
|
||||
+2
-2
@@ -3,14 +3,14 @@ using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="File"/> class.
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileResponse"/> class.
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetFiles.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetFilesQuery"/> class.
|
||||
+44
-38
@@ -3,13 +3,12 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetFiles.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,7 +18,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetFiles;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -29,11 +28,9 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetFile
|
||||
public class GetFilesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IFileService _mockFileService;
|
||||
private readonly GetFilesQueryHandler _sut;
|
||||
private readonly FileFixture _fileFixture;
|
||||
private readonly FileResponseFixture _fileResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFilesQueryHandlerTests"/> class.
|
||||
@@ -42,10 +39,8 @@ public class GetFilesQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockFileService = Substitute.For<IFileService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetFilesQueryHandler(_mockFileService, _mockMapper);
|
||||
_sut = new GetFilesQueryHandler(_mockFileService);
|
||||
_fileFixture = new FileFixture();
|
||||
_fileResponseFixture = new FileResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -55,23 +50,31 @@ public class GetFilesQueryHandlerTests
|
||||
GetFilesQuery getFilesQuery = GetFilesQueryFixture.CreateGetFilesQuery(false);
|
||||
|
||||
IEnumerable<File> files = _fileFixture.CreateMany();
|
||||
IEnumerable<FileResponse> fileResponses = _fileResponseFixture.CreateMany(files.Count());
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileResponse>>(Arg.Is<IEnumerable<File>>(f => f == files))
|
||||
.Returns(fileResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(fileResponses);
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileResponse>>(Arg.Is<IEnumerable<File>>(f => f == files));
|
||||
result.Value.Should().HaveCount(files.Count());
|
||||
|
||||
List<FileResponse> resultList = result.Value.ToList();
|
||||
List<File> filesList = files.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(filesList[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(filesList[i].Name);
|
||||
resultList[i].DateCreated.Should().Be(filesList[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(filesList[i].DateModified.Value);
|
||||
resultList[i].Size.Should().Be(filesList[i].Size);
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,23 +84,31 @@ public class GetFilesQueryHandlerTests
|
||||
GetFilesQuery getFilesQuery = GetFilesQueryFixture.CreateGetFilesQuery(true);
|
||||
|
||||
IEnumerable<File> files = _fileFixture.CreateMany();
|
||||
IEnumerable<FileResponse> fileResponses = _fileResponseFixture.CreateMany(files.Count());
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileResponse>>(Arg.Is<IEnumerable<File>>(f => f == files))
|
||||
.Returns(fileResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(fileResponses);
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileResponse>>(Arg.Is<IEnumerable<File>>(f => f == files));
|
||||
result.Value.Should().HaveCount(files.Count());
|
||||
|
||||
List<FileResponse> resultList = result.Value.ToList();
|
||||
List<File> filesList = files.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(filesList[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(filesList[i].Name);
|
||||
resultList[i].DateCreated.Should().Be(filesList[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(filesList[i].DateModified.Value);
|
||||
resultList[i].Size.Should().Be(filesList[i].Size);
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -106,7 +117,7 @@ public class GetFilesQueryHandlerTests
|
||||
// Arrange
|
||||
GetFilesQuery query = _fixture.Create<GetFilesQuery>();
|
||||
Error error = Error.Failure("FileService.Error", "An error occurred");
|
||||
_mockFileService.GetFiles(query.Path, query.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -115,8 +126,7 @@ public class GetFilesQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockFileService.Received(1).GetFiles(query.Path, query.IncludeHiddenElements);
|
||||
_mockMapper.DidNotReceive().Map<IEnumerable<FileResponse>>(Arg.Any<IEnumerable<File>>());
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -125,19 +135,15 @@ public class GetFilesQueryHandlerTests
|
||||
// Arrange
|
||||
GetFilesQuery query = _fixture.Create<GetFilesQuery>();
|
||||
ErrorOr<IEnumerable<File>> emptyList = ErrorOrFactory.From(Enumerable.Empty<File>());
|
||||
_mockFileService.GetFiles(query.Path, query.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileResponse>>(Arg.Is<IEnumerable<File>>(f => !f.Any()))
|
||||
.Returns([]);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockFileService.Received(1).GetFiles(query.Path, query.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileResponse>>(Arg.Is<IEnumerable<File>>(f => !f.Any()));
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetFiles.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetFiles;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFilesQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class GetFilesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetFilesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class GetFilesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetTreeFiles.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetTreeFilesQuery"/> class.
|
||||
+47
-34
@@ -3,14 +3,13 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetTreeFiles.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -19,7 +18,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeFilesQueryHandler"/> class.
|
||||
@@ -28,11 +27,9 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetTree
|
||||
public class GetTreeFilesQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IFileService _mockFileService;
|
||||
private readonly GetTreeFilesQueryHandler _sut;
|
||||
private readonly FileFixture _fileFixture;
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeFilesQueryHandler"/> class.
|
||||
@@ -41,10 +38,8 @@ public class GetTreeFilesQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockFileService = Substitute.For<IFileService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetTreeFilesQueryHandler(_mockFileService, _mockMapper);
|
||||
_sut = new GetTreeFilesQueryHandler(_mockFileService);
|
||||
_fileFixture = new FileFixture();
|
||||
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -54,23 +49,32 @@ public class GetTreeFilesQueryHandlerTests
|
||||
GetTreeFilesQuery getFilesQuery = GetTreeFilesQueryFixture.CreateGetFilesQuery(false);
|
||||
|
||||
IEnumerable<File> files = _fileFixture.CreateMany();
|
||||
IEnumerable<FileSystemTreeNodeResponse> fileResponses = _fileSystemTreeNodeResponseFixture.CreateMany(files.Count());
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<File>>(f => f == files))
|
||||
.Returns(fileResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(fileResponses);
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<File>>(f => f == files));
|
||||
result.Value.Should().HaveCount(files.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
|
||||
List<File> filesList = files.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(filesList[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(filesList[i].Name);
|
||||
resultList[i].ItemType.Should().Be(FileSystemItemType.File);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
resultList[i].Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -80,23 +84,32 @@ public class GetTreeFilesQueryHandlerTests
|
||||
GetTreeFilesQuery getFilesQuery = GetTreeFilesQueryFixture.CreateGetFilesQuery(true);
|
||||
|
||||
IEnumerable<File> files = _fileFixture.CreateMany();
|
||||
IEnumerable<FileSystemTreeNodeResponse> fileResponses = _fileSystemTreeNodeResponseFixture.CreateMany(files.Count());
|
||||
|
||||
_mockFileService.GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements)
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
_mockMapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<File>>(f => f == files))
|
||||
.Returns(fileResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(fileResponses);
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path, getFilesQuery.IncludeHiddenElements);
|
||||
_mockMapper.Received(1).Map<IEnumerable<FileSystemTreeNodeResponse>>(Arg.Is<IEnumerable<File>>(f => f == files));
|
||||
result.Value.Should().HaveCount(files.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
|
||||
List<File> filesList = files.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(filesList[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(filesList[i].Name);
|
||||
resultList[i].ItemType.Should().Be(FileSystemItemType.File);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
resultList[i].Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,7 +118,7 @@ public class GetTreeFilesQueryHandlerTests
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _fixture.Create<GetTreeFilesQuery>();
|
||||
Error error = Error.Failure("FileService.Error", "An error occurred");
|
||||
_mockFileService.GetFiles(query.Path, query.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -114,7 +127,7 @@ public class GetTreeFilesQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockFileService.Received(1).GetFiles(query.Path, query.IncludeHiddenElements);
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -123,7 +136,7 @@ public class GetTreeFilesQueryHandlerTests
|
||||
// Arrange
|
||||
GetTreeFilesQuery query = _fixture.Create<GetTreeFilesQuery>();
|
||||
ErrorOr<IEnumerable<File>> emptyList = ErrorOrFactory.From(Enumerable.Empty<File>());
|
||||
_mockFileService.GetFiles(query.Path, query.IncludeHiddenElements)
|
||||
_mockFileService.GetFiles(query.Path!, query.IncludeHiddenElements)
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
@@ -132,6 +145,6 @@ public class GetTreeFilesQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockFileService.Received(1).GetFiles(query.Path, query.IncludeHiddenElements);
|
||||
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetTreeFiles.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeFilesQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class GetTreeFilesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetTreeFilesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class GetTreeFilesQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemPathId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemPathIdFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemPathIdFixture"/> class.
|
||||
/// </summary>
|
||||
public FileSystemPathIdFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FileSystemPathId"/>.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file system path element.</param>
|
||||
/// <returns>The created <see cref="FileSystemPathId"/>.</returns>
|
||||
public FileSystemPathId CreateFileSystemPathId(string? path = null)
|
||||
{
|
||||
path ??= _faker.System.FilePath();
|
||||
|
||||
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(path);
|
||||
|
||||
if (fileSystemPathIdResult.IsError)
|
||||
throw new InvalidOperationException("Failed to create FileSystemPathId: " + string.Join(", ", fileSystemPathIdResult.Errors));
|
||||
return fileSystemPathIdResult.Value;
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -3,17 +3,17 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.CombinePath;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CombinePathCommandHandler"/> class.
|
||||
@@ -40,9 +40,9 @@ public class CombinePathCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand combinePathCommand = CombinePathCommandFixture.CreateCombinePathCommand();
|
||||
string combinedPath = System.IO.Path.Combine(combinePathCommand.OriginalPath, combinePathCommand.NewPath);
|
||||
string combinedPath = System.IO.Path.Combine(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
|
||||
|
||||
_mockPathService.CombinePath(combinePathCommand.OriginalPath, combinePathCommand.NewPath)
|
||||
_mockPathService.CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!)
|
||||
.Returns(ErrorOrFactory.From(combinedPath));
|
||||
|
||||
// Act
|
||||
@@ -52,7 +52,7 @@ public class CombinePathCommandHandlerTests
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeOfType<PathSegmentResponse>();
|
||||
result.Value.Path.Should().Be(combinedPath);
|
||||
_mockPathService.Received(1).CombinePath(combinePathCommand.OriginalPath, combinePathCommand.NewPath);
|
||||
_mockPathService.Received(1).CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +61,7 @@ public class CombinePathCommandHandlerTests
|
||||
// Arrange
|
||||
CombinePathCommand command = _fixture.Create<CombinePathCommand>();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.CombinePath(command.OriginalPath, command.NewPath)
|
||||
_mockPathService.CombinePath(command.OriginalPath!, command.NewPath!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -70,7 +70,7 @@ public class CombinePathCommandHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockPathService.Received(1).CombinePath(command.OriginalPath, command.NewPath);
|
||||
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -78,7 +78,7 @@ public class CombinePathCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CombinePathCommand command = _fixture.Create<CombinePathCommand>();
|
||||
_mockPathService.CombinePath(command.OriginalPath, command.NewPath)
|
||||
_mockPathService.CombinePath(command.OriginalPath!, command.NewPath!)
|
||||
.Returns(ErrorOrFactory.From(string.Empty));
|
||||
|
||||
// Act
|
||||
@@ -88,6 +88,6 @@ public class CombinePathCommandHandlerTests
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeOfType<PathSegmentResponse>();
|
||||
result.Value.Path.Should().BeEmpty();
|
||||
_mockPathService.Received(1).CombinePath(command.OriginalPath, command.NewPath);
|
||||
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.CombinePath;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CombinePathCommandValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class CombinePathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class CombinePathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class CombinePathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,7 +81,7 @@ public class CombinePathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPath)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -96,7 +96,7 @@ public class CombinePathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPath)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -111,7 +111,7 @@ public class CombinePathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPath)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="CombinePathCommand"/> class.
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.SplitPath.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="SplitPathCommand"/> class.
|
||||
+21
-38
@@ -3,15 +3,12 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.SplitPath.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -21,7 +18,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.SplitPath;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SplitPathCommandHandler"/> class.
|
||||
@@ -30,13 +27,9 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.SplitPa
|
||||
public class SplitPathCommandHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly SplitPathCommandHandler _sut;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture;
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
|
||||
private readonly PathSegmentMappingConfig _pathSegmentMappingConfig;
|
||||
private readonly TypeAdapterConfig _config;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SplitPathCommandHandlerTests"/> class.
|
||||
@@ -45,14 +38,8 @@ public class SplitPathCommandHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new SplitPathCommandHandler(_mockPathService, _mockMapper);
|
||||
_sut = new SplitPathCommandHandler(_mockPathService);
|
||||
_pathSegmentFixture = new PathSegmentFixture();
|
||||
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
|
||||
|
||||
_config = new TypeAdapterConfig();
|
||||
_pathSegmentMappingConfig = new PathSegmentMappingConfig();
|
||||
_pathSegmentMappingConfig.Register(_config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,23 +49,24 @@ public class SplitPathCommandHandlerTests
|
||||
SplitPathCommand splitPathCommand = SplitPathCommandFixture.CreateSplitPathCommand();
|
||||
|
||||
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
|
||||
IEnumerable<PathSegmentResponse> pathSegmentResponses = _pathSegmentResponseFixture.CreateMany(pathSegments.Count());
|
||||
|
||||
_mockPathService.ParsePath(splitPathCommand.Path)
|
||||
_mockPathService.ParsePath(splitPathCommand.Path!)
|
||||
.Returns(ErrorOrFactory.From(pathSegments));
|
||||
|
||||
_mockMapper.Map<IEnumerable<PathSegmentResponse>>(Arg.Any<IEnumerable<PathSegment>>())
|
||||
.Returns(pathSegmentResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(splitPathCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<PathSegmentResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(pathSegmentResponses);
|
||||
_mockPathService.Received(1).ParsePath(splitPathCommand.Path);
|
||||
_mockMapper.Received(1).Map<IEnumerable<PathSegmentResponse>>(Arg.Any<IEnumerable<PathSegment>>());
|
||||
result.Value.Should().HaveCount(pathSegments.Count());
|
||||
|
||||
List<PathSegmentResponse> resultList = result.Value.ToList();
|
||||
List<PathSegment> segmentsList = pathSegments.ToList();
|
||||
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
resultList[i].Path.Should().Be(segmentsList[i].Name);
|
||||
_mockPathService.Received(1).ParsePath(splitPathCommand.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -87,7 +75,7 @@ public class SplitPathCommandHandlerTests
|
||||
// Arrange
|
||||
SplitPathCommand command = _fixture.Create<SplitPathCommand>();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.ParsePath(command.Path)
|
||||
_mockPathService.ParsePath(command.Path!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -96,8 +84,7 @@ public class SplitPathCommandHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockPathService.Received(1).ParsePath(command.Path);
|
||||
_mockMapper.DidNotReceive().Map<IEnumerable<PathSegmentResponse>>(Arg.Any<ErrorOr<IEnumerable<PathSegment>>>());
|
||||
_mockPathService.Received(1).ParsePath(command.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -106,19 +93,15 @@ public class SplitPathCommandHandlerTests
|
||||
// Arrange
|
||||
SplitPathCommand command = _fixture.Create<SplitPathCommand>();
|
||||
ErrorOr<IEnumerable<PathSegment>> emptyList = ErrorOrFactory.From(Enumerable.Empty<PathSegment>());
|
||||
_mockPathService.ParsePath(command.Path)
|
||||
_mockPathService.ParsePath(command.Path!)
|
||||
.Returns(emptyList);
|
||||
|
||||
_mockMapper.Map<IEnumerable<PathSegmentResponse>>(Arg.Any<IEnumerable<PathSegment>>())
|
||||
.Returns([]);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockPathService.Received(1).ParsePath(command.Path);
|
||||
_mockMapper.Received(1).Map<IEnumerable<PathSegmentResponse>>(Arg.Any<IEnumerable<PathSegment>>());
|
||||
_mockPathService.Received(1).ParsePath(command.Path!);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.SplitPath.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Commands.SplitPath;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SplitPathCommandValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class SplitPathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class SplitPathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class SplitPathCommandValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,14 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PathSegment"/> class.
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PathSegmentResponse"/> class.
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PathSeparatorResponse"/> class.
|
||||
+15
-15
@@ -1,16 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.CheckPathExists;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CheckPathExistsQueryHandler"/> class.
|
||||
@@ -35,14 +35,14 @@ public class CheckPathExistsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
|
||||
_mockPathService.Exists(query.Path).Returns(true);
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
PathExistsResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Exists.Should().BeTrue();
|
||||
_mockPathService.Received(1).Exists(query.Path);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,14 +50,14 @@ public class CheckPathExistsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery(true);
|
||||
_mockPathService.Exists(query.Path).Returns(true);
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
PathExistsResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Exists.Should().BeTrue();
|
||||
_mockPathService.Received(1).Exists(query.Path);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -65,14 +65,14 @@ public class CheckPathExistsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery(false);
|
||||
_mockPathService.Exists(query.Path, false).Returns(false);
|
||||
_mockPathService.Exists(query.Path!, false).Returns(false);
|
||||
|
||||
// Act
|
||||
PathExistsResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Exists.Should().BeFalse();
|
||||
_mockPathService.Received(1).Exists(query.Path, false);
|
||||
_mockPathService.Received(1).Exists(query.Path!, false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -80,14 +80,14 @@ public class CheckPathExistsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
|
||||
_mockPathService.Exists(query.Path).Returns(false);
|
||||
_mockPathService.Exists(query.Path!).Returns(false);
|
||||
|
||||
// Act
|
||||
PathExistsResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.Exists.Should().BeFalse();
|
||||
_mockPathService.Received(1).Exists(query.Path);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -110,7 +110,7 @@ public class CheckPathExistsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
|
||||
_mockPathService.Exists(query.Path).Returns(true);
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
CancellationToken cancellationToken = new(true);
|
||||
|
||||
// Act
|
||||
@@ -118,6 +118,6 @@ public class CheckPathExistsQueryHandlerTests
|
||||
|
||||
// Assert
|
||||
result.Exists.Should().BeTrue();
|
||||
_mockPathService.Received(1).Exists(query.Path);
|
||||
_mockPathService.Received(1).Exists(query.Path!);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.CheckPathExists;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CheckPathExistsQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class CheckPathExistsQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class CheckPathExistsQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class CheckPathExistsQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="CheckPathExistsQuery"/> class.
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathParent.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetPathParentQuery"/> class.
|
||||
+17
-29
@@ -3,13 +3,12 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathParent.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -18,7 +17,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathParent;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathParentQueryHandler"/> class.
|
||||
@@ -27,20 +26,16 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathP
|
||||
public class GetPathParentQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly GetPathParentQueryHandler _sut;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture;
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
|
||||
|
||||
public GetPathParentQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetPathParentQueryHandler(_mockPathService, _mockMapper);
|
||||
_sut = new GetPathParentQueryHandler(_mockPathService);
|
||||
_pathSegmentFixture = new PathSegmentFixture();
|
||||
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,14 +45,13 @@ public class GetPathParentQueryHandlerTests
|
||||
GetPathParentQuery query = GetPathParentQueryFixture.CreateGetPathParentQuery();
|
||||
|
||||
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
|
||||
IEnumerable<PathSegmentResponse> pathSegmentResponses = _pathSegmentResponseFixture.CreateMany(pathSegments.Count());
|
||||
|
||||
_mockPathService.GoUpOneLevel(query.Path)
|
||||
// Create PathSegmentResponses based on the PathSegments
|
||||
IEnumerable<PathSegmentResponse> pathSegmentResponses = pathSegments.Select(segment => new PathSegmentResponse(segment.Name));
|
||||
|
||||
_mockPathService.GoUpOneLevel(query.Path!)
|
||||
.Returns(ErrorOrFactory.From(pathSegments));
|
||||
|
||||
_mockMapper.Map<IEnumerable<PathSegmentResponse>>(Arg.Is<IEnumerable<PathSegment>>(p => p == pathSegments))
|
||||
.Returns(pathSegmentResponses);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
@@ -65,8 +59,7 @@ public class GetPathParentQueryHandlerTests
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeAssignableTo<IEnumerable<PathSegmentResponse>>();
|
||||
result.Value.Should().BeEquivalentTo(pathSegmentResponses);
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path);
|
||||
_mockMapper.Received(1).Map<IEnumerable<PathSegmentResponse>>(Arg.Is<IEnumerable<PathSegment>>(p => p == pathSegments));
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -75,7 +68,7 @@ public class GetPathParentQueryHandlerTests
|
||||
// Arrange
|
||||
GetPathParentQuery query = _fixture.Create<GetPathParentQuery>();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.GoUpOneLevel(query.Path)
|
||||
_mockPathService.GoUpOneLevel(query.Path!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -84,8 +77,7 @@ public class GetPathParentQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path);
|
||||
_mockMapper.DidNotReceive().Map<IEnumerable<PathSegmentResponse>>(Arg.Any<IEnumerable<PathSegment>>());
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -94,19 +86,15 @@ public class GetPathParentQueryHandlerTests
|
||||
// Arrange
|
||||
GetPathParentQuery query = _fixture.Create<GetPathParentQuery>();
|
||||
ErrorOr<IEnumerable<PathSegment>> emptyList = ErrorOrFactory.From(Enumerable.Empty<PathSegment>());
|
||||
_mockPathService.GoUpOneLevel(query.Path)
|
||||
_mockPathService.GoUpOneLevel(query.Path!)
|
||||
.Returns(emptyList);
|
||||
|
||||
_mockMapper.Map<IEnumerable<PathSegmentResponse>>(Arg.Is<IEnumerable<PathSegment>>(p => !p.Any()))
|
||||
.Returns([]);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEmpty();
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path);
|
||||
_mockMapper.Received(1).Map<IEnumerable<PathSegmentResponse>>(Arg.Is<IEnumerable<PathSegment>>(p => !p.Any()));
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathParent.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathParent;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathParentQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class GetPathParentQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetPathParentQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class GetPathParentQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathRoot.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetPathRootQuery"/> class.
|
||||
+18
-36
@@ -1,22 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathRoot.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathRoot;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathRootQueryHandler"/> class.
|
||||
@@ -24,24 +21,18 @@ namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathR
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathRootQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly GetPathRootQueryHandler _sut;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture;
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPathRootQueryHandlerTests"/> class.
|
||||
/// </summary>
|
||||
public GetPathRootQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetPathRootQueryHandler(_mockPathService, _mockMapper);
|
||||
_sut = new GetPathRootQueryHandler(_mockPathService);
|
||||
_pathSegmentFixture = new PathSegmentFixture();
|
||||
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,22 +41,18 @@ public class GetPathRootQueryHandlerTests
|
||||
// Arrange
|
||||
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
|
||||
PathSegment pathSegment = _pathSegmentFixture.CreatePathSegment(isDrive: true);
|
||||
PathSegmentResponse pathSegmentResponse = _pathSegmentResponseFixture.Create();
|
||||
|
||||
_mockPathService.GetPathRoot(query.Path)
|
||||
_mockPathService.GetPathRoot(query.Path!)
|
||||
.Returns(ErrorOrFactory.From(pathSegment));
|
||||
|
||||
_mockMapper.Map<PathSegmentResponse>(Arg.Is<PathSegment>(p => p == pathSegment))
|
||||
.Returns(pathSegmentResponse);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEquivalentTo(pathSegmentResponse);
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path);
|
||||
_mockMapper.Received(1).Map<PathSegmentResponse>(Arg.Is<PathSegment>(p => p == pathSegment));
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Path.Should().Be(pathSegment.Name);
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -74,7 +61,7 @@ public class GetPathRootQueryHandlerTests
|
||||
// Arrange
|
||||
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
|
||||
Error error = Error.Failure("PathService.Error", "An error occurred");
|
||||
_mockPathService.GetPathRoot(query.Path)
|
||||
_mockPathService.GetPathRoot(query.Path!)
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -83,8 +70,7 @@ public class GetPathRootQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path);
|
||||
_mockMapper.DidNotReceive().Map<PathSegmentResponse>(Arg.Any<PathSegment>());
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -93,21 +79,17 @@ public class GetPathRootQueryHandlerTests
|
||||
// Arrange
|
||||
GetPathRootQuery query = GetPathRootQueryFixture.CreateGetPathRootQuery();
|
||||
PathSegment rootPathSegment = _pathSegmentFixture.CreatePathSegment(name: "/", isDirectory: true, isDrive: true);
|
||||
PathSegmentResponse rootResponse = _pathSegmentResponseFixture.Create();
|
||||
|
||||
_mockPathService.GetPathRoot(query.Path)
|
||||
_mockPathService.GetPathRoot(query.Path!)
|
||||
.Returns(ErrorOrFactory.From(rootPathSegment));
|
||||
|
||||
_mockMapper.Map<PathSegmentResponse>(Arg.Is<PathSegment>(p => p == rootPathSegment))
|
||||
.Returns(rootResponse);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEquivalentTo(rootResponse);
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path);
|
||||
_mockMapper.Received(1).Map<PathSegmentResponse>(Arg.Is<PathSegment>(p => p == rootPathSegment));
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Path.Should().Be("/");
|
||||
_mockPathService.Received(1).GetPathRoot(query.Path!);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathRoot.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathRoot;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathRootQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class GetPathRootQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetPathRootQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class GetPathRootQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathSeparator;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -10,7 +10,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.GetPathSeparator;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathSeparator;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathSeparatorQueryHandler"/> class.
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.ValidatePath.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ValidatePathQuery"/> class.
|
||||
+9
-9
@@ -1,16 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.ValidatePath.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.ValidatePath;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ValidatePathQueryHandler"/> class.
|
||||
@@ -35,14 +35,14 @@ public class ValidatePathQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
|
||||
_mockPathService.IsValidPath(query.Path).Returns(true);
|
||||
_mockPathService.IsValidPath(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsValid.Should().BeTrue();
|
||||
_mockPathService.Received(1).IsValidPath(query.Path);
|
||||
_mockPathService.Received(1).IsValidPath(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,14 +50,14 @@ public class ValidatePathQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathQuery query = ValidatePathQueryFixure.CreateValidatePathQuery();
|
||||
_mockPathService.IsValidPath(query.Path).Returns(false);
|
||||
_mockPathService.IsValidPath(query.Path!).Returns(false);
|
||||
|
||||
// Act
|
||||
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsValid.Should().BeFalse();
|
||||
_mockPathService.Received(1).IsValidPath(query.Path);
|
||||
_mockPathService.Received(1).IsValidPath(query.Path!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.ValidatePath.Fixtures;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Pahs.Queries.ValidatePath;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ValidatePathQueryValidator"/> class.
|
||||
@@ -36,7 +36,7 @@ public class ValidatePathQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class ValidatePathQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +66,7 @@ public class ValidatePathQueryValidatorTests
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Enums.PhotoLibrary;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Thumbnails.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThumbnailResponse"/> class.
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Thumbnails.Queries.GetThumbnail.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetThumbnailQuery"/> class.
|
||||
+16
-24
@@ -3,19 +3,18 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Thumbnails.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetThumbnailQueryHandler"/> class.
|
||||
@@ -25,15 +24,13 @@ public class GetThumbnailQueryHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IThumbnailService _mockThumbnailService;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly GetThumbnailQueryHandler _sut;
|
||||
|
||||
public GetThumbnailQueryHandlerTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockThumbnailService = Substitute.For<IThumbnailService>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_sut = new GetThumbnailQueryHandler(_mockThumbnailService, _mockMapper);
|
||||
_sut = new GetThumbnailQueryHandler(_mockThumbnailService);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -42,22 +39,19 @@ public class GetThumbnailQueryHandlerTests
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _fixture.Create<GetThumbnailQuery>();
|
||||
Thumbnail thumbnail = _fixture.Create<Thumbnail>();
|
||||
ThumbnailResponse thumbnailResponse = ThumbnailResponseFixture.CreateThumbnailResponse();
|
||||
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path, query.Quality, Arg.Any<CancellationToken>())
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(thumbnail));
|
||||
|
||||
_mockMapper.Map<ThumbnailResponse>(Arg.Is<Thumbnail>(t => t == thumbnail))
|
||||
.Returns(thumbnailResponse);
|
||||
|
||||
// Act
|
||||
ErrorOr<ThumbnailResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeEquivalentTo(thumbnailResponse);
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path, query.Quality, Arg.Any<CancellationToken>());
|
||||
_mockMapper.Received(1).Map<ThumbnailResponse>(Arg.Is<Thumbnail>(t => t == thumbnail));
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Type.Should().Be(thumbnail.Type);
|
||||
result.Value.Bytes.Should().BeEquivalentTo(thumbnail.Bytes);
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -66,7 +60,7 @@ public class GetThumbnailQueryHandlerTests
|
||||
// Arrange
|
||||
GetThumbnailQuery query = _fixture.Create<GetThumbnailQuery>();
|
||||
Error error = Error.Failure("ThumbnailService.Error", "An error occurred");
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path, query.Quality, Arg.Any<CancellationToken>())
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -75,8 +69,7 @@ public class GetThumbnailQueryHandlerTests
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(error);
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path, query.Quality, Arg.Any<CancellationToken>());
|
||||
_mockMapper.DidNotReceive().Map<ThumbnailResponse>(Arg.Any<Thumbnail>());
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -87,12 +80,11 @@ public class GetThumbnailQueryHandlerTests
|
||||
CancellationTokenSource cts = new();
|
||||
cts.Cancel();
|
||||
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path, query.Quality, cts.Token)
|
||||
_mockThumbnailService.GetThumbnailAsync(query.Path!, query.Quality, cts.Token)
|
||||
.Returns(Task.FromCanceled<ErrorOr<Thumbnail>>(cts.Token));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<TaskCanceledException>(() => _sut.Handle(query, cts.Token).AsTask());
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path, query.Quality, cts.Token);
|
||||
_mockMapper.DidNotReceive().Map<ThumbnailResponse>(Arg.Any<Thumbnail>());
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, cts.Token);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetThumbnailQueryValidator"/> class.
|
||||
@@ -33,7 +33,7 @@ public class GetThumbnailQueryValidatorTests
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -46,7 +46,7 @@ public class GetThumbnailQueryValidatorTests
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -72,7 +72,7 @@ public class GetThumbnailQueryValidatorTests
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -85,7 +85,7 @@ public class GetThumbnailQueryValidatorTests
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
+50
-57
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
@@ -8,12 +8,11 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Models.Common;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using MapsterMapper;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -31,7 +30,6 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly IMapper _mockMapper;
|
||||
private readonly IBookRepository _mockBookRepository;
|
||||
private readonly AddBookCommandHandler _sut;
|
||||
private readonly AddBookCommandFixture _commandBookFixture;
|
||||
@@ -46,12 +44,11 @@ public class AddBookCommandHandlerTests
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockMapper = Substitute.For<IMapper>();
|
||||
_mockBookRepository = Substitute.For<IBookRepository>();
|
||||
|
||||
_mockUnitOfWork.GetRepository<IBookRepository>().Returns(_mockBookRepository);
|
||||
|
||||
_sut = new AddBookCommandHandler(_mockUnitOfWork, _mockMapper);
|
||||
_sut = new AddBookCommandHandler(_mockUnitOfWork);
|
||||
_commandBookFixture = new AddBookCommandFixture();
|
||||
}
|
||||
|
||||
@@ -60,19 +57,17 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
BookModel bookModel = _fixture.Create<BookModel>();
|
||||
|
||||
_mockMapper.Map<BookModel>(Arg.Any<Book>()).Returns(bookModel);
|
||||
_mockBookRepository.InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>())
|
||||
_mockBookRepository.InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().BeOfType<Book>();
|
||||
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Value.Should().BeOfType<BookResponse>();
|
||||
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -81,15 +76,15 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata with { Title = null } };
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { Title = null } };
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.Metadata.TitleCannotBeEmpty.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.TitleCannotBeEmpty.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -98,19 +93,17 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
BookModel bookModel = _fixture.Create<BookModel>();
|
||||
|
||||
_mockMapper.Map<BookModel>(Arg.Any<Book>()).Returns(bookModel);
|
||||
_mockBookRepository.InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>())
|
||||
_mockBookRepository.InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Errors.WrittenContent.BookAlreadyExists);
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(Errors.WrittenContent.BookAlreadyExists);
|
||||
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -119,15 +112,15 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { ISBNs = [new IsbnModel("invalid", IsbnFormat.Isbn13)] };
|
||||
bookCommand = bookCommand with { ISBNs = [new IsbnEntity("invalid", IsbnFormat.Isbn13)] };
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.WrittenContent.InvalidIsbn13Format.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.WrittenContent.InvalidIsbn13Format.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -136,15 +129,15 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Ratings = [new BookRatingModel(-1, 5, null, null)] };
|
||||
bookCommand = bookCommand with { Ratings = [new BookRatingEntity(-1, 5, null, null)] };
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.Metadata.RatingValueMustBePositive.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.RatingValueMustBePositive.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -155,19 +148,19 @@ public class AddBookCommandHandlerTests
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with
|
||||
{
|
||||
Metadata = bookCommand.Metadata with
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Genres = [new GenreModel("")]
|
||||
Genres = [new GenreEntity("")]
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.Metadata.GenreNameCannotBeEmpty.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.GenreNameCannotBeEmpty.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -178,19 +171,19 @@ public class AddBookCommandHandlerTests
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with
|
||||
{
|
||||
Metadata = bookCommand.Metadata with
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Tags = [new TagModel("")]
|
||||
Tags = [new TagEntity("")]
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.Metadata.TagNameCannotBeEmpty.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.TagNameCannotBeEmpty.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -201,9 +194,9 @@ public class AddBookCommandHandlerTests
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with
|
||||
{
|
||||
Metadata = bookCommand.Metadata with
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
ReleaseInfo = new ReleaseInfoModel(
|
||||
ReleaseInfo = new ReleaseInfoEntity(
|
||||
OriginalReleaseDate: new DateOnly(2025, 1, 1),
|
||||
ReReleaseDate: new DateOnly(2024, 1, 1),
|
||||
OriginalReleaseYear: null,
|
||||
@@ -215,12 +208,12 @@ public class AddBookCommandHandlerTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -231,19 +224,19 @@ public class AddBookCommandHandlerTests
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with
|
||||
{
|
||||
Metadata = bookCommand.Metadata with
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Language = new LanguageInfoModel("", "English", null)
|
||||
Language = new LanguageInfoEntity("", "English", null)
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.Metadata.LanguageCodeCannotBeEmpty.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -254,19 +247,19 @@ public class AddBookCommandHandlerTests
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with
|
||||
{
|
||||
Metadata = bookCommand.Metadata with
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
OriginalLanguage = new LanguageInfoModel("", "English", null)
|
||||
OriginalLanguage = new LanguageInfoEntity("", "English", null)
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.Errors.Should().Contain(e => e.Code == Errors.Metadata.LanguageCodeCannotBeEmpty.Code);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookModel>(), Arg.Any<CancellationToken>());
|
||||
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
|
||||
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
}
|
||||
+104
-104
@@ -41,7 +41,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Title).WithErrorMessage(Errors.Metadata.TitleCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Title).WithErrorMessage(Errors.Metadata.TitleCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -55,7 +55,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Title).WithErrorMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Title).WithErrorMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -69,7 +69,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Title);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -83,7 +83,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.OriginalTitle).WithErrorMessage(Errors.Metadata.OriginalTitleMustBeMaximum255CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.OriginalTitle).WithErrorMessage(Errors.Metadata.OriginalTitleMustBeMaximum255CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -97,7 +97,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.OriginalTitle);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.OriginalTitle);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -111,7 +111,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.OriginalTitle);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.OriginalTitle);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -125,7 +125,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Description).WithErrorMessage(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Description).WithErrorMessage(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -139,7 +139,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Description);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -153,7 +153,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Description);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -167,7 +167,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Description);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -181,7 +181,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo).WithErrorMessage(Errors.Metadata.ReleaseInfoCannotBeNull.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo).WithErrorMessage(Errors.Metadata.ReleaseInfoCannotBeNull.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -189,13 +189,13 @@ public class AddBookCommandValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { ReleaseInfo = bookCommand.Metadata.ReleaseInfo! with { OriginalReleaseYear = new Faker().Random.Int(2000, 2005), ReReleaseYear = new Faker().Random.Int(2005, 2010) } } };
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { ReleaseInfo = bookCommand.Metadata.ReleaseInfo! with { OriginalReleaseDate = null!, OriginalReleaseYear = new Faker().Random.Int(2000, 2005), ReReleaseYear = new Faker().Random.Int(2005, 2010), ReReleaseDate = null! } } };
|
||||
|
||||
// Act
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.OriginalReleaseYear);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.OriginalReleaseYear);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -209,7 +209,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.OriginalReleaseYear).WithErrorMessage(Errors.Metadata.OriginalReleaseYearMustBeBetween1And9999.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.OriginalReleaseYear).WithErrorMessage(Errors.Metadata.OriginalReleaseYearMustBeBetween1And9999.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -223,7 +223,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.OriginalReleaseYear).WithErrorMessage(Errors.Metadata.OriginalReleaseYearMustBeBetween1And9999.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.OriginalReleaseYear).WithErrorMessage(Errors.Metadata.OriginalReleaseYearMustBeBetween1And9999.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -237,7 +237,7 @@ public class AddBookCommandValidatorTests
|
||||
{
|
||||
ReleaseInfo = bookCommand.Metadata.ReleaseInfo!
|
||||
with
|
||||
{ OriginalReleaseYear = new Faker().Random.Int(2000, 2005), ReReleaseYear = new Faker().Random.Int(2005, 2010) }
|
||||
{ OriginalReleaseYear = new Faker().Random.Int(2000, 2005), ReReleaseYear = new Faker().Random.Int(2005, 2010), ReReleaseDate = null! }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -245,7 +245,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReReleaseYear);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReReleaseYear);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -259,7 +259,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReReleaseYear).WithErrorMessage(Errors.Metadata.ReReleaseYearMustBeBetween1And9999.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReReleaseYear).WithErrorMessage(Errors.Metadata.ReReleaseYearMustBeBetween1And9999.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -273,7 +273,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReReleaseYear).WithErrorMessage(Errors.Metadata.ReReleaseYearMustBeBetween1And9999.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReReleaseYear).WithErrorMessage(Errors.Metadata.ReReleaseYearMustBeBetween1And9999.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -287,7 +287,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReleaseCountry);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReleaseCountry);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -301,7 +301,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReleaseCountry).WithErrorMessage(Errors.Metadata.CountryCodeMustBe2CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReleaseCountry).WithErrorMessage(Errors.Metadata.CountryCodeMustBe2CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -315,7 +315,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReleaseVersion);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReleaseVersion);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -329,7 +329,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReleaseVersion).WithErrorMessage(Errors.Metadata.ReleaseVersionMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReleaseVersion).WithErrorMessage(Errors.Metadata.ReleaseVersionMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -337,13 +337,13 @@ public class AddBookCommandValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { ReleaseInfo = bookCommand.Metadata.ReleaseInfo! with { OriginalReleaseYear = 2000, ReReleaseYear = 2001 } } };
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { ReleaseInfo = bookCommand.Metadata.ReleaseInfo! with { OriginalReleaseYear = 2000, ReReleaseYear = 2001, ReReleaseDate = null! } } };
|
||||
|
||||
// Act
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReReleaseYear);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReReleaseYear);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -351,13 +351,13 @@ public class AddBookCommandValidatorTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { ReleaseInfo = bookCommand.Metadata.ReleaseInfo! with { OriginalReleaseYear = 2001, ReReleaseYear = 2000 } } };
|
||||
bookCommand = bookCommand with { Metadata = bookCommand.Metadata! with { ReleaseInfo = bookCommand.Metadata.ReleaseInfo! with { OriginalReleaseYear = 2001, ReReleaseYear = 2000, ReReleaseDate = null! } } };
|
||||
|
||||
// Act
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReReleaseYear).WithErrorMessage(Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReReleaseYear).WithErrorMessage(Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -371,7 +371,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReReleaseDate);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReReleaseDate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -385,7 +385,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.ReleaseInfo!.ReReleaseDate).WithErrorMessage(Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.ReleaseInfo!.ReReleaseDate).WithErrorMessage(Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -399,7 +399,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Genres).WithErrorMessage(Errors.Metadata.GenresListCannotBeNull.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Genres).WithErrorMessage(Errors.Metadata.GenresListCannotBeNull.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -413,7 +413,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Genres[0].Name").WithErrorMessage(Errors.Metadata.GenreNameCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Genres[0].Name").WithErrorMessage(Errors.Metadata.GenreNameCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -427,7 +427,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Genres[0].Name").WithErrorMessage(Errors.Metadata.GenreNameMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Genres[0].Name").WithErrorMessage(Errors.Metadata.GenreNameMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -447,7 +447,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Genres);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Genres);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -461,7 +461,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Tags).WithErrorMessage(Errors.Metadata.TagsListCannotBeNull.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Tags).WithErrorMessage(Errors.Metadata.TagsListCannotBeNull.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -475,7 +475,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Tags[0].Name").WithErrorMessage(Errors.Metadata.TagNameCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Tags[0].Name").WithErrorMessage(Errors.Metadata.TagNameCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -489,7 +489,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Tags[0].Name").WithErrorMessage(Errors.Metadata.TagNameMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor("Metadata.Tags[0].Name").WithErrorMessage(Errors.Metadata.TagNameMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -509,7 +509,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Tags);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Tags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -523,7 +523,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Language);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Language);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -537,7 +537,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Language!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Language!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -551,7 +551,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Language!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeMustBe2CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Language!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeMustBe2CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -565,7 +565,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Language!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Language!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -579,7 +579,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Language!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Language!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -593,7 +593,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Language!.NativeName);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Language!.NativeName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -607,7 +607,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Language!.NativeName).WithErrorMessage(Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Language!.NativeName).WithErrorMessage(Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -621,7 +621,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.OriginalLanguage);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.OriginalLanguage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -635,7 +635,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.OriginalLanguage!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.OriginalLanguage!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -649,7 +649,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.OriginalLanguage!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeMustBe2CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.OriginalLanguage!.LanguageCode).WithErrorMessage(Errors.Metadata.LanguageCodeMustBe2CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -663,7 +663,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.OriginalLanguage!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.OriginalLanguage!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -677,7 +677,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.OriginalLanguage!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.OriginalLanguage!.LanguageName).WithErrorMessage(Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -691,7 +691,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.OriginalLanguage!.NativeName);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.OriginalLanguage!.NativeName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -705,7 +705,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.OriginalLanguage!.NativeName).WithErrorMessage(Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.OriginalLanguage!.NativeName).WithErrorMessage(Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -719,7 +719,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Publisher);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Publisher);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -733,7 +733,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.Publisher);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.Publisher);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -747,7 +747,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.Publisher).WithErrorMessage(Errors.WrittenContent.PublisherMustBeMaximum100CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.Publisher).WithErrorMessage(Errors.WrittenContent.PublisherMustBeMaximum100CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -761,7 +761,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.PageCount);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.PageCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -775,7 +775,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.PageCount).WithErrorMessage(Errors.WrittenContent.PageCountMustBeGreaterThanZero.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.PageCount).WithErrorMessage(Errors.WrittenContent.PageCountMustBeGreaterThanZero.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -789,7 +789,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata.PageCount).WithErrorMessage(Errors.WrittenContent.PageCountMustBeGreaterThanZero.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Metadata!.PageCount).WithErrorMessage(Errors.WrittenContent.PageCountMustBeGreaterThanZero.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -803,7 +803,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata.PageCount);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Metadata!.PageCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -845,7 +845,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Format).WithErrorMessage(Errors.WrittenContent.UnknownBookFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Format).WithErrorMessage(Errors.WrittenContent.UnknownBookFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -887,7 +887,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Edition).WithErrorMessage(Errors.WrittenContent.EditionMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Edition).WithErrorMessage(Errors.WrittenContent.EditionMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -915,7 +915,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.VolumeNumber).WithErrorMessage(Errors.WrittenContent.VolumeNumberMustBeGreaterThanZero.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.VolumeNumber).WithErrorMessage(Errors.WrittenContent.VolumeNumberMustBeGreaterThanZero.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -929,7 +929,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.VolumeNumber).WithErrorMessage(Errors.WrittenContent.VolumeNumberMustBeGreaterThanZero.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.VolumeNumber).WithErrorMessage(Errors.WrittenContent.VolumeNumberMustBeGreaterThanZero.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -971,7 +971,7 @@ public class AddBookCommandValidatorTests
|
||||
// var result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// // Assert
|
||||
// result.ShouldHaveValidationErrorFor(x => x.Series.Title).WithErrorMessage(Errors.Metadata.TitleCannotBeEmpty.Code);
|
||||
// result.ShouldHaveValidationErrorFor(x => x.Series.Title).WithErrorMessage(Errors.Metadata.TitleCannotBeEmpty.Description);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
@@ -985,7 +985,7 @@ public class AddBookCommandValidatorTests
|
||||
// var result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// // Assert
|
||||
// result.ShouldHaveValidationErrorFor(x => x.Series.Title).WithErrorMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Code);
|
||||
// result.ShouldHaveValidationErrorFor(x => x.Series.Title).WithErrorMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Description);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
@@ -1041,7 +1041,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.ASIN).WithErrorMessage(Errors.WrittenContent.AsinMustBe10CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.ASIN).WithErrorMessage(Errors.WrittenContent.AsinMustBe10CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1083,7 +1083,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoodreadsId).WithErrorMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoodreadsId).WithErrorMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1097,7 +1097,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoodreadsId).WithErrorMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoodreadsId).WithErrorMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1111,7 +1111,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoodreadsId).WithErrorMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoodreadsId).WithErrorMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1153,7 +1153,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.LCCN).WithErrorMessage(Errors.WrittenContent.InvalidLccnFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.LCCN).WithErrorMessage(Errors.WrittenContent.InvalidLccnFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1167,7 +1167,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.LCCN).WithErrorMessage(Errors.WrittenContent.InvalidLccnFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.LCCN).WithErrorMessage(Errors.WrittenContent.InvalidLccnFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1181,7 +1181,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.LCCN).WithErrorMessage(Errors.WrittenContent.InvalidLccnFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.LCCN).WithErrorMessage(Errors.WrittenContent.InvalidLccnFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1279,7 +1279,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OCLCNumber).WithErrorMessage(Errors.WrittenContent.InvalidOclcFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.OCLCNumber).WithErrorMessage(Errors.WrittenContent.InvalidOclcFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1321,7 +1321,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OpenLibraryId).WithErrorMessage(Errors.WrittenContent.InvalidOpenLibraryId.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.OpenLibraryId).WithErrorMessage(Errors.WrittenContent.InvalidOpenLibraryId.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1335,7 +1335,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OpenLibraryId).WithErrorMessage(Errors.WrittenContent.InvalidOpenLibraryId.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.OpenLibraryId).WithErrorMessage(Errors.WrittenContent.InvalidOpenLibraryId.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1349,7 +1349,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OpenLibraryId).WithErrorMessage(Errors.WrittenContent.InvalidOpenLibraryId.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.OpenLibraryId).WithErrorMessage(Errors.WrittenContent.InvalidOpenLibraryId.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1391,7 +1391,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.LibraryThingId).WithErrorMessage(Errors.WrittenContent.LibraryThingIdMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.LibraryThingId).WithErrorMessage(Errors.WrittenContent.LibraryThingIdMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1419,7 +1419,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoogleBooksId).WithErrorMessage(Errors.WrittenContent.GoogleBooksIdMustBe12CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoogleBooksId).WithErrorMessage(Errors.WrittenContent.GoogleBooksIdMustBe12CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1433,7 +1433,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoogleBooksId).WithErrorMessage(Errors.WrittenContent.InvalidGoogleBooksIdFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.GoogleBooksId).WithErrorMessage(Errors.WrittenContent.InvalidGoogleBooksIdFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1475,7 +1475,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.BarnesAndNobleId).WithErrorMessage(Errors.WrittenContent.BarnesAndNoblesIdMustBe10CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.BarnesAndNobleId).WithErrorMessage(Errors.WrittenContent.BarnesAndNoblesIdMustBe10CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1489,7 +1489,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.BarnesAndNobleId).WithErrorMessage(Errors.WrittenContent.InvalidBarnesAndNoblesIdFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.BarnesAndNobleId).WithErrorMessage(Errors.WrittenContent.InvalidBarnesAndNoblesIdFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1545,7 +1545,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.AppleBooksId).WithErrorMessage(Errors.WrittenContent.InvalidAppleBooksIdFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.AppleBooksId).WithErrorMessage(Errors.WrittenContent.InvalidAppleBooksIdFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1559,7 +1559,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.ISBNs).WithErrorMessage(Errors.WrittenContent.IsbnListCannotBeNull.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.ISBNs).WithErrorMessage(Errors.WrittenContent.IsbnListCannotBeNull.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1573,7 +1573,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Value").WithErrorMessage(Errors.WrittenContent.IsbnValueCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Value").WithErrorMessage(Errors.WrittenContent.IsbnValueCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1587,7 +1587,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Value").WithErrorMessage(Errors.WrittenContent.InvalidIsbn10Format.Code);
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Value").WithErrorMessage(Errors.WrittenContent.InvalidIsbn10Format.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1601,7 +1601,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Value").WithErrorMessage(Errors.WrittenContent.InvalidIsbn13Format.Code);
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Value").WithErrorMessage(Errors.WrittenContent.InvalidIsbn13Format.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1615,7 +1615,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Format").WithErrorMessage(Errors.WrittenContent.UnknownIsbnFormat.Code);
|
||||
result.ShouldHaveValidationErrorFor("ISBNs[0].Format").WithErrorMessage(Errors.WrittenContent.UnknownIsbnFormat.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1629,7 +1629,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.ISBNs[0].Value);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.ISBNs![0].Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1643,7 +1643,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.ISBNs[0].Value);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.ISBNs![0].Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1657,7 +1657,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Contributors).WithErrorMessage(Errors.MediaContributor.ContributorsListCannotBeNull.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Contributors).WithErrorMessage(Errors.MediaContributor.ContributorsListCannotBeNull.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1671,7 +1671,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name").WithErrorMessage(Errors.MediaContributor.ContributorNameCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name").WithErrorMessage(Errors.MediaContributor.ContributorNameCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1685,7 +1685,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.DisplayName").WithErrorMessage(Errors.MediaContributor.ContributorDisplayNameMustBeMaximum100CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.DisplayName").WithErrorMessage(Errors.MediaContributor.ContributorDisplayNameMustBeMaximum100CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1699,7 +1699,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.DisplayName").WithErrorMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.DisplayName").WithErrorMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1713,7 +1713,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.LegalName").WithErrorMessage(Errors.MediaContributor.ContributorLegalNameMustBeMaximum100CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.LegalName").WithErrorMessage(Errors.MediaContributor.ContributorLegalNameMustBeMaximum100CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1727,7 +1727,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role").WithErrorMessage(Errors.MediaContributor.ContributorRoleCannotBeNull.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role").WithErrorMessage(Errors.MediaContributor.ContributorRoleCannotBeNull.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1741,7 +1741,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Name").WithErrorMessage(Errors.MediaContributor.RoleNameCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Name").WithErrorMessage(Errors.MediaContributor.RoleNameCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1755,7 +1755,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Name").WithErrorMessage(Errors.MediaContributor.RoleNameMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Name").WithErrorMessage(Errors.MediaContributor.RoleNameMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1769,7 +1769,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Category").WithErrorMessage(Errors.MediaContributor.RoleCategoryCannotBeEmpty.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Category").WithErrorMessage(Errors.MediaContributor.RoleCategoryCannotBeEmpty.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1783,7 +1783,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Category").WithErrorMessage(Errors.MediaContributor.RoleCategoryMustBeMaximum50CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Role.Category").WithErrorMessage(Errors.MediaContributor.RoleCategoryMustBeMaximum50CharactersLong.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1797,7 +1797,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Ratings).WithErrorMessage(Errors.Metadata.RatingsListCannotBeNull.Code);
|
||||
result.ShouldHaveValidationErrorFor(x => x.Ratings).WithErrorMessage(Errors.Metadata.RatingsListCannotBeNull.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1811,7 +1811,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].Value").WithErrorMessage(Errors.Metadata.RatingValueMustBePositive.Code);
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].Value").WithErrorMessage(Errors.Metadata.RatingValueMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1825,7 +1825,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].Value").WithErrorMessage(Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue.Code);
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].Value").WithErrorMessage(Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1839,7 +1839,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].MaxValue").WithErrorMessage(Errors.Metadata.RatingMaxValueMustBePositive.Code);
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].MaxValue").WithErrorMessage(Errors.Metadata.RatingMaxValueMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1853,7 +1853,7 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].VoteCount").WithErrorMessage(Errors.Metadata.RatingVoteCountMustBePositive.Code);
|
||||
result.ShouldHaveValidationErrorFor("Ratings[0].VoteCount").WithErrorMessage(Errors.Metadata.RatingVoteCountMustBePositive.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -1886,6 +1886,6 @@ public class AddBookCommandValidatorTests
|
||||
TestValidationResult<AddBookCommand> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Ratings[0].VoteCount);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Ratings![0].VoteCount);
|
||||
}
|
||||
}
|
||||
+46
-46
@@ -3,11 +3,11 @@ using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaContributors;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Models.Common;
|
||||
using Lumina.Contracts.Models.MediaContributors;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -46,8 +46,8 @@ public class AddBookCommandFixture
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
ReleaseInfoModel releaseInfo = new Faker<ReleaseInfoModel>()
|
||||
.CustomInstantiator(f => new ReleaseInfoModel(
|
||||
ReleaseInfoEntity releaseInfo = new Faker<ReleaseInfoEntity>()
|
||||
.CustomInstantiator(f => new ReleaseInfoEntity(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
@@ -63,42 +63,42 @@ public class AddBookCommandFixture
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.Generate();
|
||||
|
||||
Faker<GenreModel> genre = new Faker<GenreModel>()
|
||||
.CustomInstantiator(f => new GenreModel(
|
||||
Faker<GenreEntity> genre = new Faker<GenreEntity>()
|
||||
.CustomInstantiator(f => new GenreEntity(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<TagModel> tag = new Faker<TagModel>()
|
||||
.CustomInstantiator(f => new TagModel(
|
||||
Faker<TagEntity> tag = new Faker<TagEntity>()
|
||||
.CustomInstantiator(f => new TagEntity(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorRoleModel> mediaContributorRole = new Faker<MediaContributorRoleModel>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleModel(
|
||||
Faker<MediaContributorRoleEntity> mediaContributorRole = new Faker<MediaContributorRoleEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleEntity(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
Faker<MediaContributorNameModel> mediaContributorName = new Faker<MediaContributorNameModel>()
|
||||
.CustomInstantiator(f => new MediaContributorNameModel(
|
||||
Faker<MediaContributorNameEntity> mediaContributorName = new Faker<MediaContributorNameEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorNameEntity(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
Faker<MediaContributorModel> mediaContributor = new Faker<MediaContributorModel>()
|
||||
.CustomInstantiator(f => new MediaContributorModel(
|
||||
Faker<MediaContributorEntity> mediaContributor = new Faker<MediaContributorEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorEntity(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
Faker<BookRatingModel> rating = new Faker<BookRatingModel>()
|
||||
.CustomInstantiator(f => new BookRatingModel(
|
||||
Faker<BookRatingEntity> rating = new Faker<BookRatingEntity>()
|
||||
.CustomInstantiator(f => new BookRatingEntity(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
@@ -109,8 +109,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
|
||||
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
|
||||
|
||||
Faker<LanguageInfoModel> language = new Faker<LanguageInfoModel>()
|
||||
.CustomInstantiator(f => new LanguageInfoModel(
|
||||
Faker<LanguageInfoEntity> language = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
@@ -119,8 +119,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<LanguageInfoModel> originalLanguage = new Faker<LanguageInfoModel>()
|
||||
.CustomInstantiator(f => new LanguageInfoModel(
|
||||
Faker<LanguageInfoEntity> originalLanguage = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
@@ -129,8 +129,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<WrittenContentMetadataModel> metadata = new Faker<WrittenContentMetadataModel>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataModel(
|
||||
Faker<WrittenContentMetadataEntity> metadata = new Faker<WrittenContentMetadataEntity>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataEntity(
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
@@ -153,8 +153,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300));
|
||||
|
||||
Faker<IsbnModel> isbn = new Faker<IsbnModel>()
|
||||
.CustomInstantiator(f => new IsbnModel(
|
||||
Faker<IsbnEntity> isbn = new Faker<IsbnEntity>()
|
||||
.CustomInstantiator(f => new IsbnEntity(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
@@ -171,7 +171,7 @@ public class AddBookCommandFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
@@ -182,7 +182,7 @@ public class AddBookCommandFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class AddBookCommandFixture
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
_fixture.Register(() => new ReleaseInfoModel(
|
||||
_fixture.Register(() => new ReleaseInfoEntity(
|
||||
_faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)),
|
||||
releaseYear,
|
||||
_faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)),
|
||||
@@ -284,53 +284,53 @@ public class AddBookCommandFixture
|
||||
_fixture.Create<string>()[2..],
|
||||
_fixture.Create<string?>()));
|
||||
|
||||
_fixture.Register(() => new GenreModel(
|
||||
_fixture.Register(() => new GenreEntity(
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new TagModel(
|
||||
_fixture.Register(() => new TagEntity(
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new LanguageInfoModel(
|
||||
_fixture.Register(() => new LanguageInfoEntity(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string?>()
|
||||
));
|
||||
_fixture.Register(() => new IsbnModel(
|
||||
_fixture.Register(() => new IsbnEntity(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<IsbnFormat>()
|
||||
));
|
||||
_fixture.Register(() => new BookRatingModel(
|
||||
_fixture.Register(() => new BookRatingEntity(
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<BookRatingSource?>(),
|
||||
_fixture.Create<int?>()
|
||||
));
|
||||
_fixture.Register(() => new WrittenContentMetadataModel(
|
||||
_fixture.Register(() => new WrittenContentMetadataEntity(
|
||||
_fixture.Create<string>()[255..],
|
||||
LimitStringLength(_fixture.Create<string?>(), 255),
|
||||
LimitStringLength(_fixture.Create<string?>(), 2000),
|
||||
_fixture.Create<ReleaseInfoModel>(),
|
||||
_fixture.Create<List<GenreModel>>(),
|
||||
_fixture.Create<List<TagModel>>(),
|
||||
_fixture.Create<LanguageInfoModel?>(),
|
||||
_fixture.Create<LanguageInfoModel?>(),
|
||||
_fixture.Create<ReleaseInfoEntity>(),
|
||||
_fixture.Create<List<GenreEntity>>(),
|
||||
_fixture.Create<List<TagEntity>>(),
|
||||
_fixture.Create<LanguageInfoEntity?>(),
|
||||
_fixture.Create<LanguageInfoEntity?>(),
|
||||
_fixture.Create<string?>(),
|
||||
_fixture.Create<int?>()
|
||||
));
|
||||
_fixture.Register(() => new BookSeriesModel(
|
||||
_fixture.Register(() => new BookSeriesEntity(
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorRoleModel(
|
||||
_fixture.Register(() => new MediaContributorRoleEntity(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorNameModel(
|
||||
_fixture.Register(() => new MediaContributorNameEntity(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string?>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorModel(
|
||||
_fixture.Create<MediaContributorNameModel>(),
|
||||
_fixture.Create<MediaContributorRoleModel>()
|
||||
_fixture.Register(() => new MediaContributorEntity(
|
||||
_fixture.Create<MediaContributorNameEntity>(),
|
||||
_fixture.Create<MediaContributorRoleEntity>()
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaContributors;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary.Books;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AddBookRequest"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookRequestFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddBookRequestFixture"/> class.
|
||||
/// </summary>
|
||||
public AddBookRequestFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid request to add a book.
|
||||
/// </summary>
|
||||
/// <returns>The created request to add a book.</returns>
|
||||
public AddBookRequest CreateRequestBook()
|
||||
{
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
ReleaseInfoEntity releaseInfo = new Faker<ReleaseInfoEntity>()
|
||||
.CustomInstantiator(f => new ReleaseInfoEntity(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
|
||||
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
|
||||
.RuleFor(x => x.ReReleaseDate, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)))
|
||||
.RuleFor(x => x.ReReleaseYear, reReleaseYear)
|
||||
.RuleFor(x => x.ReleaseCountry, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.Generate();
|
||||
|
||||
Faker<GenreEntity> genre = new Faker<GenreEntity>()
|
||||
.CustomInstantiator(f => new GenreEntity(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<TagEntity> tag = new Faker<TagEntity>()
|
||||
.CustomInstantiator(f => new TagEntity(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorRoleEntity> mediaContributorRole = new Faker<MediaContributorRoleEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleEntity(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorNameEntity> mediaContributorName = new Faker<MediaContributorNameEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorNameEntity(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorEntity> mediaContributor = new Faker<MediaContributorEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorEntity(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
Faker<BookRatingEntity> rating = new Faker<BookRatingEntity>()
|
||||
.CustomInstantiator(f => new BookRatingEntity(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.Value, _random.Next(1, 5))
|
||||
.RuleFor(e => e.MaxValue, 5)
|
||||
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
|
||||
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
|
||||
|
||||
Faker<LanguageInfoEntity> language = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<LanguageInfoEntity> originalLanguage = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<WrittenContentMetadataEntity> metadata = new Faker<WrittenContentMetadataEntity>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataEntity(
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
|
||||
.RuleFor(x => x.ReleaseInfo, releaseInfo)
|
||||
.RuleFor(p => p.Genres, f => genre.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Tags, f => tag.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Language, language)
|
||||
.RuleFor(x => x.OriginalLanguage, originalLanguage)
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300));
|
||||
|
||||
Faker<IsbnEntity> isbn = new Faker<IsbnEntity>()
|
||||
.CustomInstantiator(f => new IsbnEntity(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(i => i.Value, f =>
|
||||
{
|
||||
bool isIsbn13 = f.Random.Bool();
|
||||
if (isIsbn13)
|
||||
{
|
||||
string prefix = f.Random.Bool() ? "978" : "979";
|
||||
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = f.Random.Number(0, 9);
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
})
|
||||
.RuleFor(i => i.Format, (f, i) => i.Value!.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
|
||||
|
||||
return new Faker<AddBookRequest>()
|
||||
.CustomInstantiator(f => new AddBookRequest(
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default!,
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(x => x.Metadata, metadata)
|
||||
.RuleFor(x => x.Format, _fixture.Create<BookFormat>())
|
||||
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
|
||||
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
|
||||
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
|
||||
.RuleFor(x => x.LCCN, f =>
|
||||
{
|
||||
string letters = new(Enumerable.Range(0, f.Random.Number(0, 3))
|
||||
.Select(_ => f.Random.Char('a', 'z'))
|
||||
.ToArray());
|
||||
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
|
||||
return letters + digits;
|
||||
})
|
||||
.RuleFor(x => x.OCLCNumber, f =>
|
||||
{
|
||||
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
|
||||
string prefix = f.Random.ArrayElement(prefixes);
|
||||
string number;
|
||||
switch (prefix)
|
||||
{
|
||||
case "ocm":
|
||||
number = f.Random.String2(8, "0123456789");
|
||||
break;
|
||||
case "ocn":
|
||||
number = f.Random.String2(f.Random.Number(9, 11), "0123456789");
|
||||
break;
|
||||
case "on":
|
||||
number = f.Random.String2(10, "0123456789");
|
||||
break;
|
||||
case "(OCoLC)":
|
||||
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
|
||||
break;
|
||||
default:
|
||||
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
|
||||
return number;
|
||||
}
|
||||
return prefix + number;
|
||||
})
|
||||
.RuleFor(x => x.OpenLibraryId, f =>
|
||||
{
|
||||
int firstDigit = f.Random.Number(1, 9);
|
||||
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
|
||||
char suffix = f.Random.ArrayElement(new[] { 'A', 'M', 'W' });
|
||||
return $"OL{firstDigit}{remainingDigits}{suffix}";
|
||||
})
|
||||
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.GoogleBooksId, f =>
|
||||
{
|
||||
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
return new string(Enumerable.Repeat(VALID_CHARS, 12)
|
||||
.Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])
|
||||
.ToArray());
|
||||
})
|
||||
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
|
||||
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
|
||||
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
|
||||
.RuleFor(p => p.ISBNs, f => isbn.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(p => p.Ratings, f => rating.Generate(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Contributors, f => mediaContributor.Generate(f.Random.Number(1, 5)));
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public BookEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid book entity.
|
||||
/// </summary>
|
||||
/// <returns>The created book entity.</returns>
|
||||
public BookEntity CreateBook()
|
||||
{
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
Faker<GenreEntity> genre = new Faker<GenreEntity>()
|
||||
.CustomInstantiator(f => new GenreEntity(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<TagEntity> tag = new Faker<TagEntity>()
|
||||
.CustomInstantiator(f => new TagEntity(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<BookRatingEntity> rating = new Faker<BookRatingEntity>()
|
||||
.CustomInstantiator(f => new BookRatingEntity(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
default
|
||||
))
|
||||
.RuleFor(e => e.Value, _random.Next(1, 5))
|
||||
.RuleFor(e => e.MaxValue, 5)
|
||||
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
|
||||
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
|
||||
|
||||
Faker<IsbnEntity> isbn = new Faker<IsbnEntity>()
|
||||
.CustomInstantiator(f => new IsbnEntity(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(i => i.Value, f =>
|
||||
{
|
||||
bool isIsbn13 = f.Random.Bool();
|
||||
if (isIsbn13)
|
||||
{
|
||||
string prefix = f.Random.Bool() ? "978" : "979";
|
||||
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = f.Random.Number(0, 9);
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
})
|
||||
.RuleFor(i => i.Format, (f, i) => i.Value!.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
|
||||
|
||||
return new BookEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Title = _faker.Random.String2(_faker.Random.Number(1, 255)),
|
||||
OriginalTitle = _faker.Random.Bool() ? _faker.Random.String2(_faker.Random.Number(1, 255)) : null,
|
||||
Description = _faker.Random.Bool() ? _faker.Random.String2(_faker.Random.Number(1, 2000)) : null,
|
||||
OriginalReleaseDate = _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)),
|
||||
OriginalReleaseYear = releaseYear,
|
||||
ReReleaseDate = _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)),
|
||||
ReReleaseYear = reReleaseYear,
|
||||
ReleaseCountry = _faker.Random.String2(2),
|
||||
ReleaseVersion = _faker.Random.Bool() ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
|
||||
LanguageCode = _faker.Random.String2(2),
|
||||
LanguageName = _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
LanguageNativeName = _faker.Random.Bool() ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
|
||||
OriginalLanguageCode = _faker.Random.String2(2),
|
||||
OriginalLanguageName = _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
OriginalLanguageNativeName = _faker.Random.Bool() ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
|
||||
Tags = new HashSet<TagEntity>(tag.Generate(_faker.Random.Number(1, 5))),
|
||||
Genres = new HashSet<GenreEntity>(genre.Generate(_faker.Random.Number(1, 5))),
|
||||
Publisher = _faker.Random.Bool() ? _faker.Random.String2(_faker.Random.Number(1, 100)) : null,
|
||||
PageCount = _random.Next(100, 1000),
|
||||
Format = _faker.PickRandom(new[] { "Hardcover", "Paperback", "eBook", "Audiobook" }),
|
||||
Edition = _faker.Random.Bool() ? _faker.Random.String2(_faker.Random.Number(1, 50)) : null,
|
||||
VolumeNumber = _faker.Random.Bool() ? _random.Next(1, 20) : null,
|
||||
ASIN = _faker.Random.String2(10),
|
||||
GoodreadsId = _random.Next(100000, 500000).ToString(),
|
||||
LCCN = _faker.Random.String2(_faker.Random.Number(8, 12)),
|
||||
OCLCNumber = _faker.Random.String2(_faker.Random.Number(8, 12)),
|
||||
OpenLibraryId = $"OL{_random.Next(1000000, 9999999)}M",
|
||||
LibraryThingId = _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
GoogleBooksId = _faker.Random.String2(12),
|
||||
BarnesAndNobleId = _faker.Random.String2(10),
|
||||
AppleBooksId = $"id{_random.Next(1, 999999)}",
|
||||
ISBNs = isbn.Generate(_faker.Random.Number(1, 5)),
|
||||
Ratings = rating.Generate(_faker.Random.Number(1, 5)),
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = _faker.Random.Bool() ? DateTime.UtcNow.AddDays(-_random.Next(1, 100)) : null
|
||||
};
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Book"/> domain entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DomainBookFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DomainBookFixture"/> class.
|
||||
/// </summary>
|
||||
public DomainBookFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
ConfigureCustomDomainTypes();
|
||||
}
|
||||
|
||||
public Book CreateDomainBook()
|
||||
{
|
||||
return Book.Create(
|
||||
_fixture.Create<WrittenContentMetadata>(),
|
||||
_fixture.Create<BookFormat>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<int>>(),
|
||||
_fixture.Create<Optional<BookSeries>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<List<Isbn>>(),
|
||||
_fixture.Create<List<MediaContributorId>>(),
|
||||
_fixture.Create<List<BookRating>>()
|
||||
).Value;
|
||||
}
|
||||
|
||||
private void ConfigureCustomDomainTypes()
|
||||
{
|
||||
_fixture.Register(() => Optional<string>.Some(_fixture.Create<string>()));
|
||||
_fixture.Register(() => Optional<int>.Some(_fixture.Create<int>()));
|
||||
|
||||
_fixture.Register(() => ReleaseInfo.Create(
|
||||
_fixture.Create<Optional<DateOnly>>(),
|
||||
_fixture.Create<Optional<int>>(),
|
||||
_fixture.Create<Optional<DateOnly>>(),
|
||||
_fixture.Create<Optional<int>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Genre.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Tag.Create(
|
||||
_fixture.Create<string>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => WrittenContentMetadata.Create(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<ReleaseInfo>(),
|
||||
_fixture.Create<List<Genre>>(),
|
||||
_fixture.Create<List<Tag>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<LanguageInfo>>(),
|
||||
_fixture.Create<Optional<string>>(),
|
||||
_fixture.Create<Optional<int>>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => Isbn.Create(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<IsbnFormat>()
|
||||
).Value);
|
||||
|
||||
_fixture.Register(() => BookRating.Create(
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<Optional<BookRatingSource>>(),
|
||||
_fixture.Create<Optional<int>>()
|
||||
).Value);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookRatingEntity"/>.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public BookRatingEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a complete book rating entity with all properties.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating entity.</returns>
|
||||
public BookRatingEntity CreateComplete()
|
||||
{
|
||||
return new BookRatingEntity(
|
||||
_random.Next(1, 5),
|
||||
5,
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
_random.Next(1, 1000)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a minimal book rating entity with only required properties.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating entity.</returns>
|
||||
public BookRatingEntity CreateMinimal()
|
||||
{
|
||||
return new BookRatingEntity(
|
||||
_random.Next(1, 5),
|
||||
5,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an invalid book rating entity.
|
||||
/// </summary>
|
||||
/// <returns>The created invalid book rating entity.</returns>
|
||||
public BookRatingEntity CreateInvalid()
|
||||
{
|
||||
return new BookRatingEntity(
|
||||
10, // invalid: value > maxValue
|
||||
5,
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
_random.Next(1, 1000)
|
||||
);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookRating"/> domain entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingFixture"/> class.
|
||||
/// </summary>
|
||||
public BookRatingFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid book rating.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating.</returns>
|
||||
public BookRating CreateBookRating()
|
||||
{
|
||||
decimal maxValue = _random.Next(5, 10);
|
||||
decimal value = _random.Next(1, (int)maxValue);
|
||||
Optional<BookRatingSource> source = Optional<BookRatingSource>.Some(_fixture.Create<BookRatingSource>());
|
||||
Optional<int> voteCount = Optional<int>.Some(_random.Next(1, 1000));
|
||||
|
||||
return BookRating.Create(value, maxValue, source, voteCount).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid book rating with specific parameters.
|
||||
/// </summary>
|
||||
/// <param name="value">The rating value.</param>
|
||||
/// <param name="maxValue">The maximum possible rating value.</param>
|
||||
/// <param name="source">The rating source.</param>
|
||||
/// <param name="voteCount">The number of votes.</param>
|
||||
/// <returns>The created book rating.</returns>
|
||||
public BookRating CreateBookRating(
|
||||
decimal value,
|
||||
decimal maxValue,
|
||||
Optional<BookRatingSource> source,
|
||||
Optional<int> voteCount)
|
||||
{
|
||||
return BookRating.Create(value, maxValue, source, voteCount).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid book rating without a source.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating.</returns>
|
||||
public BookRating CreateBookRatingWithoutSource()
|
||||
{
|
||||
decimal maxValue = _random.Next(5, 10);
|
||||
decimal value = _random.Next(1, (int)maxValue);
|
||||
Optional<int> voteCount = Optional<int>.Some(_random.Next(1, 1000));
|
||||
|
||||
return BookRating.Create(value, maxValue, Optional<BookRatingSource>.None(), voteCount).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid book rating without vote count.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating.</returns>
|
||||
public BookRating CreateBookRatingWithoutVoteCount()
|
||||
{
|
||||
decimal maxValue = _random.Next(5, 10);
|
||||
decimal value = _random.Next(1, (int)maxValue);
|
||||
Optional<BookRatingSource> source = Optional<BookRatingSource>.Some(_fixture.Create<BookRatingSource>());
|
||||
|
||||
return BookRating.Create(value, maxValue, source, Optional<int>.None()).Value;
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="IsbnEntity"/>.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnEntityFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid ISBN-10 entity.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN entity.</returns>
|
||||
public IsbnEntity CreateIsbn10()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
GenerateValidIsbn10(),
|
||||
IsbnFormat.Isbn10
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid ISBN-13 entity.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN entity.</returns>
|
||||
public IsbnEntity CreateIsbn13()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
GenerateValidIsbn13(),
|
||||
IsbnFormat.Isbn13
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an invalid ISBN entity.
|
||||
/// </summary>
|
||||
/// <returns>The created invalid ISBN entity.</returns>
|
||||
public IsbnEntity CreateInvalid()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
"invalid-isbn",
|
||||
IsbnFormat.Isbn13
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an ISBN entity without format.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN entity.</returns>
|
||||
public IsbnEntity CreateWithoutFormat()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
GenerateValidIsbn13(),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private string GenerateValidIsbn10()
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = _random.Next(0, 10);
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
|
||||
private string GenerateValidIsbn13()
|
||||
{
|
||||
string prefix = _random.Next(2) == 0 ? "978" : "979";
|
||||
string group = _random.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = _random.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = _random.Next(0, 99).ToString().PadLeft(2, '0');
|
||||
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Isbn"/> domain entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid ISBN-10.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN.</returns>
|
||||
public Isbn CreateIsbn10()
|
||||
{
|
||||
string isbn = GenerateValidIsbn10();
|
||||
return Isbn.Create(isbn, IsbnFormat.Isbn10).Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid ISBN-13.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN.</returns>
|
||||
public Isbn CreateIsbn13()
|
||||
{
|
||||
string isbn = GenerateValidIsbn13();
|
||||
return Isbn.Create(isbn, IsbnFormat.Isbn13).Value;
|
||||
}
|
||||
|
||||
private string GenerateValidIsbn10()
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = _random.Next(0, 10);
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
|
||||
private string GenerateValidIsbn13()
|
||||
{
|
||||
string prefix = _random.Next(2) == 0 ? "978" : "979";
|
||||
string group = _random.Next(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = _random.Next(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = _random.Next(0, 99).ToString().PadLeft(2, '0');
|
||||
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user