mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 14:01:11 +00:00
Updates to .NET 9.0
This commit is contained in:
commit
acbdb0a5f8
853 files changed
+34993
-10123
No files matched your search
-13
@@ -1,13 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Converters.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="OptionalJsonConverterFactory"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class OptionalJsonConverterFactoryFixture
|
||||
{
|
||||
}
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Converters;
|
||||
using Lumina.Application.UnitTests.Common.Converters.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFilesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class OptionalJsonConverterFactoryTests
|
||||
{
|
||||
private readonly OptionalJsonConverterFactory _factory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptionalJsonConverterFactoryTests"/> class.
|
||||
/// </summary>
|
||||
public OptionalJsonConverterFactoryTests()
|
||||
{
|
||||
_factory = new OptionalJsonConverterFactory();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanConvert_WhenTypeIsOptional_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Type typeToConvert = typeof(Optional<string>);
|
||||
|
||||
// Act
|
||||
bool result = _factory.CanConvert(typeToConvert);
|
||||
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanConvert_WhenTypeIsNotOptional_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
Type typeToConvert = typeof(string);
|
||||
|
||||
// Act
|
||||
bool result = _factory.CanConvert(typeToConvert);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanConvert_WhenTypeIsGenericButNotOptional_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
Type typeToConvert = typeof(List<string>);
|
||||
|
||||
// Act
|
||||
bool result = _factory.CanConvert(typeToConvert);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateConverter_WhenTypeIsOptionalString_ShouldReturnCorrectConverterType()
|
||||
{
|
||||
// Arrange
|
||||
Type typeToConvert = typeof(Optional<string>);
|
||||
JsonSerializerOptions options = new();
|
||||
|
||||
// Act
|
||||
JsonConverter converter = _factory.CreateConverter(typeToConvert, options);
|
||||
|
||||
// Assert
|
||||
converter.Should().BeOfType<OptionalJsonConverter<string>>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateConverter_WhenTypeIsOptionalInt_ShouldReturnCorrectConverterType()
|
||||
{
|
||||
// Arrange
|
||||
Type typeToConvert = typeof(Optional<int>);
|
||||
JsonSerializerOptions options = new();
|
||||
|
||||
// Act
|
||||
JsonConverter converter = _factory.CreateConverter(typeToConvert, options);
|
||||
|
||||
// Assert
|
||||
converter.Should().BeOfType<OptionalJsonConverter<int>>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateConverter_WhenTypeIsOptionalCustomClass_ShouldReturnCorrectConverterType()
|
||||
{
|
||||
// Arrange
|
||||
Type typeToConvert = typeof(Optional<OptionalJsonConverterFactoryFixture>);
|
||||
JsonSerializerOptions options = new();
|
||||
|
||||
// Act
|
||||
JsonConverter converter = _factory.CreateConverter(typeToConvert, options);
|
||||
|
||||
// Assert
|
||||
converter.Should().BeOfType<OptionalJsonConverter<OptionalJsonConverterFactoryFixture>>();
|
||||
}
|
||||
}
|
||||
-136
@@ -1,136 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Converters;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="OptionalJsonConverter"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class OptionalJsonConverterTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OptionalJsonConverterTests"/> class.
|
||||
/// </summary>
|
||||
public OptionalJsonConverterTests()
|
||||
{
|
||||
_options = new JsonSerializerOptions();
|
||||
_options.Converters.Add(new OptionalJsonConverter<string>());
|
||||
_options.Converters.Add(new OptionalJsonConverter<int>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Read_WhenJsonIsNull_ShouldReturnNone()
|
||||
{
|
||||
// Arrange
|
||||
string json = "null";
|
||||
|
||||
// Act
|
||||
Optional<string> result = JsonSerializer.Deserialize<Optional<string>>(json, _options);
|
||||
|
||||
// Assert
|
||||
result.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Read_WhenJsonHasStringValue_ShouldReturnSomeWithCorrectValue()
|
||||
{
|
||||
// Arrange
|
||||
string json = "\"test\"";
|
||||
|
||||
// Act
|
||||
Optional<string> result = JsonSerializer.Deserialize<Optional<string>>(json, _options);
|
||||
|
||||
// Assert
|
||||
result.HasValue.Should().BeTrue();
|
||||
result.Value.Should().Be("test");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Read_WhenJsonHasIntValue_ShouldReturnSomeWithCorrectValue()
|
||||
{
|
||||
// Arrange
|
||||
string json = "42";
|
||||
|
||||
// Act
|
||||
Optional<int> result = JsonSerializer.Deserialize<Optional<int>>(json, _options);
|
||||
|
||||
// Assert
|
||||
result.HasValue.Should().BeTrue();
|
||||
result.Value.Should().Be(42);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Write_WhenOptionalHasNoValue_ShouldWriteNull()
|
||||
{
|
||||
// Arrange
|
||||
Optional<string> optional = Optional<string>.None();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(optional, _options);
|
||||
|
||||
// Assert
|
||||
json.Should().Be("null");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Write_WhenOptionalHasStringValue_ShouldWriteCorrectJson()
|
||||
{
|
||||
// Arrange
|
||||
Optional<string> optional = Optional<string>.Some("test");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(optional, _options);
|
||||
|
||||
// Assert
|
||||
json.Should().Be("\"test\"");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Write_WhenOptionalHasIntValue_ShouldWriteCorrectJson()
|
||||
{
|
||||
// Arrange
|
||||
Optional<int> optional = Optional<int>.Some(42);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(optional, _options);
|
||||
|
||||
// Assert
|
||||
json.Should().Be("42");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadWrite_WhenSerializingAndDeserializingSomeValue_ShouldPreserveValue()
|
||||
{
|
||||
// Arrange
|
||||
Optional<string> original = Optional<string>.Some("test");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(original, _options);
|
||||
Optional<string> deserialized = JsonSerializer.Deserialize<Optional<string>>(json, _options);
|
||||
|
||||
// Assert
|
||||
deserialized.Should().Be(original);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadWrite_WhenSerializingAndDeserializingNone_ShouldPreserveNone()
|
||||
{
|
||||
// Arrange
|
||||
Optional<string> original = Optional<string>.None();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(original, _options);
|
||||
Optional<string> deserialized = JsonSerializer.Deserialize<Optional<string>>(json, _options);
|
||||
|
||||
// Assert
|
||||
deserialized.Should().Be(original);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.ChangePassword.Fixtures;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ChangePasswordRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordRequestMappingTests
|
||||
{
|
||||
private readonly ChangePasswordRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChangePasswordRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public ChangePasswordRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = _fixture.CreateChangePasswordRequest();
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.CurrentPassword.Should().Be(request.CurrentPassword);
|
||||
result.NewPassword.Should().Be(request.NewPassword);
|
||||
result.NewPasswordConfirm.Should().Be(request.NewPasswordConfirm);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = new(null, null, null, null);
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.CurrentPassword.Should().BeNull();
|
||||
result.NewPassword.Should().BeNull();
|
||||
result.NewPasswordConfirm.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "oldPass", "newPass", "newPass")]
|
||||
[InlineData("", "", "", "")]
|
||||
[InlineData("testUser", null, "pass123", "pass123")]
|
||||
public void ToCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? currentPassword,
|
||||
string? newPassword,
|
||||
string? newPasswordConfirm)
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = new(username, currentPassword, newPassword, newPasswordConfirm);
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.CurrentPassword.Should().Be(currentPassword);
|
||||
result.NewPassword.Should().Be(newPassword);
|
||||
result.NewPasswordConfirm.Should().Be(newPasswordConfirm);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LoginRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginRequestMappingTests
|
||||
{
|
||||
private readonly LoginRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LoginRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public LoginRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = _fixture.CreateLoginRequest();
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.Password.Should().Be(request.Password);
|
||||
result.TotpCode.Should().Be(request.TotpCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = new(null, null);
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.Password.Should().BeNull();
|
||||
result.TotpCode.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "pass123", "123456")]
|
||||
[InlineData("", "", "")]
|
||||
[InlineData("testUser", null, null)]
|
||||
[InlineData("admin", "admin123", null)]
|
||||
public void ToQuery_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? password,
|
||||
string? totpCode)
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = new(username, password, totpCode);
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.Password.Should().Be(password);
|
||||
result.TotpCode.Should().Be(totpCode);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RecoverPassword.Fixtures;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="RecoverPasswordRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordRequestMappingTests
|
||||
{
|
||||
private readonly RecoverPasswordRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RecoverPasswordRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public RecoverPasswordRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _fixture.CreateRecoverPasswordRequest();
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.TotpCode.Should().Be(request.TotpCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(null, null);
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.TotpCode.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "123456")]
|
||||
[InlineData("", "")]
|
||||
[InlineData("testUser", null)]
|
||||
[InlineData(null, "654321")]
|
||||
public void ToCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? totpCode)
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(username, totpCode);
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.TotpCode.Should().Be(totpCode);
|
||||
}
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Authentication;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="RegistrationRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RegistrationRequestMappingTests
|
||||
{
|
||||
private readonly RegistrationRequestFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegistrationRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public RegistrationRequestMappingTests()
|
||||
{
|
||||
_fixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToSetupCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _fixture.CreateRegistrationRequest();
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.Password.Should().Be(request.Password);
|
||||
result.PasswordConfirm.Should().Be(request.PasswordConfirm);
|
||||
result.Use2fa.Should().Be(request.Use2fa);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _fixture.CreateRegistrationRequest();
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(request.Username);
|
||||
result.Password.Should().Be(request.Password);
|
||||
result.PasswordConfirm.Should().Be(request.PasswordConfirm);
|
||||
result.Use2fa.Should().Be(request.Use2fa);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToSetupCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new();
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.Password.Should().BeNull();
|
||||
result.PasswordConfirm.Should().BeNull();
|
||||
result.Use2fa.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new();
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().BeNull();
|
||||
result.Password.Should().BeNull();
|
||||
result.PasswordConfirm.Should().BeNull();
|
||||
result.Use2fa.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "pass123", "pass123", true)]
|
||||
[InlineData("", "", "", false)]
|
||||
[InlineData("testUser", null, null, true)]
|
||||
[InlineData(null, "pass123", "pass123", false)]
|
||||
public void ToSetupCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? password,
|
||||
string? passwordConfirm,
|
||||
bool use2fa)
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new(username, password, passwordConfirm, use2fa);
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.Password.Should().Be(password);
|
||||
result.PasswordConfirm.Should().Be(passwordConfirm);
|
||||
result.Use2fa.Should().Be(use2fa);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1", "pass123", "pass123", true)]
|
||||
[InlineData("", "", "", false)]
|
||||
[InlineData("testUser", null, null, true)]
|
||||
[InlineData(null, "pass123", "pass123", false)]
|
||||
public void ToCommand_WhenMappingRequestWithSpecificValues_ShouldMapCorrectly(
|
||||
string? username,
|
||||
string? password,
|
||||
string? passwordConfirm,
|
||||
bool use2fa)
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new(username, password, passwordConfirm, use2fa);
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
result.Password.Should().Be(password);
|
||||
result.PasswordConfirm.Should().Be(passwordConfirm);
|
||||
result.Use2fa.Should().Be(use2fa);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GenreDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreDtoMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidGenreDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = new("Rock");
|
||||
|
||||
// Act
|
||||
ErrorOr<Genre> result = genreDto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Name.Should().Be(genreDto.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Rock")]
|
||||
[InlineData("Jazz")]
|
||||
[InlineData("Classical")]
|
||||
[InlineData("Pop")]
|
||||
public void ToDomainEntity_WhenMappingDifferentValidGenreDtos_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = new(name);
|
||||
|
||||
// Act
|
||||
ErrorOr<Genre> result = genreDto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Name.Should().Be(genreDto.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidGenreDto_ShouldReturnError(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = new(invalidName);
|
||||
|
||||
// Act
|
||||
ErrorOr<Genre> result = genreDto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidGenreDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GenreDto> genreDtos =
|
||||
[
|
||||
new GenreDto("Rock"),
|
||||
new GenreDto("Jazz"),
|
||||
new GenreDto("Classical"),
|
||||
new GenreDto("Pop")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(genreDtos.Count);
|
||||
|
||||
List<ErrorOr<Genre>> resultList = results.ToList();
|
||||
for (int i = 0; i < genreDtos.Count; i++)
|
||||
{
|
||||
resultList[i].IsError.Should().BeFalse();
|
||||
resultList[i].Value.Name.Should().Be(genreDtos[i].Name);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidGenreDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<GenreDto> genreDtos =
|
||||
[
|
||||
new GenreDto("Rock"),
|
||||
new GenreDto(""),
|
||||
new GenreDto("Jazz"),
|
||||
new GenreDto(" ")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(genreDtos.Count);
|
||||
|
||||
List<ErrorOr<Genre>> resultList = results.ToList();
|
||||
resultList[0].IsError.Should().BeFalse();
|
||||
resultList[0].Value.Name.Should().Be("Rock");
|
||||
|
||||
resultList[1].IsError.Should().BeTrue();
|
||||
|
||||
resultList[2].IsError.Should().BeFalse();
|
||||
resultList[2].Value.Name.Should().Be("Jazz");
|
||||
|
||||
resultList[3].IsError.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GenreEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreEntityMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidGenreEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new("Fiction");
|
||||
|
||||
// Act
|
||||
GenreDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(entity.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Fiction")]
|
||||
[InlineData("Science Fiction")]
|
||||
[InlineData("Mystery")]
|
||||
[InlineData("Romance")]
|
||||
public void ToResponse_WhenMappingDifferentValidGenreEntities_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new(name);
|
||||
|
||||
// Act
|
||||
GenreDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(entity.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToResponse_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new(invalidName);
|
||||
|
||||
// Act
|
||||
GenreDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Name.Should().Be(invalidName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidGenreEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new("Fiction");
|
||||
|
||||
// Act
|
||||
ErrorOr<Genre> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Name.Should().Be(entity.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new(invalidName);
|
||||
|
||||
// Act
|
||||
ErrorOr<Genre> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(Errors.Metadata.GenreNameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GenreEntity> entities =
|
||||
[
|
||||
new GenreEntity("Fiction"),
|
||||
new GenreEntity("Mystery"),
|
||||
new GenreEntity("Romance"),
|
||||
new GenreEntity("Thriller")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Genre>> results = entities.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<ErrorOr<Genre>> resultList = results.ToList();
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
resultList[i].IsError.Should().BeFalse();
|
||||
resultList[i].Value.Name.Should().Be(entities[i].Name);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GenreEntity> entities =
|
||||
[
|
||||
new GenreEntity("Fiction"),
|
||||
new GenreEntity("Mystery"),
|
||||
new GenreEntity("Romance"),
|
||||
new GenreEntity("Thriller")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<GenreDto> results = entities.ToResponses();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<GenreDto> resultList = results.ToList();
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(entities[i].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GenreMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingGenre_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Genre> createResult = Genre.Create("Rock");
|
||||
createResult.IsError.Should().BeFalse();
|
||||
Genre genre = createResult.Value;
|
||||
|
||||
// Act
|
||||
GenreEntity result = genre.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(genre.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Rock")]
|
||||
[InlineData("Jazz")]
|
||||
[InlineData("Classical")]
|
||||
[InlineData("Pop")]
|
||||
public void ToRepositoryEntity_WhenMappingDifferentGenres_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Genre> createResult = Genre.Create(name);
|
||||
createResult.IsError.Should().BeFalse();
|
||||
Genre genre = createResult.Value;
|
||||
|
||||
// Act
|
||||
GenreEntity result = genre.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(genre.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleGenres_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Genre> genres =
|
||||
[
|
||||
Genre.Create("Rock").Value,
|
||||
Genre.Create("Jazz").Value,
|
||||
Genre.Create("Classical").Value,
|
||||
Genre.Create("Pop").Value
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<GenreEntity> results = genres.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(genres.Count);
|
||||
List<GenreEntity> resultList = results.ToList();
|
||||
for (int i = 0; i < genres.Count; i++)
|
||||
resultList[i].Name.Should().Be(genres[i].Name);
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TagDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagDtoMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTagDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = new("indie");
|
||||
|
||||
// Act
|
||||
ErrorOr<Tag> result = tagDto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Name.Should().Be(tagDto.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("indie")]
|
||||
[InlineData("electronic")]
|
||||
[InlineData("instrumental")]
|
||||
[InlineData("live")]
|
||||
[InlineData("acoustic")]
|
||||
public void ToDomainEntity_WhenMappingDifferentValidTagDtos_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = new(name);
|
||||
|
||||
// Act
|
||||
ErrorOr<Tag> result = tagDto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Name.Should().Be(tagDto.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidTagDto_ShouldReturnError(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = new(invalidName);
|
||||
|
||||
// Act
|
||||
ErrorOr<Tag> result = tagDto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidTagDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<TagDto> tagDtos =
|
||||
[
|
||||
new TagDto("indie"),
|
||||
new TagDto("electronic"),
|
||||
new TagDto("instrumental"),
|
||||
new TagDto("live")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(tagDtos.Count);
|
||||
|
||||
List<ErrorOr<Tag>> resultList = results.ToList();
|
||||
for (int i = 0; i < tagDtos.Count; i++)
|
||||
{
|
||||
resultList[i].IsError.Should().BeFalse();
|
||||
resultList[i].Value.Name.Should().Be(tagDtos[i].Name);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidTagDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<TagDto> tagDtos =
|
||||
[
|
||||
new TagDto("indie"),
|
||||
new TagDto(""),
|
||||
new TagDto("electronic"),
|
||||
new TagDto(" ")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(tagDtos.Count);
|
||||
|
||||
List<ErrorOr<Tag>> resultList = results.ToList();
|
||||
resultList[0].IsError.Should().BeFalse();
|
||||
resultList[0].Value.Name.Should().Be("indie");
|
||||
|
||||
resultList[1].IsError.Should().BeTrue();
|
||||
|
||||
resultList[2].IsError.Should().BeFalse();
|
||||
resultList[2].Value.Name.Should().Be("electronic");
|
||||
|
||||
resultList[3].IsError.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TagEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagEntityMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidTagEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new("Fantasy");
|
||||
|
||||
// Act
|
||||
TagDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(entity.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Fantasy")]
|
||||
[InlineData("Young Adult")]
|
||||
[InlineData("Historical")]
|
||||
[InlineData("Coming of Age")]
|
||||
public void ToResponse_WhenMappingDifferentValidTagEntities_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new(name);
|
||||
|
||||
// Act
|
||||
TagDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(entity.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToResponse_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new(invalidName);
|
||||
|
||||
// Act
|
||||
TagDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Name.Should().Be(invalidName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTagEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new("Fantasy");
|
||||
|
||||
// Act
|
||||
ErrorOr<Tag> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Name.Should().Be(entity.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new(invalidName);
|
||||
|
||||
// Act
|
||||
ErrorOr<Tag> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
result.FirstError.Should().Be(Errors.Metadata.TagNameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<TagEntity> entities =
|
||||
[
|
||||
new TagEntity("Fantasy"),
|
||||
new TagEntity("Young Adult"),
|
||||
new TagEntity("Historical"),
|
||||
new TagEntity("Coming of Age")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Tag>> results = entities.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<ErrorOr<Tag>> resultList = results.ToList();
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
resultList[i].IsError.Should().BeFalse();
|
||||
resultList[i].Value.Name.Should().Be(entities[i].Name);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<TagEntity> entities =
|
||||
[
|
||||
new TagEntity("Fantasy"),
|
||||
new TagEntity("Young Adult"),
|
||||
new TagEntity("Historical"),
|
||||
new TagEntity("Coming of Age")
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<TagDto> results = entities.ToResponses();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<TagDto> resultList = results.ToList();
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(entities[i].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TagMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingTag_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Tag> createResult = Tag.Create("indie");
|
||||
createResult.IsError.Should().BeFalse();
|
||||
Tag tag = createResult.Value;
|
||||
|
||||
// Act
|
||||
TagEntity result = tag.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(tag.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("indie")]
|
||||
[InlineData("electronic")]
|
||||
[InlineData("instrumental")]
|
||||
[InlineData("live")]
|
||||
[InlineData("acoustic")]
|
||||
public void ToRepositoryEntity_WhenMappingDifferentTags_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Tag> createResult = Tag.Create(name);
|
||||
createResult.IsError.Should().BeFalse();
|
||||
Tag tag = createResult.Value;
|
||||
|
||||
// Act
|
||||
TagEntity result = tag.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(tag.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleTags_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Tag> tags =
|
||||
[
|
||||
Tag.Create("indie").Value,
|
||||
Tag.Create("electronic").Value,
|
||||
Tag.Create("instrumental").Value,
|
||||
Tag.Create("live").Value,
|
||||
Tag.Create("acoustic").Value
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<TagEntity> results = tags.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(tags.Count);
|
||||
List<TagEntity> resultList = results.ToList();
|
||||
for (int i = 0; i < tags.Count; i++)
|
||||
resultList[i].Name.Should().Be(tags[i].Name);
|
||||
}
|
||||
}
|
||||
-113
@@ -1,113 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Contracts.Models.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Mapster;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DirectoryMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryMappingConfigTests
|
||||
{
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly DirectoryMappingConfig _directoryMappingConfig;
|
||||
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
|
||||
|
||||
public DirectoryMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_directoryMappingConfig = new DirectoryMappingConfig();
|
||||
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
|
||||
_directoryMappingConfig.Register(_config);
|
||||
_fileSystemTreeMappingConfig.Register(_config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingDirectoryToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
|
||||
// create some child items
|
||||
List<FileSystemItem> childItems =
|
||||
[
|
||||
directoryFixture.CreateDirectory(),
|
||||
directoryFixture.CreateDirectory()
|
||||
];
|
||||
foreach (FileSystemItem item in childItems)
|
||||
directory.AddItem(item);
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.ItemType.Should().Be(directory.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().HaveCount(childItems.Count);
|
||||
|
||||
// Verify that each child item is correctly mapped
|
||||
for (int i = 0; i < childItems.Count; i++)
|
||||
{
|
||||
result.Children[i].Name.Should().Be(childItems[i].Name);
|
||||
result.Children[i].Path.Should().Be(childItems[i].Id.Path);
|
||||
result.Children[i].ItemType.Should().Be(childItems[i].Type);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingDirectoryToDirectoryResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
|
||||
// Act
|
||||
DirectoryResponse result = directory.Adapt<DirectoryResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.DateCreated.Should().Be(directory.DateCreated.Value);
|
||||
result.DateModified.Should().Be(directory.DateModified.Value);
|
||||
result.Items.Should().BeAssignableTo<List<FileSystemItemModel>>();
|
||||
result.Items.Should().HaveCount(directory.Items.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingDirectoryToFileSystemItemModel_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
DateTime beforeMapping = DateTime.Now;
|
||||
|
||||
// Act
|
||||
FileSystemItemModel result = directory.Adapt<FileSystemItemModel>(_config);
|
||||
DateTime afterMapping = DateTime.Now;
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.DateCreated.Should().BeOnOrAfter(beforeMapping).And.BeOnOrBefore(afterMapping);
|
||||
result.DateModified.Should().BeOnOrAfter(beforeMapping).And.BeOnOrBefore(afterMapping);
|
||||
}
|
||||
}
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Mapster;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileMappingConfigTests
|
||||
{
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly FileMappingConfig _fileMappingConfig;
|
||||
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
|
||||
|
||||
public FileMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_fileMappingConfig = new FileMappingConfig();
|
||||
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
|
||||
_fileMappingConfig.Register(_config);
|
||||
_fileSystemTreeMappingConfig.Register(_config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = file.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.ItemType.Should().Be(file.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileResponse result = file.Adapt<FileResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.DateCreated.Should().Be(file.DateCreated.Value);
|
||||
result.DateModified.Should().Be(file.DateModified.Value);
|
||||
result.Size.Should().Be(file.Size);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileResponseWithoutDates_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = FileFixture.CreateFileWithoutDates();
|
||||
|
||||
// Act
|
||||
FileResponse result = file.Adapt<FileResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.DateCreated.Should().Be(default);
|
||||
result.DateModified.Should().Be(default);
|
||||
result.Size.Should().Be(file.Size);
|
||||
}
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Mapster;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemTreeMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTreeMappingConfigTests
|
||||
{
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
|
||||
|
||||
public FileSystemTreeMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
|
||||
_fileSystemTreeMappingConfig.Register(_config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingWindowsRootItemToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
WindowsRootItem windowsRoot = WindowsRootItem.Create("C:", "C:").Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = windowsRoot.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(windowsRoot.Id.Path);
|
||||
result.Name.Should().Be(windowsRoot.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileSystemTreeNodeResponseToWindowsRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = new()
|
||||
{
|
||||
Path = "D:",
|
||||
Name = "D:",
|
||||
ItemType = FileSystemItemType.Root,
|
||||
IsExpanded = false
|
||||
};
|
||||
|
||||
// Act
|
||||
WindowsRootItem result = response.Adapt<WindowsRootItem>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Path.Should().Be(response.Path);
|
||||
result.Name.Should().Be(response.Name);
|
||||
result.Type.Should().Be(FileSystemItemType.Root);
|
||||
result.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingUnixRootItemToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UnixRootItem unixRoot = UnixRootItem.Create().Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = unixRoot.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(unixRoot.Id.Path);
|
||||
result.Name.Should().Be(unixRoot.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileSystemTreeNodeResponseToUnixRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = new()
|
||||
{
|
||||
Path = "/",
|
||||
Name = "/",
|
||||
ItemType = FileSystemItemType.Root,
|
||||
IsExpanded = false
|
||||
};
|
||||
|
||||
// Act
|
||||
UnixRootItem result = response.Adapt<UnixRootItem>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Path.Should().Be("/");
|
||||
result.Name.Should().Be("/");
|
||||
result.Type.Should().Be(FileSystemItemType.Root);
|
||||
result.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingDirectoryToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
directory.AddItem(directoryFixture.CreateDirectory());
|
||||
directory.AddItem(directoryFixture.CreateDirectory());
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.ItemType.Should().Be(directory.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().HaveCount(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = file.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.ItemType.Should().Be(file.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Contracts.Enums.PhotoLibrary;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Mapster;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ThumbnailMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThumbnailMappingConfigTests
|
||||
{
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly ThumbnailMappingConfig _thumbnailMappingConfig;
|
||||
private readonly Faker _faker;
|
||||
|
||||
public ThumbnailMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_thumbnailMappingConfig = new ThumbnailMappingConfig();
|
||||
_thumbnailMappingConfig.Register(_config);
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingThumbnailToThumbnailResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ImageType imageType = _faker.PickRandom<ImageType>();
|
||||
byte[] bytes = _faker.Random.Bytes(100);
|
||||
Thumbnail thumbnail = new(imageType, bytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = thumbnail.Adapt<ThumbnailResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(thumbnail.Type);
|
||||
result.Bytes.Should().BeEquivalentTo(thumbnail.Bytes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ImageType.JPEG)]
|
||||
[InlineData(ImageType.PNG)]
|
||||
[InlineData(ImageType.GIF)]
|
||||
public void Register_WhenMappingDifferentImageTypes_ShouldMapCorrectly(ImageType imageType)
|
||||
{
|
||||
// Arrange
|
||||
byte[] bytes = _faker.Random.Bytes(100);
|
||||
Thumbnail thumbnail = new(imageType, bytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = thumbnail.Adapt<ThumbnailResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEquivalentTo(bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingThumbnailWithEmptyBytes_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ImageType imageType = _faker.PickRandom<ImageType>();
|
||||
byte[] emptyBytes = [];
|
||||
Thumbnail thumbnail = new(imageType, emptyBytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = thumbnail.Adapt<ThumbnailResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingMultipleThumbnails_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Thumbnail> thumbnails =
|
||||
[
|
||||
new Thumbnail(ImageType.JPEG, _faker.Random.Bytes(100)),
|
||||
new Thumbnail(ImageType.PNG, _faker.Random.Bytes(200)),
|
||||
new Thumbnail(ImageType.GIF, _faker.Random.Bytes(150))
|
||||
];
|
||||
|
||||
// Act
|
||||
List<ThumbnailResponse> results = thumbnails.Adapt<List<ThumbnailResponse>>(_config);
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(thumbnails.Count);
|
||||
for (int i = 0; i < thumbnails.Count; i++)
|
||||
{
|
||||
results[i].Type.Should().Be(thumbnails[i].Type);
|
||||
results[i].Bytes.Should().BeEquivalentTo(thumbnails[i].Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Common;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemTreeNodeResponseMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTreeNodeResponseMappingTests
|
||||
{
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemTreeNodeResponseMappingTests"/> class.
|
||||
/// </summary>
|
||||
public FileSystemTreeNodeResponseMappingTests()
|
||||
{
|
||||
_fileSystemTreeNodeResponseFixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToWindowsRootItem_WhenMappingFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = _fileSystemTreeNodeResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
ErrorOr<WindowsRootItem> result = response.ToWindowsRootItem();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Id.Path.Should().Be(response.Path);
|
||||
result.Value.Name.Should().Be(response.Name);
|
||||
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToUnixRootItem_WhenMappingFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = _fileSystemTreeNodeResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
ErrorOr<UnixRootItem> result = response.ToUnixRootItem();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DirectoryMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryMappingTests
|
||||
{
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DirectoryMappingTests"/> class.
|
||||
/// </summary>
|
||||
public DirectoryMappingTests()
|
||||
{
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Directory directory = _directoryFixture.CreateDirectory();
|
||||
List<FileSystemItem> childItems =
|
||||
[
|
||||
_directoryFixture.CreateDirectory(),
|
||||
_directoryFixture.CreateDirectory()
|
||||
];
|
||||
foreach (FileSystemItem item in childItems)
|
||||
directory.AddItem(item);
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.ToFileSystemTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.ItemType.Should().Be(directory.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().HaveCount(childItems.Count);
|
||||
|
||||
for (int i = 0; i < childItems.Count; i++)
|
||||
{
|
||||
result.Children[i].Name.Should().Be(childItems[i].Name);
|
||||
result.Children[i].Path.Should().Be(childItems[i].Id.Path);
|
||||
result.Children[i].ItemType.Should().Be(childItems[i].Type);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponses_WhenMappingMultipleDirectories_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Directory> directories = _directoryFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = directories.ToFileSystemTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(directories.Count);
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
for (int i = 0; i < directories.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(directories[i].Name);
|
||||
resultList[i].Path.Should().Be(directories[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(directories[i].Type);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingDirectory_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Directory directory = _directoryFixture.CreateDirectory();
|
||||
List<FileSystemItem> childItems =
|
||||
[
|
||||
_directoryFixture.CreateDirectory(),
|
||||
_directoryFixture.CreateDirectory()
|
||||
];
|
||||
foreach (FileSystemItem item in childItems)
|
||||
directory.AddItem(item);
|
||||
|
||||
// Act
|
||||
DirectoryResponse result = directory.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.DateCreated.Should().Be(directory.DateCreated.Value);
|
||||
result.DateModified.Should().Be(directory.DateModified.Value);
|
||||
result.Items.Should().NotBeNull();
|
||||
result.Items.Should().HaveCount(childItems.Count);
|
||||
|
||||
for (int i = 0; i < childItems.Count; i++)
|
||||
{
|
||||
result.Items[i].Name.Should().Be(childItems[i].Name);
|
||||
result.Items[i].Path.Should().Be(childItems[i].Id.Path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleDirectories_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Directory> directories = _directoryFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IEnumerable<DirectoryResponse> result = directories.ToResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(directories.Count);
|
||||
|
||||
List<DirectoryResponse> resultList = result.ToList();
|
||||
for (int i = 0; i < directories.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(directories[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(directories[i].Name);
|
||||
resultList[i].DateCreated.Should().Be(directories[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(directories[i].DateModified.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoriesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoriesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoriesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetDirectoriesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
|
||||
// Act
|
||||
GetDirectoriesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoryTreeRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoryTreeRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoryTreeRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoryTreeRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetDirectoryTreeRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoryTreeRequest request = _fixture.Create<GetDirectoryTreeRequest>();
|
||||
|
||||
// Act
|
||||
GetDirectoryTreeQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeFiles.Should().Be(request.IncludeFiles);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeDirectoriesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeDirectoriesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetTreeDirectoriesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesRequest request = _fixture.Create<GetTreeDirectoriesRequest>();
|
||||
|
||||
// Act
|
||||
GetTreeDirectoriesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Lumina.Contracts.DTO.FileSystemManagement;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemItemMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemItemMappingTests
|
||||
{
|
||||
private readonly FileSystemPathIdFixture _fileSystemPathIdFixture;
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
private readonly FileFixture _fileFixture;
|
||||
private readonly WindowsRootItemFixture _windowsRootItemFixture;
|
||||
private readonly UnixRootItemFixture _unixRootItemFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemItemMappingTests"/> class.
|
||||
/// </summary>
|
||||
public FileSystemItemMappingTests()
|
||||
{
|
||||
_fileSystemPathIdFixture = new FileSystemPathIdFixture();
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
_fileFixture = new FileFixture();
|
||||
_windowsRootItemFixture = new WindowsRootItemFixture();
|
||||
_unixRootItemFixture = new UnixRootItemFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemItemModel_WhenMappingFileSystemItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId id = _fileSystemPathIdFixture.CreateFileSystemPathId();
|
||||
string name = "TestItem";
|
||||
FileSystemItemType type = FileSystemItemType.File;
|
||||
FileSystemItemFixture domainModel = new(id, name, type);
|
||||
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.DateCreated.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
result.DateModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Directory directory = _directoryFixture.CreateDirectory();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.ItemType.Should().Be(directory.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
File file = _fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = file.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.ItemType.Should().Be(file.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingWindowsRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
WindowsRootItem windowsRootItem = _windowsRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = windowsRootItem.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(windowsRootItem.Name);
|
||||
result.Path.Should().Be(windowsRootItem.Id.Path);
|
||||
result.ItemType.Should().Be(windowsRootItem.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingUnixRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UnixRootItem unixRootItem = _unixRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = unixRootItem.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(unixRootItem.Name);
|
||||
result.Path.Should().Be(unixRootItem.Id.Path);
|
||||
result.ItemType.Should().Be(unixRootItem.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("TestFile.txt", FileSystemItemType.File)]
|
||||
[InlineData("TestFolder", FileSystemItemType.Directory)]
|
||||
public void ToFileSystemItemModel_WhenMappingDifferentFileSystemItems_ShouldMapCorrectly(string name, FileSystemItemType type)
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId id = _fileSystemPathIdFixture.CreateFileSystemPathId();
|
||||
FileSystemItemFixture domainModel = new(id, name, type);
|
||||
|
||||
// Act
|
||||
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.DateCreated.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
result.DateModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponses_WhenMappingMixedFileSystemItems_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<FileSystemItem> domainModels =
|
||||
[
|
||||
_directoryFixture.CreateDirectory(),
|
||||
_fileFixture.CreateFile(),
|
||||
_windowsRootItemFixture.Create(),
|
||||
_unixRootItemFixture.Create()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count);
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModels[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModels[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(domainModels[i].Type);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingInvalidFileSystemItem_ShouldThrowArgumentException()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId id = _fileSystemPathIdFixture.CreateFileSystemPathId();
|
||||
string name = "TestItem";
|
||||
FileSystemItemType type = FileSystemItemType.File;
|
||||
FileSystemItemFixture invalidItem = new(id, name, type);
|
||||
|
||||
// Act & Assert
|
||||
invalidItem.Invoking(item => item.ToTreeNodeResponse())
|
||||
.Should().Throw<ArgumentException>()
|
||||
.WithMessage("Invalid FileSystemItem");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponses_WhenMappingMultipleFileSystemItems_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<FileSystemItem> domainModels = _directoryFixture.CreateMany();
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
List<FileSystemItem> domainModelsList = domainModels.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModelsList[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(domainModelsList[i].Type);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
resultList[i].Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemItem"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemItemFixture : FileSystemItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemItemFixture"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for the file system path.</param>
|
||||
/// <param name="name">The name of the file system item.</param>
|
||||
/// <param name="fileSystemItemType">The type of the file system item.</param>
|
||||
public FileSystemItemFixture(FileSystemPathId id, string name, FileSystemItemType fileSystemItemType)
|
||||
: base(id, name, fileSystemItemType)
|
||||
{
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UnixRootItemMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UnixRootItemMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingUnixRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
|
||||
createResult.IsError.Should().BeFalse();
|
||||
UnixRootItem domainModel = createResult.Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="WindowsRootItemMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WindowsRootItemMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingWindowsRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
string path = "C:\\";
|
||||
string name = "C:";
|
||||
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name);
|
||||
createResult.IsError.Should().BeFalse();
|
||||
WindowsRootItem domainModel = createResult.Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingWindowsRootItemWithCustomStatus_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
string path = "D:\\";
|
||||
string name = "D:";
|
||||
FileSystemItemStatus customStatus = FileSystemItemStatus.Inaccessible;
|
||||
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name, customStatus);
|
||||
createResult.IsError.Should().BeFalse();
|
||||
WindowsRootItem domainModel = createResult.Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileMappingTests
|
||||
{
|
||||
private readonly FileFixture _fileFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileMappingTests"/> class.
|
||||
/// </summary>
|
||||
public FileMappingTests()
|
||||
{
|
||||
_fileFixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
File domainModel = _fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToFileSystemTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.ItemType.Should().Be(domainModel.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<File> domainModels = _fileFixture.CreateMany();
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToFileSystemTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
List<File> domainModelsList = domainModels.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModelsList[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(domainModelsList[i].Type);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
resultList[i].Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingFile_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
File domainModel = _fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.DateCreated.Should().Be(domainModel.DateCreated.Value);
|
||||
result.DateModified.Should().Be(domainModel.DateModified.Value);
|
||||
result.Size.Should().Be(domainModel.Size);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<File> domainModels = _fileFixture.CreateMany();
|
||||
|
||||
// Act
|
||||
IEnumerable<FileResponse> result = domainModels.ToResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count());
|
||||
|
||||
List<FileResponse> resultList = result.ToList();
|
||||
List<File> domainModelsList = domainModels.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModelsList[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
|
||||
resultList[i].Size.Should().Be(domainModelsList[i].Size);
|
||||
resultList[i].DateCreated.Should().Be(domainModelsList[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(domainModelsList[i].DateModified.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFilesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFilesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFilesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetFilesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetFilesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
|
||||
// Act
|
||||
GetFilesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeFilesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeFilesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeFilesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeFilesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetTreeFilesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
|
||||
// Act
|
||||
GetTreeFilesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CheckPathExistsRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckPathExistsRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckPathExistsRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public CheckPathExistsRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingCheckPathExistsRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsRequest request = _fixture.Create<CheckPathExistsRequest>();
|
||||
|
||||
// Act
|
||||
CheckPathExistsQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/home/user/documents", true)]
|
||||
[InlineData("C:\\Users\\Documents", false)]
|
||||
[InlineData("/var/www/html", true)]
|
||||
public void ToQuery_WhenMappingWithDifferentPathsAndHiddenElementsFlag_ShouldMapCorrectly(string path, bool includeHiddenElements)
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsRequest request = new(path, includeHiddenElements);
|
||||
|
||||
// Act
|
||||
CheckPathExistsQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path);
|
||||
result.IncludeHiddenElements.Should().Be(includeHiddenElements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<CheckPathExistsRequest> requests = _fixture.CreateMany<CheckPathExistsRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<CheckPathExistsQuery> results = requests.Select(r => r.ToQuery()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(requests.Count);
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
{
|
||||
results[i].Path.Should().Be(requests[i].Path);
|
||||
results[i].IncludeHiddenElements.Should().Be(requests[i].IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CombinePathRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CombinePathRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CombinePathRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public CombinePathRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCombinePathRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
CombinePathRequest request = _fixture.Create<CombinePathRequest>();
|
||||
|
||||
// Act
|
||||
CombinePathCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.OriginalPath.Should().Be(request.OriginalPath);
|
||||
result.NewPath.Should().Be(request.NewPath);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/home/user", "documents")]
|
||||
[InlineData("C:\\Users", "Documents")]
|
||||
[InlineData("/var/www", "html")]
|
||||
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string originalPath, string newPath)
|
||||
{
|
||||
// Arrange
|
||||
CombinePathRequest request = new(originalPath, newPath);
|
||||
|
||||
// Act
|
||||
CombinePathCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.OriginalPath.Should().Be(originalPath);
|
||||
result.NewPath.Should().Be(newPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<CombinePathRequest> requests = _fixture.CreateMany<CombinePathRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<CombinePathCommand> results = requests.Select(r => r.ToCommand()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(requests.Count);
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
{
|
||||
results[i].OriginalPath.Should().Be(requests[i].OriginalPath);
|
||||
results[i].NewPath.Should().Be(requests[i].NewPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathParentRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathParentRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPathParentRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetPathParentRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetPathParentRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentRequest request = _fixture.Create<GetPathParentRequest>();
|
||||
|
||||
// Act
|
||||
GetPathParentQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/home/user/documents")]
|
||||
[InlineData("C:\\Users\\Documents")]
|
||||
[InlineData("/var/www/html")]
|
||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentRequest request = new(path);
|
||||
|
||||
// Act
|
||||
GetPathParentQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GetPathParentRequest> requests = _fixture.CreateMany<GetPathParentRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<GetPathParentQuery> results = requests.Select(r => r.ToQuery()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(requests.Count);
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
{
|
||||
results[i].Path.Should().Be(requests[i].Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetPathRootRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathRootRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPathRootRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetPathRootRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetPathRootRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootRequest request = _fixture.Create<GetPathRootRequest>();
|
||||
|
||||
// Act
|
||||
GetPathRootQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/home/user/documents")]
|
||||
[InlineData("C:\\Users\\Documents")]
|
||||
[InlineData("/var/www/html")]
|
||||
[InlineData("D:\\Projects\\MyProject")]
|
||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootRequest request = new(path);
|
||||
|
||||
// Act
|
||||
GetPathRootQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GetPathRootRequest> requests = _fixture.CreateMany<GetPathRootRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<GetPathRootQuery> results = requests.Select(r => r.ToQuery()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(requests.Count);
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
{
|
||||
results[i].Path.Should().Be(requests[i].Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-26
@@ -1,34 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Mapster;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PathSegmentMappingConfig"/> class.
|
||||
/// Contains unit tests for the <see cref="PathSegmentMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathSegmentMappingConfigTests
|
||||
public class PathSegmentMappingTests
|
||||
{
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly PathSegmentMappingConfig _pathSegmentMappingConfig;
|
||||
|
||||
public PathSegmentMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_pathSegmentMappingConfig = new PathSegmentMappingConfig();
|
||||
_pathSegmentMappingConfig.Register(_config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingPathSegmentToPathSegmentResponse_ShouldMapCorrectly()
|
||||
public void ToResponse_WhenMappingPathSegment_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
|
||||
@@ -36,7 +26,7 @@ public class PathSegmentMappingConfigTests
|
||||
PathSegment pathSegment = createResult.Value;
|
||||
|
||||
// Act
|
||||
PathSegmentResponse result = pathSegment.Adapt<PathSegmentResponse>(_config);
|
||||
PathSegmentResponse result = pathSegment.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
@@ -47,7 +37,7 @@ public class PathSegmentMappingConfigTests
|
||||
[InlineData("Folder", true, false)]
|
||||
[InlineData("File.txt", false, false)]
|
||||
[InlineData("C:", false, true)]
|
||||
public void Register_WhenMappingDifferentPathSegmentTypes_ShouldMapCorrectly(string name, bool isDirectory, bool isDrive)
|
||||
public void ToResponse_WhenMappingDifferentPathSegmentTypes_ShouldMapCorrectly(string name, bool isDirectory, bool isDrive)
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<PathSegment> createResult = PathSegment.Create(name, isDirectory, isDrive);
|
||||
@@ -55,7 +45,7 @@ public class PathSegmentMappingConfigTests
|
||||
PathSegment pathSegment = createResult.Value;
|
||||
|
||||
// Act
|
||||
PathSegmentResponse result = pathSegment.Adapt<PathSegmentResponse>(_config);
|
||||
PathSegmentResponse result = pathSegment.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
@@ -63,7 +53,7 @@ public class PathSegmentMappingConfigTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingMultiplePathSegments_ShouldMapAllCorrectly()
|
||||
public void ToResponses_WhenMappingMultiplePathSegments_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<PathSegment> pathSegments =
|
||||
@@ -75,14 +65,13 @@ public class PathSegmentMappingConfigTests
|
||||
];
|
||||
|
||||
// Act
|
||||
List<PathSegmentResponse> results = pathSegments.Adapt<List<PathSegmentResponse>>(_config);
|
||||
IEnumerable<PathSegmentResponse> results = pathSegments.ToResponses();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(pathSegments.Count);
|
||||
List<PathSegmentResponse> resultList = results.ToList();
|
||||
for (int i = 0; i < pathSegments.Count; i++)
|
||||
{
|
||||
results[i].Path.Should().Be(pathSegments[i].Name);
|
||||
}
|
||||
resultList[i].Path.Should().Be(pathSegments[i].Name);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SplitPathRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SplitPathRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SplitPathRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public SplitPathRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingSplitPathRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
SplitPathRequest request = _fixture.Create<SplitPathRequest>();
|
||||
|
||||
// Act
|
||||
SplitPathCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/home/user/documents")]
|
||||
[InlineData("C:\\Users\\Documents")]
|
||||
[InlineData("/var/www/html")]
|
||||
[InlineData("D:\\Projects\\MyProject\\file.txt")]
|
||||
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
SplitPathRequest request = new(path);
|
||||
|
||||
// Act
|
||||
SplitPathCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<SplitPathRequest> requests = _fixture.CreateMany<SplitPathRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<SplitPathCommand> results = requests.Select(r => r.ToCommand()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(requests.Count);
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
results[i].Path.Should().Be(requests[i].Path);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ValidatePathRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatePathRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ValidatePathRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public ValidatePathRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidatePathRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathRequest request = _fixture.Create<ValidatePathRequest>();
|
||||
|
||||
// Act
|
||||
ValidatePathQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("/home/user/documents")]
|
||||
[InlineData("C:\\Users\\Documents")]
|
||||
[InlineData("/var/www/html")]
|
||||
[InlineData("D:\\Projects\\MyProject\\file.txt")]
|
||||
[InlineData("\\\\NetworkShare\\Folder")]
|
||||
[InlineData("relative/path/to/file.txt")]
|
||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathRequest request = new(path);
|
||||
|
||||
// Act
|
||||
ValidatePathQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<ValidatePathRequest> requests = _fixture.CreateMany<ValidatePathRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<ValidatePathQuery> results = requests.Select(r => r.ToQuery()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(requests.Count);
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
results[i].Path.Should().Be(requests[i].Path);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetThumbnailRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThumbnailRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetThumbnailRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetThumbnailRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailRequest request = _fixture.Create<GetThumbnailRequest>();
|
||||
|
||||
// Act
|
||||
GetThumbnailQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.Quality.Should().Be(request.Quality);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("C:\\test\\image.jpg", 50)]
|
||||
[InlineData("/home/user/image.png", 100)]
|
||||
[InlineData("D:\\photos\\vacation\\pic.gif", 75)]
|
||||
public void ToQuery_WhenMappingWithDifferentPathsAndQualities_ShouldMapCorrectly(string path, int quality)
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailRequest request = new(path, quality);
|
||||
|
||||
// Act
|
||||
GetThumbnailQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path);
|
||||
result.Quality.Should().Be(quality);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GetThumbnailRequest> requests = _fixture.CreateMany<GetThumbnailRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<GetThumbnailQuery> results = requests.Select(r => r.ToQuery()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(requests.Count);
|
||||
for (int i = 0; i < requests.Count; i++)
|
||||
{
|
||||
results[i].Path.Should().Be(requests[i].Path);
|
||||
results[i].Quality.Should().Be(requests[i].Quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Domain.Common.Enums.PhotoLibrary;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ThumbnailMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThumbnailMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThumbnailMappingTests"/> class.
|
||||
/// </summary>
|
||||
public ThumbnailMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingThumbnail_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Thumbnail domainModel = _fixture.Create<Thumbnail>();
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(domainModel.Type);
|
||||
result.Bytes.Should().BeEquivalentTo(domainModel.Bytes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ImageType.JPEG)]
|
||||
[InlineData(ImageType.PNG)]
|
||||
[InlineData(ImageType.GIF)]
|
||||
public void ToResponse_WhenMappingDifferentImageTypes_ShouldMapCorrectly(ImageType imageType)
|
||||
{
|
||||
// Arrange
|
||||
byte[] bytes = _fixture.CreateMany<byte>(100).ToArray();
|
||||
Thumbnail domainModel = new(imageType, bytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEquivalentTo(bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingThumbnailWithEmptyBytes_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ImageType imageType = _fixture.Create<ImageType>();
|
||||
byte[] emptyBytes = [];
|
||||
Thumbnail domainModel = new(imageType, emptyBytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingMultipleThumbnails_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Thumbnail> thumbnails = _fixture.CreateMany<Thumbnail>(3).ToList();
|
||||
|
||||
// Act
|
||||
List<ThumbnailResponse> results = thumbnails.Select(t => t.ToResponse()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(thumbnails.Count);
|
||||
for (int i = 0; i < thumbnails.Count; i++)
|
||||
{
|
||||
results[i].Type.Should().Be(thumbnails[i].Type);
|
||||
results[i].Bytes.Should().BeEquivalentTo(thumbnails[i].Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AddMediaLibraryRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddMediaLibraryRequestMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddLibraryRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
"My Library",
|
||||
LibraryType.Book,
|
||||
["C:/Books", "D:/Media/Books"]
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(request.UserId);
|
||||
result.Title.Should().Be(request.Title);
|
||||
result.LibraryType.Should().Be(request.LibraryType);
|
||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryType.Book)]
|
||||
[InlineData(LibraryType.Movie)]
|
||||
[InlineData(LibraryType.TvShow)]
|
||||
[InlineData(LibraryType.Music)]
|
||||
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
|
||||
{
|
||||
// Arrange
|
||||
AddLibraryRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
"My Library",
|
||||
libraryType,
|
||||
["C:/Media"]
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(request.UserId);
|
||||
result.Title.Should().Be(request.Title);
|
||||
result.LibraryType.Should().Be(libraryType);
|
||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
string[] contentLocations =
|
||||
[
|
||||
"C:/Media/Books",
|
||||
"D:/Books",
|
||||
"E:/Digital Library/Books",
|
||||
"F:/Reading Material"
|
||||
];
|
||||
|
||||
AddLibraryRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
"My Library",
|
||||
LibraryType.Book,
|
||||
contentLocations
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Should().BeEquivalentTo(contentLocations);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryEntityMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidLibraryEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LibraryEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "My Library",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations =
|
||||
[
|
||||
new() { Path = "C:/Books" },
|
||||
new() { Path = "D:/Media/Books" }
|
||||
],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
LibraryResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(entity.Id);
|
||||
result.UserId.Should().Be(entity.UserId);
|
||||
result.Title.Should().Be(entity.Title);
|
||||
result.LibraryType.Should().Be(entity.LibraryType);
|
||||
result.ContentLocations.Should().BeEquivalentTo(entity.ContentLocations.Select(l => l.Path));
|
||||
result.Created.Should().Be(entity.Created);
|
||||
result.Updated.Should().Be(entity.Updated);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryType.Book)]
|
||||
[InlineData(LibraryType.Movie)]
|
||||
[InlineData(LibraryType.TvShow)]
|
||||
[InlineData(LibraryType.Music)]
|
||||
public void ToResponse_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
|
||||
{
|
||||
// Arrange
|
||||
LibraryEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "My Library",
|
||||
LibraryType = libraryType,
|
||||
ContentLocations = [new() { Path = "C:/Media" }],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
LibraryResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.LibraryType.Should().Be(libraryType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LibraryEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "My Library",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations =
|
||||
[
|
||||
new() { Path = "C:/Media/Books" },
|
||||
new() { Path = "D:/Books" },
|
||||
new() { Path = "E:/Digital Library/Books" },
|
||||
new() { Path = "F:/Reading Material" }
|
||||
],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
LibraryResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Should().BeEquivalentTo(entity.ContentLocations.Select(l => l.Path));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingWithUpdatedDateTime_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DateTime updated = DateTime.UtcNow.AddDays(-1);
|
||||
LibraryEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "My Library",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations = [new() { Path = "C:/Books" }],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = updated
|
||||
};
|
||||
|
||||
// Act
|
||||
LibraryResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Updated.Should().Be(updated);
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingValidLibrary_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
["C:/Books", "D:/Media/Books"]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
// Act
|
||||
LibraryEntity result = library.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(library.Id.Value);
|
||||
result.UserId.Should().Be(library.UserId.Value);
|
||||
result.Title.Should().Be(library.Title);
|
||||
result.LibraryType.Should().Be(library.LibraryType);
|
||||
result.ContentLocations.Select(l => l.Path)
|
||||
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
|
||||
result.Created.Should().Be(library.Created);
|
||||
result.Updated.Should().Be(library.Updated.HasValue ? library.Updated : null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingLibraryWithEmptyContentLocations_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
"Empty Library",
|
||||
LibraryType.Book,
|
||||
[]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
// Act
|
||||
LibraryEntity result = library.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryType.Book)]
|
||||
[InlineData(LibraryType.Movie)]
|
||||
[InlineData(LibraryType.TvShow)]
|
||||
[InlineData(LibraryType.Music)]
|
||||
public void ToRepositoryEntity_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
"Test Library",
|
||||
libraryType,
|
||||
["C:/Media"]
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
// Act
|
||||
LibraryEntity result = library.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.LibraryType.Should().Be(libraryType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<string> contentLocations =
|
||||
[
|
||||
"C:/Media/Books",
|
||||
"D:/Books",
|
||||
"E:/Digital Library/Books",
|
||||
"F:/Reading Material"
|
||||
];
|
||||
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
contentLocations
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
// Act
|
||||
LibraryEntity result = library.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Select(l => l.Path)
|
||||
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AddBookRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookRequestMappingTests
|
||||
{
|
||||
private readonly AddBookRequestFixture _requestFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddBookRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public AddBookRequestMappingTests()
|
||||
{
|
||||
_requestFixture = new AddBookRequestFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = _requestFixture.CreateRequestBook();
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Metadata.Should().BeEquivalentTo(request.Metadata);
|
||||
result.Format.Should().Be(request.Format);
|
||||
result.Edition.Should().Be(request.Edition);
|
||||
result.VolumeNumber.Should().Be(request.VolumeNumber);
|
||||
result.Series.Should().BeEquivalentTo(request.Series);
|
||||
result.ASIN.Should().Be(request.ASIN);
|
||||
result.GoodreadsId.Should().Be(request.GoodreadsId);
|
||||
result.LCCN.Should().Be(request.LCCN);
|
||||
result.OCLCNumber.Should().Be(request.OCLCNumber);
|
||||
result.OpenLibraryId.Should().Be(request.OpenLibraryId);
|
||||
result.LibraryThingId.Should().Be(request.LibraryThingId);
|
||||
result.GoogleBooksId.Should().Be(request.GoogleBooksId);
|
||||
result.BarnesAndNobleId.Should().Be(request.BarnesAndNobleId);
|
||||
result.AppleBooksId.Should().Be(request.AppleBooksId);
|
||||
result.ISBNs.Should().BeEquivalentTo(request.ISBNs);
|
||||
result.Contributors.Should().BeEquivalentTo(request.Contributors);
|
||||
result.Ratings.Should().BeEquivalentTo(request.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingMinimalRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = new(
|
||||
Metadata: new WrittenContentMetadataDto(
|
||||
Title: "Test Book",
|
||||
OriginalTitle: null,
|
||||
Description: null,
|
||||
ReleaseInfo: null,
|
||||
Genres: null,
|
||||
Tags: null,
|
||||
Language: null,
|
||||
OriginalLanguage: null,
|
||||
Publisher: null,
|
||||
PageCount: null),
|
||||
Format: null,
|
||||
Edition: null,
|
||||
VolumeNumber: null,
|
||||
Series: null,
|
||||
ASIN: null,
|
||||
GoodreadsId: null,
|
||||
LCCN: null,
|
||||
OCLCNumber: null,
|
||||
OpenLibraryId: null,
|
||||
LibraryThingId: null,
|
||||
GoogleBooksId: null,
|
||||
BarnesAndNobleId: null,
|
||||
AppleBooksId: null,
|
||||
ISBNs: null,
|
||||
Contributors: null,
|
||||
Ratings: null);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Metadata.Should().BeEquivalentTo(request.Metadata);
|
||||
result.Format.Should().BeNull();
|
||||
result.Edition.Should().BeNull();
|
||||
result.VolumeNumber.Should().BeNull();
|
||||
result.Series.Should().BeNull();
|
||||
result.ASIN.Should().BeNull();
|
||||
result.GoodreadsId.Should().BeNull();
|
||||
result.LCCN.Should().BeNull();
|
||||
result.OCLCNumber.Should().BeNull();
|
||||
result.OpenLibraryId.Should().BeNull();
|
||||
result.LibraryThingId.Should().BeNull();
|
||||
result.GoogleBooksId.Should().BeNull();
|
||||
result.BarnesAndNobleId.Should().BeNull();
|
||||
result.AppleBooksId.Should().BeNull();
|
||||
result.ISBNs.Should().BeNull();
|
||||
result.Contributors.Should().BeNull();
|
||||
result.Ratings.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequestWithCollections_ShouldMapCollectionsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = new(
|
||||
Metadata: new WrittenContentMetadataDto(
|
||||
Title: "Test Book",
|
||||
OriginalTitle: null,
|
||||
Description: null,
|
||||
ReleaseInfo: null,
|
||||
Genres: null,
|
||||
Tags: null,
|
||||
Language: null,
|
||||
OriginalLanguage: null,
|
||||
Publisher: null,
|
||||
PageCount: null),
|
||||
Format: null,
|
||||
Edition: null,
|
||||
VolumeNumber: null,
|
||||
Series: null,
|
||||
ASIN: null,
|
||||
GoodreadsId: null,
|
||||
LCCN: null,
|
||||
OCLCNumber: null,
|
||||
OpenLibraryId: null,
|
||||
LibraryThingId: null,
|
||||
GoogleBooksId: null,
|
||||
BarnesAndNobleId: null,
|
||||
AppleBooksId: null,
|
||||
ISBNs: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
|
||||
Contributors:
|
||||
[
|
||||
new(
|
||||
new MediaContributorNameDto("John Doe", "John Smith Doe"),
|
||||
new MediaContributorRoleDto("Author", "Writing")
|
||||
)
|
||||
],
|
||||
Ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)]);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ISBNs.Should().BeEquivalentTo(request.ISBNs);
|
||||
result.Contributors.Should().BeEquivalentTo(request.Contributors);
|
||||
result.Ratings.Should().BeEquivalentTo(request.Ratings);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookMappingTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookMappingTests()
|
||||
{
|
||||
_bookFixture = new BookFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingCompleteBook_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.CreateDomainBook();
|
||||
|
||||
// Act
|
||||
BookEntity result = book.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(book.Id.Value);
|
||||
result.Title.Should().Be(book.Metadata.Title);
|
||||
result.OriginalTitle.Should().Be(book.Metadata.OriginalTitle.HasValue ? book.Metadata.OriginalTitle.Value : null);
|
||||
result.Description.Should().Be(book.Metadata.Description.HasValue ? book.Metadata.Description.Value : null);
|
||||
result.OriginalReleaseDate.Should().Be(book.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null);
|
||||
result.OriginalReleaseYear.Should().Be(book.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null);
|
||||
result.ReReleaseDate.Should().Be(book.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? book.Metadata.ReleaseInfo.ReReleaseDate.Value : null);
|
||||
result.ReReleaseYear.Should().Be(book.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? book.Metadata.ReleaseInfo.ReReleaseYear.Value : null);
|
||||
result.ReleaseCountry.Should().Be(book.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? book.Metadata.ReleaseInfo.ReleaseCountry.Value : null);
|
||||
result.ReleaseVersion.Should().Be(book.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? book.Metadata.ReleaseInfo.ReleaseVersion.Value : null);
|
||||
result.LanguageCode.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageCode : null);
|
||||
result.LanguageName.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageName : null);
|
||||
result.LanguageNativeName.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.NativeName.Value : null);
|
||||
result.OriginalLanguageCode.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageCode : null);
|
||||
result.OriginalLanguageName.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageName : null);
|
||||
result.OriginalLanguageNativeName.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.NativeName.Value : null);
|
||||
result.Tags.Should().BeEquivalentTo(book.Metadata.Tags.ToRepositoryEntities());
|
||||
result.Genres.Should().BeEquivalentTo(book.Metadata.Genres.ToRepositoryEntities());
|
||||
result.Publisher.Should().Be(book.Metadata.Publisher.HasValue ? book.Metadata.Publisher.Value : null);
|
||||
result.PageCount.Should().Be(book.Metadata.PageCount.HasValue ? book.Metadata.PageCount.Value : null);
|
||||
result.Format.Should().Be(book.Format.HasValue ? book.Format.Value : null);
|
||||
result.Edition.Should().Be(book.Edition.HasValue ? book.Edition.Value : null);
|
||||
result.VolumeNumber.Should().Be(book.VolumeNumber.HasValue ? book.VolumeNumber.Value : null);
|
||||
result.ASIN.Should().Be(book.ASIN.HasValue ? book.ASIN.Value : null);
|
||||
result.GoodreadsId.Should().Be(book.GoodreadsId.HasValue ? book.GoodreadsId.Value : null);
|
||||
result.LCCN.Should().Be(book.LCCN.HasValue ? book.LCCN.Value : null);
|
||||
result.OCLCNumber.Should().Be(book.OCLCNumber.HasValue ? book.OCLCNumber.Value : null);
|
||||
result.OpenLibraryId.Should().Be(book.OpenLibraryId.HasValue ? book.OpenLibraryId.Value : null);
|
||||
result.LibraryThingId.Should().Be(book.LibraryThingId.HasValue ? book.LibraryThingId.Value : null);
|
||||
result.GoogleBooksId.Should().Be(book.GoogleBooksId.HasValue ? book.GoogleBooksId.Value : null);
|
||||
result.BarnesAndNobleId.Should().Be(book.BarnesAndNobleId.HasValue ? book.BarnesAndNobleId.Value : null);
|
||||
result.AppleBooksId.Should().Be(book.AppleBooksId.HasValue ? book.AppleBooksId.Value : null);
|
||||
result.ISBNs.Should().BeEquivalentTo(book.ISBNs.ToRepositoryEntities());
|
||||
result.Ratings.Should().BeEquivalentTo(book.Ratings.ToRepositoryEntities());
|
||||
result.Created.Should().Be(book.Created);
|
||||
result.Updated.Should().Be(book.Updated.HasValue ? book.Updated.Value : null);
|
||||
}
|
||||
}
|
||||
+347
@@ -0,0 +1,347 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookEntityMappingTests
|
||||
{
|
||||
private readonly BookEntityFixture _bookEntityFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookEntityMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookEntityMappingTests()
|
||||
{
|
||||
_bookEntityFixture = new BookEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidBookEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.CreateBook();
|
||||
|
||||
// Act
|
||||
ErrorOr<Book> result = bookEntity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Id.Value.Should().Be(bookEntity.Id);
|
||||
result.Value.Metadata.Title.Should().Be(bookEntity.Title);
|
||||
|
||||
if (bookEntity.OriginalTitle is not null)
|
||||
{
|
||||
result.Value.Metadata.OriginalTitle.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.OriginalTitle.Value.Should().Be(bookEntity.OriginalTitle);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.OriginalTitle.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.Description is not null)
|
||||
{
|
||||
result.Value.Metadata.Description.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Description.Value.Should().Be(bookEntity.Description);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Description.HasValue.Should().BeFalse();
|
||||
if (bookEntity.OriginalReleaseDate.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.Value.Should().Be(bookEntity.OriginalReleaseDate.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OriginalReleaseYear.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.Value.Should().Be(bookEntity.OriginalReleaseYear.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReReleaseDate.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseDate.Value.Should().Be(bookEntity.ReReleaseDate.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReReleaseYear.HasValue)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseYear.Value.Should().Be(bookEntity.ReReleaseYear.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReleaseCountry is not null)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseCountry.Value.Should().Be(bookEntity.ReleaseCountry);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ReleaseVersion is not null)
|
||||
{
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseVersion.Value.Should().Be(bookEntity.ReleaseVersion);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.LanguageCode is not null)
|
||||
{
|
||||
result.Value.Metadata.Language.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Language.Value.LanguageCode.Should().Be(bookEntity.LanguageCode);
|
||||
result.Value.Metadata.Language.Value.LanguageName.Should().Be(bookEntity.LanguageName);
|
||||
|
||||
if (bookEntity.LanguageNativeName is not null)
|
||||
{
|
||||
result.Value.Metadata.Language.Value.NativeName.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Language.Value.NativeName.Value.Should().Be(bookEntity.LanguageNativeName);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Language.Value.NativeName.HasValue.Should().BeFalse();
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Language.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OriginalLanguageCode is not null)
|
||||
{
|
||||
result.Value.Metadata.OriginalLanguage.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.OriginalLanguage.Value.LanguageCode.Should().Be(bookEntity.OriginalLanguageCode);
|
||||
result.Value.Metadata.OriginalLanguage.Value.LanguageName.Should().Be(bookEntity.OriginalLanguageName);
|
||||
|
||||
if (bookEntity.OriginalLanguageNativeName is not null)
|
||||
{
|
||||
result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.OriginalLanguage.Value.NativeName.Value.Should().Be(bookEntity.OriginalLanguageNativeName);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue.Should().BeFalse();
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.OriginalLanguage.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.Publisher is not null)
|
||||
{
|
||||
result.Value.Metadata.Publisher.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.Publisher.Value.Should().Be(bookEntity.Publisher);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.Publisher.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.PageCount.HasValue)
|
||||
{
|
||||
result.Value.Metadata.PageCount.HasValue.Should().BeTrue();
|
||||
result.Value.Metadata.PageCount.Value.Should().Be(bookEntity.PageCount.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Metadata.PageCount.HasValue.Should().BeFalse();
|
||||
|
||||
result.Value.Format.Value.Should().Be(bookEntity.Format);
|
||||
|
||||
if (bookEntity.Edition is not null)
|
||||
{
|
||||
result.Value.Edition.HasValue.Should().BeTrue();
|
||||
result.Value.Edition.Value.Should().Be(bookEntity.Edition);
|
||||
}
|
||||
else
|
||||
result.Value.Edition.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.VolumeNumber.HasValue)
|
||||
{
|
||||
result.Value.VolumeNumber.HasValue.Should().BeTrue();
|
||||
result.Value.VolumeNumber.Value.Should().Be(bookEntity.VolumeNumber.Value);
|
||||
}
|
||||
else
|
||||
result.Value.VolumeNumber.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.ASIN is not null)
|
||||
{
|
||||
result.Value.ASIN.HasValue.Should().BeTrue();
|
||||
result.Value.ASIN.Value.Should().Be(bookEntity.ASIN);
|
||||
}
|
||||
else
|
||||
result.Value.ASIN.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.GoodreadsId is not null)
|
||||
{
|
||||
result.Value.GoodreadsId.HasValue.Should().BeTrue();
|
||||
result.Value.GoodreadsId.Value.Should().Be(bookEntity.GoodreadsId);
|
||||
}
|
||||
else
|
||||
result.Value.GoodreadsId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.LCCN is not null)
|
||||
{
|
||||
result.Value.LCCN.HasValue.Should().BeTrue();
|
||||
result.Value.LCCN.Value.Should().Be(bookEntity.LCCN);
|
||||
}
|
||||
else
|
||||
result.Value.LCCN.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OCLCNumber is not null)
|
||||
{
|
||||
result.Value.OCLCNumber.HasValue.Should().BeTrue();
|
||||
result.Value.OCLCNumber.Value.Should().Be(bookEntity.OCLCNumber);
|
||||
}
|
||||
else
|
||||
result.Value.OCLCNumber.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.OpenLibraryId is not null)
|
||||
{
|
||||
result.Value.OpenLibraryId.HasValue.Should().BeTrue();
|
||||
result.Value.OpenLibraryId.Value.Should().Be(bookEntity.OpenLibraryId);
|
||||
}
|
||||
else
|
||||
result.Value.OpenLibraryId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.LibraryThingId is not null)
|
||||
{
|
||||
result.Value.LibraryThingId.HasValue.Should().BeTrue();
|
||||
result.Value.LibraryThingId.Value.Should().Be(bookEntity.LibraryThingId);
|
||||
}
|
||||
else
|
||||
result.Value.LibraryThingId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.GoogleBooksId is not null)
|
||||
{
|
||||
result.Value.GoogleBooksId.HasValue.Should().BeTrue();
|
||||
result.Value.GoogleBooksId.Value.Should().Be(bookEntity.GoogleBooksId);
|
||||
}
|
||||
else
|
||||
result.Value.GoogleBooksId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.BarnesAndNobleId is not null)
|
||||
{
|
||||
result.Value.BarnesAndNobleId.HasValue.Should().BeTrue();
|
||||
result.Value.BarnesAndNobleId.Value.Should().Be(bookEntity.BarnesAndNobleId);
|
||||
}
|
||||
else
|
||||
result.Value.BarnesAndNobleId.HasValue.Should().BeFalse();
|
||||
|
||||
if (bookEntity.AppleBooksId is not null)
|
||||
{
|
||||
result.Value.AppleBooksId.HasValue.Should().BeTrue();
|
||||
result.Value.AppleBooksId.Value.Should().Be(bookEntity.AppleBooksId);
|
||||
}
|
||||
else
|
||||
result.Value.AppleBooksId.HasValue.Should().BeFalse();
|
||||
|
||||
result.Value.Created.Should().Be(bookEntity.Created);
|
||||
|
||||
if (bookEntity.Updated.HasValue)
|
||||
{
|
||||
result.Value.Updated.HasValue.Should().BeTrue();
|
||||
result.Value.Updated!.Value.Should().Be(bookEntity.Updated.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Updated.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingBookEntity_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookEntity = _bookEntityFixture.CreateBook();
|
||||
|
||||
// Act
|
||||
BookResponse result = bookEntity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(bookEntity.Id);
|
||||
result.Metadata.Title.Should().Be(bookEntity.Title);
|
||||
result.Metadata.OriginalTitle.Should().Be(bookEntity.OriginalTitle);
|
||||
result.Metadata.Description.Should().Be(bookEntity.Description);
|
||||
result.Metadata.ReleaseInfo!.OriginalReleaseDate.Should().Be(bookEntity.OriginalReleaseDate);
|
||||
result.Metadata.ReleaseInfo.OriginalReleaseYear.Should().Be(bookEntity.OriginalReleaseYear);
|
||||
result.Metadata.ReleaseInfo.ReReleaseDate.Should().Be(bookEntity.ReReleaseDate);
|
||||
result.Metadata.ReleaseInfo.ReReleaseYear.Should().Be(bookEntity.ReReleaseYear);
|
||||
result.Metadata.ReleaseInfo.ReleaseCountry.Should().Be(bookEntity.ReleaseCountry);
|
||||
result.Metadata.ReleaseInfo.ReleaseVersion.Should().Be(bookEntity.ReleaseVersion);
|
||||
result.Metadata.Language.Should().NotBeNull();
|
||||
result.Metadata.Language!.LanguageCode.Should().Be(bookEntity.LanguageCode);
|
||||
result.Metadata.Language.LanguageName.Should().Be(bookEntity.LanguageName);
|
||||
result.Metadata.Language.NativeName.Should().Be(bookEntity.LanguageNativeName);
|
||||
result.Metadata.OriginalLanguage.Should().NotBeNull();
|
||||
result.Metadata.OriginalLanguage!.LanguageCode.Should().Be(bookEntity.OriginalLanguageCode);
|
||||
result.Metadata.OriginalLanguage.LanguageName.Should().Be(bookEntity.OriginalLanguageName);
|
||||
result.Metadata.OriginalLanguage.NativeName.Should().Be(bookEntity.OriginalLanguageNativeName);
|
||||
result.Metadata.Publisher.Should().Be(bookEntity.Publisher);
|
||||
result.Metadata.PageCount.Should().Be(bookEntity.PageCount);
|
||||
result.Format.Should().Be(bookEntity.Format);
|
||||
result.Edition.Should().Be(bookEntity.Edition);
|
||||
result.VolumeNumber.Should().Be(bookEntity.VolumeNumber);
|
||||
result.ASIN.Should().Be(bookEntity.ASIN);
|
||||
result.GoodreadsId.Should().Be(bookEntity.GoodreadsId);
|
||||
result.LCCN.Should().Be(bookEntity.LCCN);
|
||||
result.OCLCNumber.Should().Be(bookEntity.OCLCNumber);
|
||||
result.OpenLibraryId.Should().Be(bookEntity.OpenLibraryId);
|
||||
result.LibraryThingId.Should().Be(bookEntity.LibraryThingId);
|
||||
result.GoogleBooksId.Should().Be(bookEntity.GoogleBooksId);
|
||||
result.BarnesAndNobleId.Should().Be(bookEntity.BarnesAndNobleId);
|
||||
result.AppleBooksId.Should().Be(bookEntity.AppleBooksId);
|
||||
result.ISBNs.Should().BeEquivalentTo(bookEntity.ISBNs);
|
||||
result.Ratings.Should().BeEquivalentTo(bookEntity.Ratings);
|
||||
result.Created.Should().Be(bookEntity.Created);
|
||||
result.Updated.Should().Be(bookEntity.Updated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities =
|
||||
[
|
||||
_bookEntityFixture.CreateBook(),
|
||||
_bookEntityFixture.CreateBook()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Book>> results = bookEntities.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(bookEntities.Count);
|
||||
results.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities =
|
||||
[
|
||||
_bookEntityFixture.CreateBook(),
|
||||
_bookEntityFixture.CreateBook()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<BookResponse> results = bookEntities.ToResponses();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(bookEntities.Count);
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingDtoMappingTests
|
||||
{
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingDtoMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookRatingDtoMappingTests()
|
||||
{
|
||||
_bookRatingDtoFixture = new BookRatingDtoFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingCompleteBookRatinDto_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.CreateComplete();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(dto.Value!.Value);
|
||||
result.Value.MaxValue.Should().Be(dto.MaxValue!.Value);
|
||||
|
||||
if (dto.Source.HasValue)
|
||||
{
|
||||
result.Value.Source.HasValue.Should().BeTrue();
|
||||
result.Value.Source.Value.Should().Be(dto.Source.Value);
|
||||
}
|
||||
else
|
||||
result.Value.Source.HasValue.Should().BeFalse();
|
||||
|
||||
if (dto.VoteCount.HasValue)
|
||||
{
|
||||
result.Value.VoteCount.HasValue.Should().BeTrue();
|
||||
result.Value.VoteCount.Value.Should().Be(dto.VoteCount.Value);
|
||||
}
|
||||
else
|
||||
result.Value.VoteCount.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingMinimalBookRatingDto_ShouldMapRequiredPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.CreateMinimal();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(dto.Value!.Value);
|
||||
result.Value.MaxValue.Should().Be(dto.MaxValue!.Value);
|
||||
result.Value.Source.HasValue.Should().BeFalse();
|
||||
result.Value.VoteCount.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingInvalidBookRatingDto_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingDto dto = _bookRatingDtoFixture.CreateInvalid();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidBookRatingDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingDto> dtos =
|
||||
[
|
||||
_bookRatingDtoFixture.CreateComplete(),
|
||||
_bookRatingDtoFixture.CreateMinimal()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(dtos.Count);
|
||||
|
||||
List<ErrorOr<BookRating>> resultList = results.ToList();
|
||||
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
|
||||
|
||||
// Complete rating
|
||||
resultList[0].Value.Value.Should().Be(dtos[0].Value!.Value);
|
||||
resultList[0].Value.MaxValue.Should().Be(dtos[0].MaxValue!.Value);
|
||||
resultList[0].Value.Source.Value.Should().Be(dtos[0].Source!.Value);
|
||||
resultList[0].Value.VoteCount.Value.Should().Be(dtos[0].VoteCount!.Value);
|
||||
|
||||
// Minimal rating
|
||||
resultList[1].Value.Value.Should().Be(dtos[1].Value!.Value);
|
||||
resultList[1].Value.MaxValue.Should().Be(dtos[1].MaxValue!.Value);
|
||||
resultList[1].Value.Source.HasValue.Should().BeFalse();
|
||||
resultList[1].Value.VoteCount.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidBookRatingDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingDto> dtos =
|
||||
[
|
||||
_bookRatingDtoFixture.CreateComplete(),
|
||||
_bookRatingDtoFixture.CreateInvalid(),
|
||||
_bookRatingDtoFixture.CreateMinimal()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(dtos.Count);
|
||||
|
||||
List<ErrorOr<BookRating>> resultList = results.ToList();
|
||||
|
||||
resultList[0].IsError.Should().BeFalse();
|
||||
resultList[1].IsError.Should().BeTrue();
|
||||
resultList[2].IsError.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingEntityMappingTests
|
||||
{
|
||||
private readonly BookRatingEntityFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingEntityMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookRatingEntityMappingTests()
|
||||
{
|
||||
_fixture = new BookRatingEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _fixture.CreateBookRating();
|
||||
|
||||
// Act
|
||||
BookRatingDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(entity.Value!.Value);
|
||||
result.MaxValue.Should().Be(entity.MaxValue!.Value);
|
||||
result.Source.Should().Be(entity.Source);
|
||||
result.VoteCount.Should().Be(entity.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _fixture.CreateInvalidBookRating();
|
||||
|
||||
// Act
|
||||
BookRatingDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(default);
|
||||
result.MaxValue.Should().Be(default);
|
||||
result.Source.Should().Be(entity.Source);
|
||||
result.VoteCount.Should().Be(entity.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingEntity> entities =
|
||||
[
|
||||
_fixture.CreateBookRating(),
|
||||
_fixture.CreateBookRating()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<BookRatingDto> results = entities.ToResponses();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
results.Should().AllSatisfy(result =>
|
||||
{
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().BeInRange(1, 5);
|
||||
result.MaxValue.Should().Be(5);
|
||||
result.VoteCount.Should().BeInRange(1, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _fixture.CreateBookRating();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(entity.Value);
|
||||
result.Value.MaxValue.Should().Be(entity.MaxValue);
|
||||
result.Value.Source.Value.Should().Be(entity.Source);
|
||||
result.Value.VoteCount.Value.Should().Be(entity.VoteCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
|
||||
{
|
||||
// Arrange
|
||||
BookRatingEntity entity = _fixture.CreateInvalidBookRating();
|
||||
|
||||
// Act
|
||||
ErrorOr<BookRating> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(default);
|
||||
result.Value.MaxValue.Should().Be(default);
|
||||
result.Value.Source.HasValue.Should().BeFalse();
|
||||
result.Value.VoteCount.HasValue.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRatingEntity> entities =
|
||||
[
|
||||
_fixture.CreateBookRating(),
|
||||
_fixture.CreateBookRating()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
results.Should().AllSatisfy(result =>
|
||||
{
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().BeInRange(1, 5);
|
||||
result.Value.MaxValue.Should().Be(5);
|
||||
result.Value.Source.HasValue.Should().BeTrue();
|
||||
result.Value.VoteCount.Value.Should().BeInRange(1, 1000);
|
||||
});
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRatingMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingMappingTests
|
||||
{
|
||||
private readonly BookRatingFixture _bookRatingFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingMappingTests"/> class.
|
||||
/// </summary>
|
||||
public BookRatingMappingTests()
|
||||
{
|
||||
_bookRatingFixture = new BookRatingFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingCompleteBookRating_ShouldMapAllPropertiesCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.CreateBookRating();
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(bookRating.Value);
|
||||
result.MaxValue.Should().Be(bookRating.MaxValue);
|
||||
result.Source.Should().Be(bookRating.Source.Value);
|
||||
result.VoteCount.Should().Be(bookRating.VoteCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingBookRatingWithoutSource_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.CreateBookRatingWithoutSource();
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(bookRating.Value);
|
||||
result.MaxValue.Should().Be(bookRating.MaxValue);
|
||||
result.Source.Should().BeNull();
|
||||
result.VoteCount.Should().Be(bookRating.VoteCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingBookRatingWithoutVoteCount_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
BookRating bookRating = _bookRatingFixture.CreateBookRatingWithoutVoteCount();
|
||||
|
||||
// Act
|
||||
BookRatingEntity result = bookRating.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(bookRating.Value);
|
||||
result.MaxValue.Should().Be(bookRating.MaxValue);
|
||||
result.Source.Should().Be(bookRating.Source.Value);
|
||||
result.VoteCount.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleBookRatings_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<BookRating> bookRatings =
|
||||
[
|
||||
_bookRatingFixture.CreateBookRating(),
|
||||
_bookRatingFixture.CreateBookRatingWithoutSource(),
|
||||
_bookRatingFixture.CreateBookRatingWithoutVoteCount()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<BookRatingEntity> results = bookRatings.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(bookRatings.Count);
|
||||
|
||||
List<BookRatingEntity> resultList = results.ToList();
|
||||
|
||||
// Complete rating
|
||||
resultList[0].Value.Should().Be(bookRatings[0].Value);
|
||||
resultList[0].MaxValue.Should().Be(bookRatings[0].MaxValue);
|
||||
resultList[0].Source.Should().Be(bookRatings[0].Source.Value);
|
||||
resultList[0].VoteCount.Should().Be(bookRatings[0].VoteCount.Value);
|
||||
|
||||
// Rating without source
|
||||
resultList[1].Value.Should().Be(bookRatings[1].Value);
|
||||
resultList[1].MaxValue.Should().Be(bookRatings[1].MaxValue);
|
||||
resultList[1].Source.Should().BeNull();
|
||||
resultList[1].VoteCount.Should().Be(bookRatings[1].VoteCount.Value);
|
||||
|
||||
// Rating without vote count
|
||||
resultList[2].Value.Should().Be(bookRatings[2].Value);
|
||||
resultList[2].MaxValue.Should().Be(bookRatings[2].MaxValue);
|
||||
resultList[2].Source.Should().Be(bookRatings[2].Source.Value);
|
||||
resultList[2].VoteCount.Should().BeNull();
|
||||
}
|
||||
}
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnDtoMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnDtoMappingTests
|
||||
{
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IsbnDtoMappingTests"/> class.
|
||||
/// </summary>
|
||||
public IsbnDtoMappingTests()
|
||||
{
|
||||
_isbnDtoFixture = new IsbnDtoFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidIsbn10Dto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.CreateIsbn10();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(dto.Value);
|
||||
result.Value.Format.Should().Be(dto.Format!.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidIsbn13Dto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.CreateIsbn13();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(dto.Value);
|
||||
result.Value.Format.Should().Be(dto.Format!.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingDtoWithoutFormat_ShouldUseDefaultFormat()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.CreateWithoutFormat();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(dto.Value);
|
||||
result.Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingInvalidIsbnDto_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
IsbnDto dto = _isbnDtoFixture.CreateInvalid();
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = dto.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMultipleValidIsbnDtos_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnDto> dtos =
|
||||
[
|
||||
_isbnDtoFixture.CreateIsbn10(),
|
||||
_isbnDtoFixture.CreateIsbn13(),
|
||||
_isbnDtoFixture.CreateWithoutFormat()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(dtos.Count);
|
||||
|
||||
List<ErrorOr<Isbn>> resultList = results.ToList();
|
||||
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
|
||||
|
||||
resultList[0].Value.Value.Should().Be(dtos[0].Value);
|
||||
resultList[0].Value.Format.Should().Be(dtos[0].Format!.Value);
|
||||
|
||||
resultList[1].Value.Value.Should().Be(dtos[1].Value);
|
||||
resultList[1].Value.Format.Should().Be(dtos[1].Format!.Value);
|
||||
|
||||
resultList[2].Value.Value.Should().Be(dtos[2].Value);
|
||||
resultList[2].Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainModels_WhenMappingMixedValidAndInvalidIsbnDtos_ShouldReturnMixedResults()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnDto> dtos =
|
||||
[
|
||||
_isbnDtoFixture.CreateIsbn10(),
|
||||
_isbnDtoFixture.CreateInvalid(),
|
||||
_isbnDtoFixture.CreateIsbn13()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(dtos.Count);
|
||||
|
||||
List<ErrorOr<Isbn>> resultList = results.ToList();
|
||||
|
||||
resultList[0].IsError.Should().BeFalse();
|
||||
resultList[0].Value.Value.Should().Be(dtos[0].Value);
|
||||
|
||||
resultList[1].IsError.Should().BeTrue();
|
||||
|
||||
resultList[2].IsError.Should().BeFalse();
|
||||
resultList[2].Value.Value.Should().Be(dtos[2].Value);
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnEntityMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new("0-7475-3269-9", IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(entity.Value);
|
||||
result.Format.Should().Be(entity.Format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0-7475-3269-9", IsbnFormat.Isbn10)]
|
||||
[InlineData("978-0-7475-3269-9", IsbnFormat.Isbn13)]
|
||||
public void ToResponse_WhenMappingDifferentValidIsbnEntities_ShouldMapCorrectly(string value, IsbnFormat format)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new(value, format);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(value);
|
||||
result.Format.Should().Be(format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", null)]
|
||||
[InlineData(" ", null)]
|
||||
[InlineData(null, null)]
|
||||
public void ToResponse_WhenMappingInvalidIsbnEntity_ShouldPreserveValues(string? value, IsbnFormat? format)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new(value, format);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Value.Should().Be(value);
|
||||
result.Format.Should().Be(format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new("0-7475-3269-9", IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Value.Should().Be(entity.Value);
|
||||
result.Value.Format.Should().Be(entity.Format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData(null)]
|
||||
public void ToDomainEntity_WhenMappingInvalidIsbnEntity_ShouldReturnError(string? invalidValue)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new(invalidValue, null);
|
||||
|
||||
// Act
|
||||
ErrorOr<Isbn> result = entity.ToDomainEntity();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntities_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
new IsbnEntity("0-7475-3269-9", IsbnFormat.Isbn10),
|
||||
new IsbnEntity("978-0-7475-3269-9", IsbnFormat.Isbn13)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<ErrorOr<Isbn>> resultList = results.ToList();
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
resultList[i].IsError.Should().BeFalse();
|
||||
resultList[i].Value.Value.Should().Be(entities[i].Value);
|
||||
resultList[i].Value.Format.Should().Be(entities[i].Format);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
new IsbnEntity("0-7475-3269-9", IsbnFormat.Isbn10),
|
||||
new IsbnEntity("978-0-7475-3269-9", IsbnFormat.Isbn13)
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnDto> results = entities.ToResponses();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(entities.Count);
|
||||
|
||||
List<IsbnDto> resultList = results.ToList();
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
resultList[i].Value.Should().Be(entities[i].Value);
|
||||
resultList[i].Format.Should().Be(entities[i].Format);
|
||||
}
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="IsbnMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnMappingTests
|
||||
{
|
||||
private readonly IsbnFixture _isbnFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IsbnMappingTests"/> class.
|
||||
/// </summary>
|
||||
public IsbnMappingTests()
|
||||
{
|
||||
_isbnFixture = new IsbnFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingIsbn10_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Isbn isbn = _isbnFixture.CreateIsbn10();
|
||||
|
||||
// Act
|
||||
IsbnEntity result = isbn.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(isbn.Value);
|
||||
result.Format.Should().Be(IsbnFormat.Isbn10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingIsbn13_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Isbn isbn = _isbnFixture.CreateIsbn13();
|
||||
|
||||
// Act
|
||||
IsbnEntity result = isbn.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Value.Should().Be(isbn.Value);
|
||||
result.Format.Should().Be(IsbnFormat.Isbn13);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingMultipleIsbns_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Isbn> isbns =
|
||||
[
|
||||
_isbnFixture.CreateIsbn10(),
|
||||
_isbnFixture.CreateIsbn13(),
|
||||
_isbnFixture.CreateIsbn10()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(isbns.Count);
|
||||
|
||||
List<IsbnEntity> resultList = results.ToList();
|
||||
for (int i = 0; i < isbns.Count; i++)
|
||||
{
|
||||
resultList[i].Value.Should().Be(isbns[i].Value);
|
||||
resultList[i].Format.Should().Be(isbns[i].Format);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntities_WhenMappingEmptyCollection_ShouldReturnEmptyCollection()
|
||||
{
|
||||
// Arrange
|
||||
List<Isbn> isbns = [];
|
||||
|
||||
// Act
|
||||
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UserEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid user entity.
|
||||
/// </summary>
|
||||
/// <param name="libraryCount">Number of libraries to generate. Default is 0.</param>
|
||||
/// <returns>The created user entity.</returns>
|
||||
public static UserEntity CreateUserEntity(int libraryCount = 0)
|
||||
{
|
||||
Guid userId = Guid.NewGuid();
|
||||
List<LibraryEntity> libraries = [.. new Faker<LibraryEntity>()
|
||||
.CustomInstantiator(f => new LibraryEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
Title = f.Commerce.ProductName(),
|
||||
LibraryType = f.PickRandom<LibraryType>(),
|
||||
ContentLocations = [],
|
||||
Created = f.Date.Past(),
|
||||
Updated = null
|
||||
})
|
||||
.Generate(libraryCount)];
|
||||
|
||||
return new Faker<UserEntity>()
|
||||
.CustomInstantiator(f => new UserEntity
|
||||
{
|
||||
Id = userId,
|
||||
Username = default!,
|
||||
Password = default!,
|
||||
Created = default,
|
||||
TotpSecret = default,
|
||||
Libraries = libraries
|
||||
})
|
||||
.RuleFor(x => x.Username, f => f.Internet.UserName())
|
||||
.RuleFor(x => x.Password, f => Uri.EscapeDataString(f.Internet.Password()))
|
||||
.RuleFor(x => x.Created, f => f.Date.Past())
|
||||
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32) : null)
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of user entities.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of entities to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public static List<UserEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count)
|
||||
.Select(_ => CreateUserEntity())
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.UsersManagement.Users;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UserEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserEntityMappingTests
|
||||
{
|
||||
private readonly UserEntityFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserEntityMappingTests"/> class.
|
||||
/// </summary>
|
||||
public UserEntityMappingTests()
|
||||
{
|
||||
_fixture = new UserEntityFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidUserEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity();
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(entity.Id);
|
||||
result.Username.Should().Be(entity.Username);
|
||||
result.Created.Should().Be(entity.Created);
|
||||
result.Updated.Should().Be(entity.Updated);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1")]
|
||||
[InlineData("test.user")]
|
||||
[InlineData("john_doe")]
|
||||
[InlineData("jane.doe@example.com")]
|
||||
public void ToResponse_WhenMappingDifferentUsernames_ShouldMapCorrectly(string username)
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity();
|
||||
entity.Username = username;
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingWithUpdatedDateTime_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity();
|
||||
entity.Updated = DateTime.UtcNow.AddDays(-1);
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Updated.Should().Be(entity.Updated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingWithLibraries_ShouldNotAffectMapping()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity(2);
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(entity.Id);
|
||||
result.Username.Should().Be(entity.Username);
|
||||
result.Created.Should().Be(entity.Created);
|
||||
result.Updated.Should().Be(entity.Updated);
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UserMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingValidUser_ShouldOnlyUpdateUsername()
|
||||
{
|
||||
// Arrange
|
||||
User domainEntity = User.Create(
|
||||
UserId.Create(Guid.NewGuid()),
|
||||
"newusername"
|
||||
).Value;
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
TotpSecret = "totpsecret",
|
||||
VerificationToken = "verificationtoken",
|
||||
VerificationTokenCreated = DateTime.UtcNow,
|
||||
Libraries = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeSameAs(repositoryEntity); // Should modify the same instance
|
||||
result.Username.Should().Be(domainEntity.Username); // Only username should be updated
|
||||
|
||||
// Verify other properties remain unchanged
|
||||
result.Id.Should().Be(repositoryEntity.Id);
|
||||
result.Password.Should().Be(repositoryEntity.Password);
|
||||
result.TotpSecret.Should().Be(repositoryEntity.TotpSecret);
|
||||
result.VerificationToken.Should().Be(repositoryEntity.VerificationToken);
|
||||
result.VerificationTokenCreated.Should().Be(repositoryEntity.VerificationTokenCreated);
|
||||
result.Libraries.Should().BeSameAs(repositoryEntity.Libraries);
|
||||
result.Created.Should().Be(repositoryEntity.Created);
|
||||
result.Updated.Should().Be(repositoryEntity.Updated);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1")]
|
||||
[InlineData("test.user")]
|
||||
[InlineData("john_doe")]
|
||||
[InlineData("jane.doe@example.com")]
|
||||
public void ToRepositoryEntity_WhenMappingDifferentUsernames_ShouldUpdateCorrectly(string newUsername)
|
||||
{
|
||||
// Arrange
|
||||
User domainEntity = User.Create(
|
||||
UserId.Create(Guid.NewGuid()),
|
||||
newUsername
|
||||
).Value;
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
Libraries = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(newUsername);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenRepositoryEntityHasLibraries_ShouldPreserveLibraries()
|
||||
{
|
||||
// Arrange
|
||||
User domainEntity = User.Create(
|
||||
UserId.Create(Guid.NewGuid()),
|
||||
"newusername"
|
||||
).Value;
|
||||
|
||||
List<LibraryEntity> libraries =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 1",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 2",
|
||||
LibraryType = LibraryType.Movie,
|
||||
ContentLocations = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
}
|
||||
];
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
Libraries = libraries,
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Libraries.Should().BeSameAs(libraries);
|
||||
result.Libraries.Should().HaveCount(2);
|
||||
}
|
||||
}
|
||||
-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();
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -1,17 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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.
|
||||
@@ -98,12 +98,18 @@ public class DirectoryFixture
|
||||
private Directory CreateNestedDirectory(int currentDepth, int maxDepth, int maxChildrenPerDirectory)
|
||||
{
|
||||
List<FileSystemItem> childItems = [];
|
||||
|
||||
// ensure we create at least one child if we haven't reached max depth
|
||||
if (currentDepth < maxDepth)
|
||||
{
|
||||
int childCount = _faker.Random.Int(0, maxChildrenPerDirectory);
|
||||
// force at least 1 child, up to maxChildrenPerDirectory
|
||||
int childCount = _faker.Random.Int(1, maxChildrenPerDirectory);
|
||||
for (int i = 0; i < childCount; i++)
|
||||
childItems.Add(CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory));
|
||||
{
|
||||
Directory childDirectory = CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory);
|
||||
ErrorOr<Updated> addResult = childDirectory.SetParent(childDirectory);
|
||||
if (!addResult.IsError)
|
||||
childItems.Add(childDirectory);
|
||||
}
|
||||
}
|
||||
return CreateDirectory(childItems: childItems);
|
||||
}
|
||||
+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.DTO.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="FileSystemItemDto"/> 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="FileSystemItemDto"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="FileSystemItemModel"/>.</returns>
|
||||
public FileSystemItemModel Create()
|
||||
/// <returns>The created <see cref="FileSystemItemDto"/>.</returns>
|
||||
public FileSystemItemDto Create()
|
||||
{
|
||||
return new FileSystemItemModel(
|
||||
return new FileSystemItemDto(
|
||||
_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="FileSystemItemDto"/>.
|
||||
/// </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<FileSystemItemDto> CreateMany(int count = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
|
||||
}
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
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]
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
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.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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>>());
|
||||
}
|
||||
}
|
||||
+10
-8
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileManagementAggregate.Entities.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UnixRootItem"/> class.
|
||||
@@ -15,17 +15,19 @@ namespace Lumina.Domain.UnitTests.Core.Aggregates.FileManagementAggregate.Entiti
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UnixRootItemFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UnixRootItem"/>.
|
||||
/// </summary>
|
||||
/// <param name="status">The status of the UNIX root item.</param>
|
||||
/// <returns>The created <see cref="UnixRootItem"/>.</returns>
|
||||
public UnixRootItem CreateUnixRootItem(FileSystemItemStatus status = FileSystemItemStatus.Accessible)
|
||||
public UnixRootItem Create()
|
||||
{
|
||||
ErrorOr<UnixRootItem> unixRootItemResult = UnixRootItem.Create(status);
|
||||
|
||||
ErrorOr<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
|
||||
_faker.PickRandom<FileSystemItemStatus>()
|
||||
);
|
||||
if (unixRootItemResult.IsError)
|
||||
throw new InvalidOperationException("Failed to create UnixRootItem: " + string.Join(", ", unixRootItemResult.Errors));
|
||||
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.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -2,10 +2,10 @@
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSystem;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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.
|
||||
+3
-3
@@ -1,16 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileManagementAggregate.Entities.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
-39
@@ -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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,8 +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>
|
||||
/// Contains unit tests for the <see cref="GetFilesQueryHandler"/> class.
|
||||
@@ -29,11 +27,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 +38,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 +49,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 +83,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 +116,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 +125,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 +134,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.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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]
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileManagementAggregate.ValueObjects.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemPathId"/> class.
|
||||
+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.BoundedContexts.FileSystemManagementBoundedContext.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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileManagementAggregate.ValueObjects.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.Presentation.Api.UnitTests.Core.Controllers.FileManagement.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.Presentation.Api.UnitTests.Core.Controllers.FileManagement.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.BoundedContexts.FileSystemManagementBoundedContext.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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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.BoundedContexts.FileSystemManagementBoundedContext.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.
|
||||
Loaded 100 of 853 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user