Removes FluentAssertions library from test projects, due to licensing changes

This commit is contained in:
BinaryAlley committed 2025-02-03 00:31:15 +02:00
1 parent c1100e5398
commit d46bfae4fc
235 files changed
+4468 -4725

No files matched your search

@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using FluentValidation;
using FluentValidation.Results;
using Lumina.Application.Common.Behaviors;
@@ -46,8 +45,8 @@ public class ValidationBehaviorTests
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(expectedResponse);
Assert.False(result.IsError);
Assert.Equal(expectedResponse, result.Value);
await _nextDelegate.Received(1).Invoke(request, Arg.Any<CancellationToken>());
}
@@ -65,8 +64,8 @@ public class ValidationBehaviorTests
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(expectedResponse);
Assert.False(result.IsError);
Assert.Equal(expectedResponse, result.Value);
await _mockValidator.Received(1).ValidateAsync(request, Arg.Any<CancellationToken>());
await _nextDelegate.Received(1).Invoke(request, Arg.Any<CancellationToken>());
}
@@ -88,12 +87,12 @@ public class ValidationBehaviorTests
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().HaveCount(2);
result.Errors[0].Type.Should().Be(ErrorType.Validation);
result.Errors[0].Description.Should().Be("Error message 1");
result.Errors[1].Type.Should().Be(ErrorType.Validation);
result.Errors[1].Description.Should().Be("Error message 2");
Assert.True(result.IsError);
Assert.Equal(2, result.Errors.Count);
Assert.Equal(ErrorType.Validation, result.Errors[0].Type);
Assert.Equal("Error message 1", result.Errors[0].Description);
Assert.Equal(ErrorType.Validation, result.Errors[1].Type);
Assert.Equal("Error message 2", result.Errors[1].Description);
await _mockValidator.Received(1).ValidateAsync(request, Arg.Any<CancellationToken>());
await _nextDelegate.DidNotReceive().Invoke(request, Arg.Any<CancellationToken>());
}
@@ -1,5 +1,4 @@
#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;
@@ -35,11 +34,11 @@ public class ChangePasswordRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.CurrentPassword, result.CurrentPassword);
Assert.Equal(request.NewPassword, result.NewPassword);
Assert.Equal(request.NewPasswordConfirm, result.NewPasswordConfirm);
}
[Fact]
@@ -52,11 +51,11 @@ public class ChangePasswordRequestMappingTests
ChangePasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.CurrentPassword.Should().BeNull();
result.NewPassword.Should().BeNull();
result.NewPasswordConfirm.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.CurrentPassword);
Assert.Null(result.NewPassword);
Assert.Null(result.NewPasswordConfirm);
}
[Theory]
@@ -76,10 +75,10 @@ public class ChangePasswordRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(currentPassword, result.CurrentPassword);
Assert.Equal(newPassword, result.NewPassword);
Assert.Equal(newPasswordConfirm, result.NewPasswordConfirm);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -35,10 +34,10 @@ public class LoginRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.Password, result.Password);
Assert.Equal(request.TotpCode, result.TotpCode);
}
[Fact]
@@ -51,10 +50,10 @@ public class LoginRequestMappingTests
LoginUserQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.Password.Should().BeNull();
result.TotpCode.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.Password);
Assert.Null(result.TotpCode);
}
[Theory]
@@ -74,9 +73,9 @@ public class LoginRequestMappingTests
LoginUserQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
result.Password.Should().Be(password);
result.TotpCode.Should().Be(totpCode);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(password, result.Password);
Assert.Equal(totpCode, result.TotpCode);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -35,9 +34,9 @@ public class RecoverPasswordRequestMappingTests
RecoverPasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(request.Username);
result.TotpCode.Should().Be(request.TotpCode);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.TotpCode, result.TotpCode);
}
[Fact]
@@ -50,9 +49,9 @@ public class RecoverPasswordRequestMappingTests
RecoverPasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.TotpCode.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.TotpCode);
}
[Theory]
@@ -71,8 +70,8 @@ public class RecoverPasswordRequestMappingTests
RecoverPasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
result.TotpCode.Should().Be(totpCode);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(totpCode, result.TotpCode);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -36,11 +35,11 @@ public class RegistrationRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.Password, result.Password);
Assert.Equal(request.PasswordConfirm, result.PasswordConfirm);
Assert.Equal(request.Use2fa, result.Use2fa);
}
[Fact]
@@ -53,11 +52,11 @@ public class RegistrationRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.Password, result.Password);
Assert.Equal(request.PasswordConfirm, result.PasswordConfirm);
Assert.Equal(request.Use2fa, result.Use2fa);
}
[Fact]
@@ -70,11 +69,11 @@ public class RegistrationRequestMappingTests
SetupApplicationCommand result = request.ToSetupCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.Password.Should().BeNull();
result.PasswordConfirm.Should().BeNull();
result.Use2fa.Should().BeTrue();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.Password);
Assert.Null(result.PasswordConfirm);
Assert.True(result.Use2fa);
}
[Fact]
@@ -87,11 +86,11 @@ public class RegistrationRequestMappingTests
RegisterUserCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.Password.Should().BeNull();
result.PasswordConfirm.Should().BeNull();
result.Use2fa.Should().BeTrue();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.Password);
Assert.Null(result.PasswordConfirm);
Assert.True(result.Use2fa);
}
[Theory]
@@ -112,11 +111,11 @@ public class RegistrationRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(password, result.Password);
Assert.Equal(passwordConfirm, result.PasswordConfirm);
Assert.Equal(use2fa, result.Use2fa);
}
[Theory]
@@ -137,10 +136,10 @@ public class RegistrationRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(password, result.Password);
Assert.Equal(passwordConfirm, result.PasswordConfirm);
Assert.Equal(use2fa, result.Use2fa);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
using Lumina.Contracts.Requests.Authorization;
@@ -29,9 +28,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Equal(request.Permissions, result.Permissions);
}
[Fact]
@@ -47,9 +46,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Empty(result.Permissions);
}
[Theory]
@@ -68,9 +67,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(roleName);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(roleName, result.RoleName);
Assert.Equal(request.Permissions, result.Permissions);
}
[Fact]
@@ -89,9 +88,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEquivalentTo(permissions);
result.Permissions.Should().HaveCount(3);
Assert.NotNull(result);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Equal(permissions, result.Permissions);
Assert.Equal(3, result.Permissions.Count);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class DeleteRoleRequestMappingTests
DeleteRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId!.Value);
Assert.NotNull(result);
Assert.Equal(request.RoleId!.Value, result.RoleId);
}
[Theory]
@@ -44,8 +43,8 @@ public class DeleteRoleRequestMappingTests
DeleteRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(roleId);
Assert.NotNull(result);
Assert.Equal(roleId, result.RoleId);
}
[Fact]
@@ -54,11 +53,8 @@ public class DeleteRoleRequestMappingTests
// Arrange
DeleteRoleRequest request = new(null);
// Act
Action act = () => request.ToCommand();
// Assert
act.Should().Throw<InvalidOperationException>();
// Act & Assert
Assert.Throws<InvalidOperationException>(() => request.ToCommand());
}
[Fact]
@@ -71,7 +67,7 @@ public class DeleteRoleRequestMappingTests
DeleteRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.RoleId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetAuthorizationRequestMappingTests
GetAuthorizationQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -40,8 +39,8 @@ public class GetAuthorizationRequestMappingTests
GetAuthorizationQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.UserId);
}
[Theory]
@@ -58,7 +57,7 @@ public class GetAuthorizationRequestMappingTests
GetAuthorizationQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetRolePermissionsRequestMappingTests
GetRolePermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId);
Assert.NotNull(result);
Assert.Equal(request.RoleId, result.RoleId);
}
[Theory]
@@ -44,8 +43,8 @@ public class GetRolePermissionsRequestMappingTests
GetRolePermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(roleId);
Assert.NotNull(result);
Assert.Equal(roleId, result.RoleId);
}
[Fact]
@@ -58,7 +57,7 @@ public class GetRolePermissionsRequestMappingTests
GetRolePermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.RoleId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -40,8 +39,8 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.UserId);
}
[Theory]
@@ -58,8 +57,8 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -72,7 +71,7 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.UserId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -40,8 +39,8 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.UserId);
}
[Theory]
@@ -58,8 +57,8 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -72,7 +71,7 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.UserId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
@@ -7,6 +6,7 @@ using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
@@ -31,9 +31,9 @@ public class PermissionEntityMappingTests
PermissionResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.PermissionName.Should().Be(entity.PermissionName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.PermissionName, result.PermissionName);
}
[Theory]
@@ -54,9 +54,9 @@ public class PermissionEntityMappingTests
PermissionResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.PermissionName.Should().Be(permission);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(permission, result.PermissionName);
}
[Fact]
@@ -74,11 +74,10 @@ public class PermissionEntityMappingTests
IEnumerable<PermissionResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(3);
results.Should().BeEquivalentTo(entities, options => options
.Including(x => x.Id)
.Including(x => x.PermissionName));
Assert.NotNull(results);
Assert.Equal(3, results.Count());
Assert.Equal(entities.Select(e => e.Id), results.Select(r => r.Id));
Assert.Equal(entities.Select(e => e.PermissionName), results.Select(r => r.PermissionName));
}
[Fact]
@@ -91,8 +90,8 @@ public class PermissionEntityMappingTests
IEnumerable<PermissionResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().BeEmpty();
Assert.NotNull(results);
Assert.Empty(results);
}
[Theory]
@@ -112,8 +111,8 @@ public class PermissionEntityMappingTests
PermissionResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.PermissionName.Should().Be(entity.PermissionName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.PermissionName, result.PermissionName);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
@@ -7,6 +6,7 @@ using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
@@ -31,9 +31,9 @@ public class RoleEntityMappingTests
RoleResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.RoleName.Should().Be(entity.RoleName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.RoleName, result.RoleName);
}
[Fact]
@@ -77,10 +77,10 @@ public class RoleEntityMappingTests
RolePermissionsResponse result = role.ToRolePermissionsResponse();
// Assert
result.Should().NotBeNull();
result.Role.Id.Should().Be(role.Id);
result.Role.RoleName.Should().Be(role.RoleName);
result.Permissions.Should().HaveCount(2);
Assert.NotNull(result);
Assert.Equal(role.Id, result.Role.Id);
Assert.Equal(role.RoleName, result.Role.RoleName);
Assert.Equal(2, result.Permissions.Length);
}
[Fact]
@@ -98,11 +98,14 @@ public class RoleEntityMappingTests
IEnumerable<RoleResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(3);
results.Should().BeEquivalentTo(entities, options => options
.Including(x => x.Id)
.Including(x => x.RoleName));
Assert.NotNull(results);
Assert.Equal(3, results.Count());
List<RoleResponse> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
Assert.Equal(entities[i].Id, resultList[i].Id);
Assert.Equal(entities[i].RoleName, resultList[i].RoleName);
}
}
[Fact]
@@ -115,8 +118,8 @@ public class RoleEntityMappingTests
IEnumerable<RoleResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().BeEmpty();
Assert.NotNull(results);
Assert.Empty(results);
}
[Theory]
@@ -136,9 +139,9 @@ public class RoleEntityMappingTests
RoleResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.RoleName.Should().Be(roleName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(roleName, result.RoleName);
}
[Theory]
@@ -158,8 +161,8 @@ public class RoleEntityMappingTests
RoleResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.RoleName.Should().Be(entity.RoleName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.RoleName, result.RoleName);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
using Lumina.Contracts.Requests.Authorization;
@@ -31,10 +30,10 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId!.Value);
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.RoleId!.Value, result.RoleId);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Equal(request.Permissions, result.Permissions);
}
[Theory]
@@ -54,8 +53,8 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(roleName);
Assert.NotNull(result);
Assert.Equal(roleName, result.RoleName);
}
[Theory]
@@ -75,8 +74,8 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId!.Value);
Assert.NotNull(result);
Assert.Equal(request.RoleId!.Value, result.RoleId);
}
[Fact]
@@ -95,8 +94,8 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Permissions.Should().BeEquivalentTo(permissions);
result.Permissions.Should().HaveCount(3);
Assert.NotNull(result);
Assert.Equal(permissions, result.Permissions);
Assert.Equal(3, result.Permissions.Count);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
using Lumina.Contracts.Requests.Authorization;
@@ -31,10 +30,10 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId!.Value);
result.RoleId.Should().Be(request.RoleId);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.UserId!.Value, result.UserId);
Assert.Equal(request.RoleId, result.RoleId);
Assert.Equal(request.Permissions, result.Permissions);
}
[Fact]
@@ -52,10 +51,10 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId!.Value);
result.RoleId.Should().BeNull();
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.UserId!.Value, result.UserId);
Assert.Null(result.RoleId);
Assert.Equal(request.Permissions, result.Permissions);
}
[Theory]
@@ -75,8 +74,8 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId!.Value);
Assert.NotNull(result);
Assert.Equal(request.UserId!.Value, result.UserId);
}
[Fact]
@@ -99,8 +98,8 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Permissions.Should().BeEquivalentTo(permissions);
result.Permissions.Should().HaveCount(3);
Assert.NotNull(result);
Assert.Equal(permissions, result.Permissions);
Assert.Equal(3, result.Permissions.Count);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
@@ -32,10 +31,10 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEquivalentTo(entity.Role);
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Role, result.Role);
Assert.Equal(entity.Permissions, result.Permissions);
}
[Fact]
@@ -53,10 +52,10 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEmpty();
result.Permissions.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Empty(result.Role!);
Assert.Empty(result.Permissions);
}
[Fact]
@@ -79,10 +78,10 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEquivalentTo(entity.Role);
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Role, result.Role);
Assert.Equal(entity.Permissions, result.Permissions);
}
[Theory]
@@ -103,9 +102,9 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEquivalentTo(entity.Role);
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Role, result.Role);
Assert.Equal(entity.Permissions, result.Permissions);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -27,9 +26,9 @@ public class GenreDtoMappingTests
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(genreDto.Name, result.Value.Name);
}
[Theory]
@@ -46,9 +45,9 @@ public class GenreDtoMappingTests
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(genreDto.Name, result.Value.Name);
}
[Theory]
@@ -64,7 +63,7 @@ public class GenreDtoMappingTests
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
Assert.True(result.IsError);
}
[Fact]
@@ -83,14 +82,14 @@ public class GenreDtoMappingTests
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreDtos.Count);
Assert.NotNull(results);
Assert.Equal(genreDtos.Count, results.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);
Assert.False(resultList[i].IsError);
Assert.Equal(genreDtos[i].Name, resultList[i].Value.Name);
}
}
@@ -110,18 +109,18 @@ public class GenreDtoMappingTests
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreDtos.Count);
Assert.NotNull(results);
Assert.Equal(genreDtos.Count, results.Count());
List<ErrorOr<Genre>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("Rock");
Assert.False(resultList[0].IsError);
Assert.Equal("Rock", resultList[0].Value.Name);
resultList[1].IsError.Should().BeTrue();
Assert.True(resultList[1].IsError);
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("Jazz");
Assert.False(resultList[2].IsError);
Assert.Equal("Jazz", resultList[2].Value.Name);
resultList[3].IsError.Should().BeTrue();
Assert.True(resultList[3].IsError);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -29,8 +28,8 @@ public class GenreEntityMappingTests
GenreDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -47,8 +46,8 @@ public class GenreEntityMappingTests
GenreDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -64,7 +63,7 @@ public class GenreEntityMappingTests
GenreDto result = entity.ToResponse();
// Assert
result.Name.Should().Be(invalidName);
Assert.Equal(invalidName, result.Name);
}
[Fact]
@@ -77,9 +76,9 @@ public class GenreEntityMappingTests
ErrorOr<Genre> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(entity.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(entity.Name, result.Value.Name);
}
[Theory]
@@ -95,8 +94,8 @@ public class GenreEntityMappingTests
ErrorOr<Genre> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Metadata.GenreNameCannotBeEmpty);
Assert.True(result.IsError);
Assert.Equal(Errors.Metadata.GenreNameCannotBeEmpty, result.FirstError);
}
[Fact]
@@ -115,14 +114,14 @@ public class GenreEntityMappingTests
IEnumerable<ErrorOr<Genre>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.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);
Assert.False(resultList[i].IsError);
Assert.Equal(entities[i].Name, resultList[i].Value.Name);
}
}
@@ -142,13 +141,13 @@ public class GenreEntityMappingTests
IEnumerable<GenreDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<GenreDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].Name.Should().Be(entities[i].Name);
Assert.Equal(entities[i].Name, resultList[i].Name);
}
}
}
@@ -1,6 +1,5 @@
#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;
@@ -22,15 +21,15 @@ public class GenreMappingTests
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create("Rock");
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
Assert.NotNull(result);
Assert.Equal(genre.Name, result.Name);
}
[Theory]
@@ -42,15 +41,15 @@ public class GenreMappingTests
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create(name);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
Assert.NotNull(result);
Assert.Equal(genre.Name, result.Name);
}
[Fact]
@@ -69,10 +68,10 @@ public class GenreMappingTests
IEnumerable<GenreEntity> results = genres.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genres.Count);
Assert.NotNull(results);
Assert.Equal(genres.Count, results.Count());
List<GenreEntity> resultList = results.ToList();
for (int i = 0; i < genres.Count; i++)
resultList[i].Name.Should().Be(genres[i].Name);
Assert.Equal(genres[i].Name, resultList[i].Name);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -27,9 +26,9 @@ public class TagDtoMappingTests
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(tagDto.Name, result.Value.Name);
}
[Theory]
@@ -47,9 +46,9 @@ public class TagDtoMappingTests
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(tagDto.Name, result.Value.Name);
}
[Theory]
@@ -65,7 +64,7 @@ public class TagDtoMappingTests
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
Assert.True(result.IsError);
}
[Fact]
@@ -84,14 +83,14 @@ public class TagDtoMappingTests
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagDtos.Count);
Assert.NotNull(results);
Assert.Equal(tagDtos.Count, results.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);
Assert.False(resultList[i].IsError);
Assert.Equal(tagDtos[i].Name, resultList[i].Value.Name);
}
}
@@ -111,18 +110,18 @@ public class TagDtoMappingTests
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagDtos.Count);
Assert.NotNull(results);
Assert.Equal(tagDtos.Count, results.Count());
List<ErrorOr<Tag>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("indie");
Assert.False(resultList[0].IsError);
Assert.Equal("indie", resultList[0].Value.Name);
resultList[1].IsError.Should().BeTrue();
Assert.True(resultList[1].IsError);
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("electronic");
Assert.False(resultList[2].IsError);
Assert.Equal("electronic", resultList[2].Value.Name);
resultList[3].IsError.Should().BeTrue();
Assert.True(resultList[3].IsError);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -29,8 +28,8 @@ public class TagEntityMappingTests
TagDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -47,8 +46,8 @@ public class TagEntityMappingTests
TagDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -64,7 +63,7 @@ public class TagEntityMappingTests
TagDto result = entity.ToResponse();
// Assert
result.Name.Should().Be(invalidName);
Assert.Equal(invalidName, result.Name);
}
[Fact]
@@ -77,9 +76,9 @@ public class TagEntityMappingTests
ErrorOr<Tag> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(entity.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(entity.Name, result.Value.Name);
}
[Theory]
@@ -95,8 +94,8 @@ public class TagEntityMappingTests
ErrorOr<Tag> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Metadata.TagNameCannotBeEmpty);
Assert.True(result.IsError);
Assert.Equal(Errors.Metadata.TagNameCannotBeEmpty, result.FirstError);
}
[Fact]
@@ -115,14 +114,14 @@ public class TagEntityMappingTests
IEnumerable<ErrorOr<Tag>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.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);
Assert.False(resultList[i].IsError);
Assert.Equal(entities[i].Name, resultList[i].Value.Name);
}
}
@@ -142,13 +141,11 @@ public class TagEntityMappingTests
IEnumerable<TagDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<TagDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].Name.Should().Be(entities[i].Name);
}
Assert.Equal(entities[i].Name, resultList[i].Name);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -22,15 +21,15 @@ public class TagMappingTests
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create("indie");
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
Assert.NotNull(result);
Assert.Equal(tag.Name, result.Name);
}
[Theory]
@@ -43,15 +42,15 @@ public class TagMappingTests
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create(name);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
Assert.NotNull(result);
Assert.Equal(tag.Name, result.Name);
}
[Fact]
@@ -71,10 +70,10 @@ public class TagMappingTests
IEnumerable<TagEntity> results = tags.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tags.Count);
Assert.NotNull(results);
Assert.Equal(tags.Count, results.Count());
List<TagEntity> resultList = results.ToList();
for (int i = 0; i < tags.Count; i++)
resultList[i].Name.Should().Be(tags[i].Name);
Assert.Equal(tags[i].Name, resultList[i].Name);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -37,11 +36,11 @@ public class FileSystemTreeNodeResponseMappingTests
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);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(response.Path, result.Value.Id.Path);
Assert.Equal(response.Name, result.Value.Name);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
}
[Fact]
@@ -54,8 +53,8 @@ public class FileSystemTreeNodeResponseMappingTests
ErrorOr<UnixRootItem> result = response.ToUnixRootItem();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -46,20 +45,20 @@ public class DirectoryMappingTests
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);
Assert.NotNull(result);
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.NotNull(result.Children);
Assert.Equal(childItems.Count, result.Children.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);
Assert.Equal(childItems[i].Name, result.Children[i].Name);
Assert.Equal(childItems[i].Id.Path, result.Children[i].Path);
Assert.Equal(childItems[i].Type, result.Children[i].ItemType);
}
}
@@ -73,15 +72,15 @@ public class DirectoryMappingTests
IEnumerable<FileSystemTreeNodeResponse> result = directories.ToFileSystemTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(directories.Count);
Assert.NotNull(result);
Assert.Equal(directories.Count, result.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);
Assert.Equal(directories[i].Name, resultList[i].Name);
Assert.Equal(directories[i].Id.Path, resultList[i].Path);
Assert.Equal(directories[i].Type, resultList[i].ItemType);
}
}
@@ -102,18 +101,18 @@ public class DirectoryMappingTests
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);
Assert.NotNull(result);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.DateCreated.Value, result.DateCreated);
Assert.Equal(directory.DateModified.Value, result.DateModified);
Assert.NotNull(result.Items);
Assert.Equal(childItems.Count, result.Items.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);
Assert.Equal(childItems[i].Name, result.Items[i].Name);
Assert.Equal(childItems[i].Id.Path, result.Items[i].Path);
}
}
@@ -127,16 +126,16 @@ public class DirectoryMappingTests
IEnumerable<DirectoryResponse> result = directories.ToResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(directories.Count);
Assert.NotNull(result);
Assert.Equal(directories.Count, result.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);
Assert.Equal(directories[i].Id.Path, resultList[i].Path);
Assert.Equal(directories[i].Name, resultList[i].Name);
Assert.Equal(directories[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(directories[i].DateModified.Value, resultList[i].DateModified);
}
}
}
@@ -1,7 +1,6 @@
#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;
@@ -36,8 +35,8 @@ public class GetDirectoriesRequestMappingTests
GetDirectoriesQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -59,11 +58,11 @@ public class FileSystemItemMappingTests
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));
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.True((DateTime.Now - result.DateCreated) < TimeSpan.FromSeconds(1));
Assert.True((DateTime.Now - result.DateModified) < TimeSpan.FromSeconds(1));
}
[Fact]
@@ -76,10 +75,10 @@ public class FileSystemItemMappingTests
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);
Assert.NotNull(result);
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Type, result.ItemType);
}
[Fact]
@@ -92,10 +91,10 @@ public class FileSystemItemMappingTests
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);
Assert.NotNull(result);
Assert.Equal(file.Name, result.Name);
Assert.Equal(file.Id.Path, result.Path);
Assert.Equal(file.Type, result.ItemType);
}
[Fact]
@@ -108,13 +107,13 @@ public class FileSystemItemMappingTests
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();
Assert.NotNull(result);
Assert.Equal(windowsRootItem.Name, result.Name);
Assert.Equal(windowsRootItem.Id.Path, result.Path);
Assert.Equal(windowsRootItem.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
[Fact]
@@ -127,13 +126,13 @@ public class FileSystemItemMappingTests
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();
Assert.NotNull(result);
Assert.Equal(unixRootItem.Name, result.Name);
Assert.Equal(unixRootItem.Id.Path, result.Path);
Assert.Equal(unixRootItem.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
[Theory]
@@ -149,11 +148,11 @@ public class FileSystemItemMappingTests
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));
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.True((DateTime.Now - result.DateCreated) < TimeSpan.FromSeconds(1));
Assert.True((DateTime.Now - result.DateModified) < TimeSpan.FromSeconds(1));
}
[Fact]
@@ -163,26 +162,26 @@ public class FileSystemItemMappingTests
List<FileSystemItem> domainModels =
[
_directoryFixture.CreateDirectory(),
_fileFixture.CreateFile(),
_windowsRootItemFixture.Create(),
_unixRootItemFixture.Create()
_fileFixture.CreateFile(),
_windowsRootItemFixture.Create(),
_unixRootItemFixture.Create()
];
// Act
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count);
Assert.NotNull(result);
Assert.Equal(domainModels.Count, result.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();
Assert.Equal(domainModels[i].Name, resultList[i].Name);
Assert.Equal(domainModels[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModels[i].Type, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
}
}
@@ -196,9 +195,8 @@ public class FileSystemItemMappingTests
FileSystemItemFixture invalidItem = new(id, name, type);
// Act & Assert
invalidItem.Invoking(item => item.ToTreeNodeResponse())
.Should().Throw<ArgumentException>()
.WithMessage("Invalid FileSystemItem");
ArgumentException exception = Assert.Throws<ArgumentException>(() => invalidItem.ToTreeNodeResponse());
Assert.Equal("Invalid FileSystemItem", exception.Message);
}
[Fact]
@@ -211,19 +209,19 @@ public class FileSystemItemMappingTests
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count());
Assert.NotNull(result);
Assert.Equal(domainModels.Count(), result.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();
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Type, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
}
}
}
@@ -1,14 +1,9 @@
#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.Common.Enums.FileSystem;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -25,20 +20,20 @@ public class UnixRootItemMappingTests
{
// Arrange
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
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();
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(FileSystemItemType.Root, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.NotNull(result.Children);
Assert.Empty(result.Children);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -23,20 +22,20 @@ public class WindowsRootItemMappingTests
string path = "C:\\";
string name = "C:";
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
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();
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(FileSystemItemType.Root, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
[Fact]
@@ -47,19 +46,19 @@ public class WindowsRootItemMappingTests
string name = "D:";
FileSystemItemStatus customStatus = FileSystemItemStatus.Inaccessible;
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name, customStatus);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
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();
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(FileSystemItemType.Root, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -40,12 +39,12 @@ public class FileMappingTests
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();
Assert.NotNull(result);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
}
[Fact]
@@ -58,19 +57,19 @@ public class FileMappingTests
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToFileSystemTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count());
Assert.NotNull(result);
Assert.Equal(domainModels.Count(), result.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();
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Type, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
}
}
@@ -84,12 +83,12 @@ public class FileMappingTests
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);
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(domainModel.DateCreated.Value, result.DateCreated);
Assert.Equal(domainModel.DateModified.Value, result.DateModified);
Assert.Equal(domainModel.Size, result.Size);
}
[Fact]
@@ -102,18 +101,18 @@ public class FileMappingTests
IEnumerable<FileResponse> result = domainModels.ToResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count());
Assert.NotNull(result);
Assert.Equal(domainModels.Count(), result.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);
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Size, resultList[i].Size);
Assert.Equal(domainModelsList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(domainModelsList[i].DateModified.Value, resultList[i].DateModified);
}
}
}
@@ -1,7 +1,6 @@
#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;
@@ -36,8 +35,8 @@ public class GetFilesRequestMappingTests
GetFilesQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
}
@@ -1,7 +1,6 @@
#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;
@@ -36,8 +35,8 @@ public class GetTreeFilesRequestMappingTests
GetTreeFilesQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
}
@@ -1,7 +1,6 @@
#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;
@@ -38,9 +37,9 @@ public class CheckPathExistsRequestMappingTests
CheckPathExistsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
[Theory]
@@ -56,9 +55,9 @@ public class CheckPathExistsRequestMappingTests
CheckPathExistsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
result.IncludeHiddenElements.Should().Be(includeHiddenElements);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
Assert.Equal(includeHiddenElements, result.IncludeHiddenElements);
}
[Fact]
@@ -71,12 +70,12 @@ public class CheckPathExistsRequestMappingTests
List<CheckPathExistsQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.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);
Assert.Equal(requests[i].Path, results[i].Path);
Assert.Equal(requests[i].IncludeHiddenElements, results[i].IncludeHiddenElements);
}
}
}
@@ -1,7 +1,6 @@
#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;
@@ -38,9 +37,9 @@ public class CombinePathRequestMappingTests
CombinePathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.OriginalPath.Should().Be(request.OriginalPath);
result.NewPath.Should().Be(request.NewPath);
Assert.NotNull(result);
Assert.Equal(request.OriginalPath, result.OriginalPath);
Assert.Equal(request.NewPath, result.NewPath);
}
[Theory]
@@ -56,9 +55,9 @@ public class CombinePathRequestMappingTests
CombinePathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.OriginalPath.Should().Be(originalPath);
result.NewPath.Should().Be(newPath);
Assert.NotNull(result);
Assert.Equal(originalPath, result.OriginalPath);
Assert.Equal(newPath, result.NewPath);
}
[Fact]
@@ -71,12 +70,12 @@ public class CombinePathRequestMappingTests
List<CombinePathCommand> results = requests.Select(r => r.ToCommand()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.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);
Assert.Equal(requests[i].OriginalPath, results[i].OriginalPath);
Assert.Equal(requests[i].NewPath, results[i].NewPath);
}
}
}
@@ -1,7 +1,6 @@
#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;
@@ -38,8 +37,8 @@ public class GetPathParentRequestMappingTests
GetPathParentQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
}
[Theory]
@@ -55,8 +54,8 @@ public class GetPathParentRequestMappingTests
GetPathParentQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
}
[Fact]
@@ -69,11 +68,11 @@ public class GetPathParentRequestMappingTests
List<GetPathParentQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
Assert.Equal(requests[i].Path, results[i].Path);
}
}
}
@@ -1,7 +1,6 @@
#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;
@@ -38,8 +37,8 @@ public class GetPathRootRequestMappingTests
GetPathRootQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
}
[Theory]
@@ -56,8 +55,8 @@ public class GetPathRootRequestMappingTests
GetPathRootQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
}
[Fact]
@@ -70,11 +69,11 @@ public class GetPathRootRequestMappingTests
List<GetPathRootQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
Assert.Equal(requests[i].Path, results[i].Path);
}
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
@@ -22,15 +21,15 @@ public class PathSegmentMappingTests
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(pathSegment.Name);
Assert.NotNull(result);
Assert.Equal(pathSegment.Name, result.Path);
}
[Theory]
@@ -41,15 +40,15 @@ public class PathSegmentMappingTests
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create(name, isDirectory, isDrive);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(pathSegment.Name);
Assert.NotNull(result);
Assert.Equal(pathSegment.Name, result.Path);
}
[Fact]
@@ -68,10 +67,10 @@ public class PathSegmentMappingTests
IEnumerable<PathSegmentResponse> results = pathSegments.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(pathSegments.Count);
Assert.NotNull(results);
Assert.Equal(pathSegments.Count, results.Count());
List<PathSegmentResponse> resultList = results.ToList();
for (int i = 0; i < pathSegments.Count; i++)
resultList[i].Path.Should().Be(pathSegments[i].Name);
Assert.Equal(pathSegments[i].Name, resultList[i].Path);
}
}
@@ -1,7 +1,6 @@
#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;
@@ -38,8 +37,8 @@ public class SplitPathRequestMappingTests
SplitPathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
}
[Theory]
@@ -56,8 +55,8 @@ public class SplitPathRequestMappingTests
SplitPathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
}
[Fact]
@@ -70,9 +69,9 @@ public class SplitPathRequestMappingTests
List<SplitPathCommand> results = requests.Select(r => r.ToCommand()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
results[i].Path.Should().Be(requests[i].Path);
Assert.Equal(requests[i].Path, results[i].Path);
}
}
@@ -1,7 +1,6 @@
#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;
@@ -38,8 +37,8 @@ public class ValidatePathRequestMappingTests
ValidatePathQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
}
[Theory]
@@ -58,8 +57,8 @@ public class ValidatePathRequestMappingTests
ValidatePathQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
}
[Fact]
@@ -72,9 +71,9 @@ public class ValidatePathRequestMappingTests
List<ValidatePathQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
results[i].Path.Should().Be(requests[i].Path);
Assert.Equal(requests[i].Path, results[i].Path);
}
}
@@ -1,7 +1,6 @@
#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;
@@ -38,9 +37,9 @@ public class GetThumbnailRequestMappingTests
GetThumbnailQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.Quality.Should().Be(request.Quality);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.Quality, result.Quality);
}
[Theory]
@@ -56,9 +55,9 @@ public class GetThumbnailRequestMappingTests
GetThumbnailQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
result.Quality.Should().Be(quality);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
Assert.Equal(quality, result.Quality);
}
[Fact]
@@ -71,12 +70,12 @@ public class GetThumbnailRequestMappingTests
List<GetThumbnailQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.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);
Assert.Equal(requests[i].Path, results[i].Path);
Assert.Equal(requests[i].Quality, results[i].Quality);
}
}
}
@@ -1,7 +1,6 @@
#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;
@@ -39,9 +38,9 @@ public class ThumbnailMappingTests
ThumbnailResponse result = domainModel.ToResponse();
// Assert
result.Should().NotBeNull();
result.Type.Should().Be(domainModel.Type);
result.Bytes.Should().BeEquivalentTo(domainModel.Bytes);
Assert.NotNull(result);
Assert.Equal(domainModel.Type, result.Type);
Assert.Equal(domainModel.Bytes, result.Bytes);
}
[Theory]
@@ -58,9 +57,9 @@ public class ThumbnailMappingTests
ThumbnailResponse result = domainModel.ToResponse();
// Assert
result.Should().NotBeNull();
result.Type.Should().Be(imageType);
result.Bytes.Should().BeEquivalentTo(bytes);
Assert.NotNull(result);
Assert.Equal(imageType, result.Type);
Assert.Equal(bytes, result.Bytes);
}
[Fact]
@@ -75,9 +74,9 @@ public class ThumbnailMappingTests
ThumbnailResponse result = domainModel.ToResponse();
// Assert
result.Should().NotBeNull();
result.Type.Should().Be(imageType);
result.Bytes.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(imageType, result.Type);
Assert.Empty(result.Bytes);
}
[Fact]
@@ -90,12 +89,12 @@ public class ThumbnailMappingTests
List<ThumbnailResponse> results = thumbnails.Select(t => t.ToResponse()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(thumbnails.Count);
Assert.NotNull(results);
Assert.Equal(thumbnails.Count, results.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);
Assert.Equal(thumbnails[i].Type, results[i].Type);
Assert.Equal(thumbnails[i].Bytes, results[i].Bytes);
}
}
}
@@ -1,5 +1,4 @@
#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;
@@ -34,15 +33,15 @@ public class AddMediaLibraryRequestMappingTests
AddLibraryCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Title.Should().Be(request.Title);
result.LibraryType.Should().Be(request.LibraryType);
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
result.CoverImage.Should().BeEquivalentTo(request.CoverImage);
result.IsEnabled.Should().Be(request.IsEnabled);
result.IsLocked.Should().Be(request.IsLocked);
result.DownloadMedatadaFromWeb.Should().Be(request.DownloadMedatadaFromWeb);
result.SaveMetadataInMediaDirectories.Should().Be(request.SaveMetadataInMediaDirectories);
Assert.NotNull(result);
Assert.Equal(request.Title, result.Title);
Assert.Equal(request.LibraryType, result.LibraryType);
Assert.Equal(request.ContentLocations, result.ContentLocations);
Assert.Equal(request.CoverImage, result.CoverImage);
Assert.Equal(request.IsEnabled, result.IsEnabled);
Assert.Equal(request.IsLocked, result.IsLocked);
Assert.Equal(request.DownloadMedatadaFromWeb, result.DownloadMedatadaFromWeb);
Assert.Equal(request.SaveMetadataInMediaDirectories, result.SaveMetadataInMediaDirectories);
}
[Theory]
@@ -68,15 +67,15 @@ public class AddMediaLibraryRequestMappingTests
AddLibraryCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Title.Should().Be(request.Title);
result.LibraryType.Should().Be(libraryType.ToString());
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
result.CoverImage.Should().BeEquivalentTo(request.CoverImage);
result.IsEnabled.Should().Be(request.IsEnabled);
result.IsLocked.Should().Be(request.IsLocked);
result.DownloadMedatadaFromWeb.Should().Be(request.DownloadMedatadaFromWeb);
result.SaveMetadataInMediaDirectories.Should().Be(request.SaveMetadataInMediaDirectories);
Assert.NotNull(result);
Assert.Equal(request.Title, result.Title);
Assert.Equal(libraryType.ToString(), result.LibraryType);
Assert.Equal(request.ContentLocations, result.ContentLocations);
Assert.Equal(request.CoverImage, result.CoverImage);
Assert.Equal(request.IsEnabled, result.IsEnabled);
Assert.Equal(request.IsLocked, result.IsLocked);
Assert.Equal(request.DownloadMedatadaFromWeb, result.DownloadMedatadaFromWeb);
Assert.Equal(request.SaveMetadataInMediaDirectories, result.SaveMetadataInMediaDirectories);
}
[Fact]
@@ -106,8 +105,8 @@ public class AddMediaLibraryRequestMappingTests
AddLibraryCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Should().BeEquivalentTo(contentLocations);
Assert.NotNull(result);
Assert.Equal(contentLocations, result.ContentLocations);
}
[Fact]
@@ -135,7 +134,7 @@ public class AddMediaLibraryRequestMappingTests
AddLibraryCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.CoverImage.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.CoverImage);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -43,15 +42,15 @@ public class LibraryEntityMappingTests
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.CoverImage.Should().Be(entity.CoverImage);
result.CreatedOnUtc.Should().Be(entity.CreatedOnUtc);
result.UpdatedOnUtc.Should().Be(entity.UpdatedOnUtc);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Title, result.Title);
Assert.Equal(entity.LibraryType, result.LibraryType);
Assert.Equal(entity.ContentLocations.Select(l => l.Path), result.ContentLocations);
Assert.Equal(entity.CoverImage, result.CoverImage);
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
}
[Theory]
@@ -80,8 +79,8 @@ public class LibraryEntityMappingTests
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.LibraryType.Should().Be(libraryType);
Assert.NotNull(result);
Assert.Equal(libraryType, result.LibraryType);
}
[Fact]
@@ -112,8 +111,8 @@ public class LibraryEntityMappingTests
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Should().BeEquivalentTo(entity.ContentLocations.Select(l => l.Path));
Assert.NotNull(result);
Assert.Equal(entity.ContentLocations.Select(l => l.Path), result.ContentLocations);
}
[Fact]
@@ -139,8 +138,8 @@ public class LibraryEntityMappingTests
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UpdatedOnUtc.Should().Be(updated);
Assert.NotNull(result);
Assert.Equal(updated, result.UpdatedOnUtc);
}
[Fact]
@@ -166,7 +165,7 @@ public class LibraryEntityMappingTests
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.CoverImage.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.CoverImage);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -42,20 +41,19 @@ public class LibraryMappingTests
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.CoverImage.Should().BeEquivalentTo(library.CoverImage);
result.CreatedOnUtc.Should().Be(library.CreatedOnUtc);
result.UpdatedOnUtc.Should().Be(library.UpdatedOnUtc.HasValue ? library.UpdatedOnUtc : null);
result.IsEnabled.Should().BeTrue();
result.IsLocked.Should().BeFalse();
result.DownloadMedatadaFromWeb.Should().BeTrue();
result.SaveMetadataInMediaDirectories.Should().BeFalse();
Assert.NotNull(result);
Assert.Equal(library.Id.Value, result.Id);
Assert.Equal(library.UserId.Value, result.UserId);
Assert.Equal(library.Title, result.Title);
Assert.Equal(library.LibraryType, result.LibraryType);
Assert.Equal(library.ContentLocations.Select(l => l.Path), result.ContentLocations.Select(l => l.Path));
Assert.Equal(library.CoverImage, result.CoverImage);
Assert.Equal(library.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(library.UpdatedOnUtc, result.UpdatedOnUtc);
Assert.True(result.IsEnabled);
Assert.False(result.IsLocked);
Assert.True(result.DownloadMedatadaFromWeb);
Assert.False(result.SaveMetadataInMediaDirectories);
}
[Fact]
@@ -79,9 +77,9 @@ public class LibraryMappingTests
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Should().BeEmpty();
result.CoverImage.Should().BeEquivalentTo(library.CoverImage);
Assert.NotNull(result);
Assert.Empty(result.ContentLocations);
Assert.Equal(library.CoverImage, result.CoverImage);
}
[Theory]
@@ -109,13 +107,13 @@ public class LibraryMappingTests
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.LibraryType.Should().Be(libraryType);
result.CoverImage.Should().BeEquivalentTo(library.CoverImage);
result.IsEnabled.Should().BeTrue();
result.IsLocked.Should().BeFalse();
result.DownloadMedatadaFromWeb.Should().BeTrue();
result.SaveMetadataInMediaDirectories.Should().BeFalse();
Assert.NotNull(result);
Assert.Equal(libraryType, result.LibraryType);
Assert.Equal(library.CoverImage, result.CoverImage);
Assert.True(result.IsEnabled);
Assert.False(result.IsLocked);
Assert.True(result.DownloadMedatadaFromWeb);
Assert.False(result.SaveMetadataInMediaDirectories);
}
[Fact]
@@ -147,10 +145,9 @@ public class LibraryMappingTests
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Select(l => l.Path)
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
result.CoverImage.Should().BeEquivalentTo(library.CoverImage);
Assert.NotNull(result);
Assert.Equal(library.ContentLocations.Select(l => l.Path), result.ContentLocations.Select(l => l.Path));
Assert.Equal(library.CoverImage, result.CoverImage);
}
[Fact]
@@ -180,9 +177,8 @@ public class LibraryMappingTests
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Select(l => l.Path)
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
result.CoverImage.Should().BeNull();
Assert.NotNull(result);
Assert.Equal(library.ContentLocations.Select(l => l.Path), result.ContentLocations.Select(l => l.Path));
Assert.Null(result.CoverImage);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -38,24 +37,24 @@ public class AddBookRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(request.Metadata, result.Metadata);
Assert.Equal(request.Format, result.Format);
Assert.Equal(request.Edition, result.Edition);
Assert.Equal(request.VolumeNumber, result.VolumeNumber);
Assert.Equal(request.Series, result.Series);
Assert.Equal(request.ASIN, result.ASIN);
Assert.Equal(request.GoodreadsId, result.GoodreadsId);
Assert.Equal(request.LCCN, result.LCCN);
Assert.Equal(request.OCLCNumber, result.OCLCNumber);
Assert.Equal(request.OpenLibraryId, result.OpenLibraryId);
Assert.Equal(request.LibraryThingId, result.LibraryThingId);
Assert.Equal(request.GoogleBooksId, result.GoogleBooksId);
Assert.Equal(request.BarnesAndNobleId, result.BarnesAndNobleId);
Assert.Equal(request.AppleBooksId, result.AppleBooksId);
Assert.Equal(request.ISBNs, result.ISBNs);
Assert.Equal(request.Contributors, result.Contributors);
Assert.Equal(request.Ratings, result.Ratings);
}
[Fact]
@@ -95,24 +94,24 @@ public class AddBookRequestMappingTests
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();
Assert.NotNull(result);
Assert.Equal(request.Metadata, result.Metadata);
Assert.Null(result.Format);
Assert.Null(result.Edition);
Assert.Null(result.VolumeNumber);
Assert.Null(result.Series);
Assert.Null(result.ASIN);
Assert.Null(result.GoodreadsId);
Assert.Null(result.LCCN);
Assert.Null(result.OCLCNumber);
Assert.Null(result.OpenLibraryId);
Assert.Null(result.LibraryThingId);
Assert.Null(result.GoogleBooksId);
Assert.Null(result.BarnesAndNobleId);
Assert.Null(result.AppleBooksId);
Assert.Null(result.ISBNs);
Assert.Null(result.Contributors);
Assert.Null(result.Ratings);
}
[Fact]
@@ -158,9 +157,9 @@ public class AddBookRequestMappingTests
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);
Assert.NotNull(result);
Assert.Equal(request.ISBNs, result.ISBNs);
Assert.Equal(request.Contributors, result.Contributors);
Assert.Equal(request.Ratings, result.Ratings);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -37,42 +36,42 @@ public class BookMappingTests
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.CreatedOnUtc.Should().Be(book.CreatedOnUtc);
result.UpdatedOnUtc.Should().Be(book.UpdatedOnUtc.HasValue ? book.UpdatedOnUtc.Value : null);
Assert.NotNull(result);
Assert.Equal(book.Id.Value, result.Id);
Assert.Equal(book.Metadata.Title, result.Title);
Assert.Equal(book.Metadata.OriginalTitle.HasValue ? book.Metadata.OriginalTitle.Value : null, result.OriginalTitle);
Assert.Equal(book.Metadata.Description.HasValue ? book.Metadata.Description.Value : null, result.Description);
Assert.Equal(book.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null, result.OriginalReleaseDate);
Assert.Equal(book.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null, result.OriginalReleaseYear);
Assert.Equal(book.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? book.Metadata.ReleaseInfo.ReReleaseDate.Value : null, result.ReReleaseDate);
Assert.Equal(book.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? book.Metadata.ReleaseInfo.ReReleaseYear.Value : null, result.ReReleaseYear);
Assert.Equal(book.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? book.Metadata.ReleaseInfo.ReleaseCountry.Value : null, result.ReleaseCountry);
Assert.Equal(book.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? book.Metadata.ReleaseInfo.ReleaseVersion.Value : null, result.ReleaseVersion);
Assert.Equal(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageCode : null, result.LanguageCode);
Assert.Equal(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageName : null, result.LanguageName);
Assert.Equal(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.NativeName.Value : null, result.LanguageNativeName);
Assert.Equal(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageCode : null, result.OriginalLanguageCode);
Assert.Equal(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageName : null, result.OriginalLanguageName);
Assert.Equal(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.NativeName.Value : null, result.OriginalLanguageNativeName);
Assert.Equal(book.Metadata.Tags.ToRepositoryEntities(), result.Tags);
Assert.Equal(book.Metadata.Genres.ToRepositoryEntities(), result.Genres);
Assert.Equal(book.Metadata.Publisher.HasValue ? book.Metadata.Publisher.Value : null, result.Publisher);
Assert.Equal(book.Metadata.PageCount.HasValue ? book.Metadata.PageCount.Value : null, result.PageCount);
Assert.Equal(book.Format.HasValue ? book.Format.Value : null, result.Format);
Assert.Equal(book.Edition.HasValue ? book.Edition.Value : null, result.Edition);
Assert.Equal(book.VolumeNumber.HasValue ? book.VolumeNumber.Value : null, result.VolumeNumber);
Assert.Equal(book.ASIN.HasValue ? book.ASIN.Value : null, result.ASIN);
Assert.Equal(book.GoodreadsId.HasValue ? book.GoodreadsId.Value : null, result.GoodreadsId);
Assert.Equal(book.LCCN.HasValue ? book.LCCN.Value : null, result.LCCN);
Assert.Equal(book.OCLCNumber.HasValue ? book.OCLCNumber.Value : null, result.OCLCNumber);
Assert.Equal(book.OpenLibraryId.HasValue ? book.OpenLibraryId.Value : null, result.OpenLibraryId);
Assert.Equal(book.LibraryThingId.HasValue ? book.LibraryThingId.Value : null, result.LibraryThingId);
Assert.Equal(book.GoogleBooksId.HasValue ? book.GoogleBooksId.Value : null, result.GoogleBooksId);
Assert.Equal(book.BarnesAndNobleId.HasValue ? book.BarnesAndNobleId.Value : null, result.BarnesAndNobleId);
Assert.Equal(book.AppleBooksId.HasValue ? book.AppleBooksId.Value : null, result.AppleBooksId);
Assert.Equal(book.ISBNs.ToRepositoryEntities(), result.ISBNs);
Assert.Equal(book.Ratings.ToRepositoryEntities(), result.Ratings);
Assert.Equal(book.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(book.UpdatedOnUtc.HasValue ? book.UpdatedOnUtc.Value : null, result.UpdatedOnUtc);
}
}
@@ -1,14 +1,15 @@
#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.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
@@ -39,224 +40,224 @@ public class BookEntityMappingTests
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);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(bookEntity.Id, result.Value.Id.Value);
Assert.Equal(bookEntity.Title, result.Value.Metadata.Title);
if (bookEntity.OriginalTitle is not null)
{
result.Value.Metadata.OriginalTitle.HasValue.Should().BeTrue();
result.Value.Metadata.OriginalTitle.Value.Should().Be(bookEntity.OriginalTitle);
Assert.True(result.Value.Metadata.OriginalTitle.HasValue);
Assert.Equal(bookEntity.OriginalTitle, result.Value.Metadata.OriginalTitle.Value);
}
else
result.Value.Metadata.OriginalTitle.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.OriginalTitle.HasValue);
if (bookEntity.Description is not null)
{
result.Value.Metadata.Description.HasValue.Should().BeTrue();
result.Value.Metadata.Description.Value.Should().Be(bookEntity.Description);
Assert.True(result.Value.Metadata.Description.HasValue);
Assert.Equal(bookEntity.Description, result.Value.Metadata.Description.Value);
}
else
result.Value.Metadata.Description.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.Description.HasValue);
if (bookEntity.OriginalReleaseDate.HasValue)
{
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.Value.Should().Be(bookEntity.OriginalReleaseDate.Value);
Assert.True(result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
Assert.Equal(bookEntity.OriginalReleaseDate.Value, result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.Value);
}
else
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue);
if (bookEntity.OriginalReleaseYear.HasValue)
{
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.Value.Should().Be(bookEntity.OriginalReleaseYear.Value);
Assert.True(result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
Assert.Equal(bookEntity.OriginalReleaseYear.Value, result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.Value);
}
else
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue);
if (bookEntity.ReReleaseDate.HasValue)
{
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReReleaseDate.Value.Should().Be(bookEntity.ReReleaseDate.Value);
Assert.True(result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue);
Assert.Equal(bookEntity.ReReleaseDate.Value, result.Value.Metadata.ReleaseInfo.ReReleaseDate.Value);
}
else
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue);
if (bookEntity.ReReleaseYear.HasValue)
{
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReReleaseYear.Value.Should().Be(bookEntity.ReReleaseYear.Value);
Assert.True(result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue);
Assert.Equal(bookEntity.ReReleaseYear.Value, result.Value.Metadata.ReleaseInfo.ReReleaseYear.Value);
}
else
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue);
if (bookEntity.ReleaseCountry is not null)
{
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReleaseCountry.Value.Should().Be(bookEntity.ReleaseCountry);
Assert.True(result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue);
Assert.Equal(bookEntity.ReleaseCountry, result.Value.Metadata.ReleaseInfo.ReleaseCountry.Value);
}
else
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue);
if (bookEntity.ReleaseVersion is not null)
{
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReleaseVersion.Value.Should().Be(bookEntity.ReleaseVersion);
Assert.True(result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue);
Assert.Equal(bookEntity.ReleaseVersion, result.Value.Metadata.ReleaseInfo.ReleaseVersion.Value);
}
else
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue);
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);
Assert.True(result.Value.Metadata.Language.HasValue);
Assert.Equal(bookEntity.LanguageCode, result.Value.Metadata.Language.Value.LanguageCode);
Assert.Equal(bookEntity.LanguageName, result.Value.Metadata.Language.Value.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);
Assert.True(result.Value.Metadata.Language.Value.NativeName.HasValue);
Assert.Equal(bookEntity.LanguageNativeName, result.Value.Metadata.Language.Value.NativeName.Value);
}
else
result.Value.Metadata.Language.Value.NativeName.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.Language.Value.NativeName.HasValue);
}
else
result.Value.Metadata.Language.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.Language.HasValue);
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);
Assert.True(result.Value.Metadata.OriginalLanguage.HasValue);
Assert.Equal(bookEntity.OriginalLanguageCode, result.Value.Metadata.OriginalLanguage.Value.LanguageCode);
Assert.Equal(bookEntity.OriginalLanguageName, result.Value.Metadata.OriginalLanguage.Value.LanguageName);
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);
Assert.True(result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue);
Assert.Equal(bookEntity.OriginalLanguageNativeName, result.Value.Metadata.OriginalLanguage.Value.NativeName.Value);
}
else
result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue);
}
else
result.Value.Metadata.OriginalLanguage.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.OriginalLanguage.HasValue);
if (bookEntity.Publisher is not null)
{
result.Value.Metadata.Publisher.HasValue.Should().BeTrue();
result.Value.Metadata.Publisher.Value.Should().Be(bookEntity.Publisher);
Assert.True(result.Value.Metadata.Publisher.HasValue);
Assert.Equal(bookEntity.Publisher, result.Value.Metadata.Publisher.Value);
}
else
result.Value.Metadata.Publisher.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.Publisher.HasValue);
if (bookEntity.PageCount.HasValue)
{
result.Value.Metadata.PageCount.HasValue.Should().BeTrue();
result.Value.Metadata.PageCount.Value.Should().Be(bookEntity.PageCount.Value);
Assert.True(result.Value.Metadata.PageCount.HasValue);
Assert.Equal(bookEntity.PageCount.Value, result.Value.Metadata.PageCount.Value);
}
else
result.Value.Metadata.PageCount.HasValue.Should().BeFalse();
Assert.False(result.Value.Metadata.PageCount.HasValue);
result.Value.Format.Value.Should().Be(bookEntity.Format);
Assert.Equal(bookEntity.Format, result.Value.Format.Value);
if (bookEntity.Edition is not null)
{
result.Value.Edition.HasValue.Should().BeTrue();
result.Value.Edition.Value.Should().Be(bookEntity.Edition);
Assert.True(result.Value.Edition.HasValue);
Assert.Equal(bookEntity.Edition, result.Value.Edition.Value);
}
else
result.Value.Edition.HasValue.Should().BeFalse();
Assert.False(result.Value.Edition.HasValue);
if (bookEntity.VolumeNumber.HasValue)
{
result.Value.VolumeNumber.HasValue.Should().BeTrue();
result.Value.VolumeNumber.Value.Should().Be(bookEntity.VolumeNumber.Value);
Assert.True(result.Value.VolumeNumber.HasValue);
Assert.Equal(bookEntity.VolumeNumber.Value, result.Value.VolumeNumber.Value);
}
else
result.Value.VolumeNumber.HasValue.Should().BeFalse();
Assert.False(result.Value.VolumeNumber.HasValue);
if (bookEntity.ASIN is not null)
{
result.Value.ASIN.HasValue.Should().BeTrue();
result.Value.ASIN.Value.Should().Be(bookEntity.ASIN);
Assert.True(result.Value.ASIN.HasValue);
Assert.Equal(bookEntity.ASIN, result.Value.ASIN.Value);
}
else
result.Value.ASIN.HasValue.Should().BeFalse();
Assert.False(result.Value.ASIN.HasValue);
if (bookEntity.GoodreadsId is not null)
{
result.Value.GoodreadsId.HasValue.Should().BeTrue();
result.Value.GoodreadsId.Value.Should().Be(bookEntity.GoodreadsId);
Assert.True(result.Value.GoodreadsId.HasValue);
Assert.Equal(bookEntity.GoodreadsId, result.Value.GoodreadsId.Value);
}
else
result.Value.GoodreadsId.HasValue.Should().BeFalse();
Assert.False(result.Value.GoodreadsId.HasValue);
if (bookEntity.LCCN is not null)
{
result.Value.LCCN.HasValue.Should().BeTrue();
result.Value.LCCN.Value.Should().Be(bookEntity.LCCN);
Assert.True(result.Value.LCCN.HasValue);
Assert.Equal(bookEntity.LCCN, result.Value.LCCN.Value);
}
else
result.Value.LCCN.HasValue.Should().BeFalse();
Assert.False(result.Value.LCCN.HasValue);
if (bookEntity.OCLCNumber is not null)
{
result.Value.OCLCNumber.HasValue.Should().BeTrue();
result.Value.OCLCNumber.Value.Should().Be(bookEntity.OCLCNumber);
Assert.True(result.Value.OCLCNumber.HasValue);
Assert.Equal(bookEntity.OCLCNumber, result.Value.OCLCNumber.Value);
}
else
result.Value.OCLCNumber.HasValue.Should().BeFalse();
Assert.False(result.Value.OCLCNumber.HasValue);
if (bookEntity.OpenLibraryId is not null)
{
result.Value.OpenLibraryId.HasValue.Should().BeTrue();
result.Value.OpenLibraryId.Value.Should().Be(bookEntity.OpenLibraryId);
Assert.True(result.Value.OpenLibraryId.HasValue);
Assert.Equal(bookEntity.OpenLibraryId, result.Value.OpenLibraryId.Value);
}
else
result.Value.OpenLibraryId.HasValue.Should().BeFalse();
Assert.False(result.Value.OpenLibraryId.HasValue);
if (bookEntity.LibraryThingId is not null)
{
result.Value.LibraryThingId.HasValue.Should().BeTrue();
result.Value.LibraryThingId.Value.Should().Be(bookEntity.LibraryThingId);
Assert.True(result.Value.LibraryThingId.HasValue);
Assert.Equal(bookEntity.LibraryThingId, result.Value.LibraryThingId.Value);
}
else
result.Value.LibraryThingId.HasValue.Should().BeFalse();
Assert.False(result.Value.LibraryThingId.HasValue);
if (bookEntity.GoogleBooksId is not null)
{
result.Value.GoogleBooksId.HasValue.Should().BeTrue();
result.Value.GoogleBooksId.Value.Should().Be(bookEntity.GoogleBooksId);
Assert.True(result.Value.GoogleBooksId.HasValue);
Assert.Equal(bookEntity.GoogleBooksId, result.Value.GoogleBooksId.Value);
}
else
result.Value.GoogleBooksId.HasValue.Should().BeFalse();
Assert.False(result.Value.GoogleBooksId.HasValue);
if (bookEntity.BarnesAndNobleId is not null)
{
result.Value.BarnesAndNobleId.HasValue.Should().BeTrue();
result.Value.BarnesAndNobleId.Value.Should().Be(bookEntity.BarnesAndNobleId);
Assert.True(result.Value.BarnesAndNobleId.HasValue);
Assert.Equal(bookEntity.BarnesAndNobleId, result.Value.BarnesAndNobleId.Value);
}
else
result.Value.BarnesAndNobleId.HasValue.Should().BeFalse();
Assert.False(result.Value.BarnesAndNobleId.HasValue);
if (bookEntity.AppleBooksId is not null)
{
result.Value.AppleBooksId.HasValue.Should().BeTrue();
result.Value.AppleBooksId.Value.Should().Be(bookEntity.AppleBooksId);
Assert.True(result.Value.AppleBooksId.HasValue);
Assert.Equal(bookEntity.AppleBooksId, result.Value.AppleBooksId.Value);
}
else
result.Value.AppleBooksId.HasValue.Should().BeFalse();
Assert.False(result.Value.AppleBooksId.HasValue);
result.Value.CreatedOnUtc.Should().Be(bookEntity.CreatedOnUtc);
Assert.Equal(bookEntity.CreatedOnUtc, result.Value.CreatedOnUtc);
if (bookEntity.UpdatedOnUtc.HasValue)
{
result.Value.UpdatedOnUtc.HasValue.Should().BeTrue();
result.Value.UpdatedOnUtc!.Value.Should().Be(bookEntity.UpdatedOnUtc.Value);
Assert.True(result.Value.UpdatedOnUtc.HasValue);
Assert.Equal(bookEntity.UpdatedOnUtc.Value, result.Value.UpdatedOnUtc!.Value);
}
else
result.Value.UpdatedOnUtc.HasValue.Should().BeFalse();
Assert.False(result.Value.UpdatedOnUtc.HasValue);
}
[Fact]
@@ -269,43 +270,48 @@ public class BookEntityMappingTests
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.CreatedOnUtc.Should().Be(bookEntity.CreatedOnUtc);
result.UpdatedOnUtc.Should().Be(bookEntity.UpdatedOnUtc);
Assert.NotNull(result);
Assert.Equal(bookEntity.Id, result.Id);
Assert.Equal(bookEntity.Title, result.Metadata.Title);
Assert.Equal(bookEntity.OriginalTitle, result.Metadata.OriginalTitle);
Assert.Equal(bookEntity.Description, result.Metadata.Description);
Assert.Equal(bookEntity.OriginalReleaseDate, result.Metadata.ReleaseInfo!.OriginalReleaseDate);
Assert.Equal(bookEntity.OriginalReleaseYear, result.Metadata.ReleaseInfo.OriginalReleaseYear);
Assert.Equal(bookEntity.ReReleaseDate, result.Metadata.ReleaseInfo.ReReleaseDate);
Assert.Equal(bookEntity.ReReleaseYear, result.Metadata.ReleaseInfo.ReReleaseYear);
Assert.Equal(bookEntity.ReleaseCountry, result.Metadata.ReleaseInfo.ReleaseCountry);
Assert.Equal(bookEntity.ReleaseVersion, result.Metadata.ReleaseInfo.ReleaseVersion);
Assert.NotNull(result.Metadata.Language);
Assert.Equal(bookEntity.LanguageCode, result.Metadata.Language!.LanguageCode);
Assert.Equal(bookEntity.LanguageName, result.Metadata.Language.LanguageName);
Assert.Equal(bookEntity.LanguageNativeName, result.Metadata.Language.NativeName);
Assert.NotNull(result.Metadata.OriginalLanguage);
Assert.Equal(bookEntity.OriginalLanguageCode, result.Metadata.OriginalLanguage!.LanguageCode);
Assert.Equal(bookEntity.OriginalLanguageName, result.Metadata.OriginalLanguage.LanguageName);
Assert.Equal(bookEntity.OriginalLanguageNativeName, result.Metadata.OriginalLanguage.NativeName);
Assert.Equal(bookEntity.Publisher, result.Metadata.Publisher);
Assert.Equal(bookEntity.PageCount, result.Metadata.PageCount);
Assert.Equal(bookEntity.Format, result.Format);
Assert.Equal(bookEntity.Edition, result.Edition);
Assert.Equal(bookEntity.VolumeNumber, result.VolumeNumber);
Assert.Equal(bookEntity.ASIN, result.ASIN);
Assert.Equal(bookEntity.GoodreadsId, result.GoodreadsId);
Assert.Equal(bookEntity.LCCN, result.LCCN);
Assert.Equal(bookEntity.OCLCNumber, result.OCLCNumber);
Assert.Equal(bookEntity.OpenLibraryId, result.OpenLibraryId);
Assert.Equal(bookEntity.LibraryThingId, result.LibraryThingId);
Assert.Equal(bookEntity.GoogleBooksId, result.GoogleBooksId);
Assert.Equal(bookEntity.BarnesAndNobleId, result.BarnesAndNobleId);
Assert.Equal(bookEntity.AppleBooksId, result.AppleBooksId);
Assert.Equal(bookEntity.ISBNs.Select(i => new IsbnDto(i.Value, i.Format)), result.ISBNs);
Assert.Equal(bookEntity.Ratings.Select(r => new BookRatingDto(
r.Value,
r.MaxValue,
r.Source,
r.VoteCount
)), result.Ratings);
Assert.Equal(bookEntity.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(bookEntity.UpdatedOnUtc, result.UpdatedOnUtc);
}
[Fact]
@@ -322,9 +328,9 @@ public class BookEntityMappingTests
IEnumerable<ErrorOr<Book>> results = bookEntities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(bookEntities.Count);
results.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
Assert.NotNull(results);
Assert.Equal(bookEntities.Count, results.Count());
Assert.All(results, result => Assert.False(result.IsError));
}
[Fact]
@@ -341,7 +347,7 @@ public class BookEntityMappingTests
IEnumerable<BookResponse> results = bookEntities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(bookEntities.Count);
Assert.NotNull(results);
Assert.Equal(bookEntities.Count, results.Count());
}
}
@@ -1,6 +1,5 @@
#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;
@@ -39,26 +38,26 @@ public class BookRatingDtoMappingTests
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);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value!.Value, result.Value.Value);
Assert.Equal(dto.MaxValue!.Value, result.Value.MaxValue);
if (dto.Source.HasValue)
{
result.Value.Source.HasValue.Should().BeTrue();
result.Value.Source.Value.Should().Be(dto.Source.Value);
Assert.True(result.Value.Source.HasValue);
Assert.Equal(dto.Source.Value, result.Value.Source.Value);
}
else
result.Value.Source.HasValue.Should().BeFalse();
Assert.False(result.Value.Source.HasValue);
if (dto.VoteCount.HasValue)
{
result.Value.VoteCount.HasValue.Should().BeTrue();
result.Value.VoteCount.Value.Should().Be(dto.VoteCount.Value);
Assert.True(result.Value.VoteCount.HasValue);
Assert.Equal(dto.VoteCount.Value, result.Value.VoteCount.Value);
}
else
result.Value.VoteCount.HasValue.Should().BeFalse();
Assert.False(result.Value.VoteCount.HasValue);
}
[Fact]
@@ -71,12 +70,12 @@ public class BookRatingDtoMappingTests
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();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value!.Value, result.Value.Value);
Assert.Equal(dto.MaxValue!.Value, result.Value.MaxValue);
Assert.False(result.Value.Source.HasValue);
Assert.False(result.Value.VoteCount.HasValue);
}
[Fact]
@@ -89,7 +88,7 @@ public class BookRatingDtoMappingTests
ErrorOr<BookRating> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
Assert.True(result.IsError);
}
[Fact]
@@ -106,23 +105,24 @@ public class BookRatingDtoMappingTests
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.Count);
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<BookRating>> resultList = results.ToList();
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
foreach (ErrorOr<BookRating> result in resultList)
Assert.False(result.IsError);
// 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);
// complete rating
Assert.Equal(dtos[0].Value!.Value, resultList[0].Value.Value);
Assert.Equal(dtos[0].MaxValue!.Value, resultList[0].Value.MaxValue);
Assert.Equal(dtos[0].Source!.Value, resultList[0].Value.Source.Value);
Assert.Equal(dtos[0].VoteCount!.Value, resultList[0].Value.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();
// minimal rating
Assert.Equal(dtos[1].Value!.Value, resultList[1].Value.Value);
Assert.Equal(dtos[1].MaxValue!.Value, resultList[1].Value.MaxValue);
Assert.False(resultList[1].Value.Source.HasValue);
Assert.False(resultList[1].Value.VoteCount.HasValue);
}
[Fact]
@@ -140,13 +140,13 @@ public class BookRatingDtoMappingTests
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.Count);
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<BookRating>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
Assert.False(resultList[0].IsError);
Assert.True(resultList[1].IsError);
Assert.False(resultList[2].IsError);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -9,6 +8,7 @@ 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;
@@ -39,11 +39,11 @@ public class BookRatingEntityMappingTests
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);
Assert.NotNull(result);
Assert.Equal(entity.Value!.Value, result.Value);
Assert.Equal(entity.MaxValue!.Value, result.MaxValue);
Assert.Equal(entity.Source, result.Source);
Assert.Equal(entity.VoteCount, result.VoteCount);
}
[Fact]
@@ -56,11 +56,11 @@ public class BookRatingEntityMappingTests
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);
Assert.NotNull(result);
Assert.Equal(0, result.Value);
Assert.Equal(0, result.MaxValue);
Assert.Equal(entity.Source, result.Source);
Assert.Equal(entity.VoteCount, result.VoteCount);
}
[Fact]
@@ -77,15 +77,15 @@ public class BookRatingEntityMappingTests
IEnumerable<BookRatingDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
results.Should().AllSatisfy(result =>
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
foreach (BookRatingDto result in results)
{
result.Should().NotBeNull();
result.Value.Should().BeInRange(1, 5);
result.MaxValue.Should().Be(5);
result.VoteCount.Should().BeInRange(1, 1000);
});
Assert.NotNull(result);
Assert.InRange(result.Value!.Value, 1, 5);
Assert.Equal(5, result.MaxValue);
Assert.InRange(result.VoteCount!.Value, 1, 1000);
}
}
[Fact]
@@ -98,12 +98,12 @@ public class BookRatingEntityMappingTests
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);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(entity.Value, result.Value.Value);
Assert.Equal(entity.MaxValue, result.Value.MaxValue);
Assert.Equal(entity.Source, result.Value.Source.Value);
Assert.Equal(entity.VoteCount, result.Value.VoteCount.Value);
}
[Fact]
@@ -116,12 +116,12 @@ public class BookRatingEntityMappingTests
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();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(default, result.Value.Value);
Assert.Equal(default, result.Value.MaxValue);
Assert.False(result.Value.Source.HasValue);
Assert.False(result.Value.VoteCount.HasValue);
}
[Fact]
@@ -138,16 +138,16 @@ public class BookRatingEntityMappingTests
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
results.Should().AllSatisfy(result =>
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
foreach (ErrorOr<BookRating> result in results)
{
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);
});
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.InRange(result.Value.Value, 1, 5);
Assert.Equal(5, result.Value.MaxValue);
Assert.True(result.Value.Source.HasValue);
Assert.InRange(result.Value.VoteCount.Value, 1, 1000);
}
}
}
@@ -1,5 +1,4 @@
#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;
@@ -38,11 +37,11 @@ public class BookRatingMappingTests
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);
Assert.NotNull(result);
Assert.Equal(bookRating.Value, result.Value);
Assert.Equal(bookRating.MaxValue, result.MaxValue);
Assert.Equal(bookRating.Source.Value, result.Source);
Assert.Equal(bookRating.VoteCount.Value, result.VoteCount);
}
[Fact]
@@ -55,11 +54,11 @@ public class BookRatingMappingTests
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);
Assert.NotNull(result);
Assert.Equal(bookRating.Value, result.Value);
Assert.Equal(bookRating.MaxValue, result.MaxValue);
Assert.Null(result.Source);
Assert.Equal(bookRating.VoteCount.Value, result.VoteCount);
}
[Fact]
@@ -72,11 +71,11 @@ public class BookRatingMappingTests
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();
Assert.NotNull(result);
Assert.Equal(bookRating.Value, result.Value);
Assert.Equal(bookRating.MaxValue, result.MaxValue);
Assert.Equal(bookRating.Source.Value, result.Source);
Assert.Null(result.VoteCount);
}
[Fact]
@@ -94,27 +93,27 @@ public class BookRatingMappingTests
IEnumerable<BookRatingEntity> results = bookRatings.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(bookRatings.Count);
Assert.NotNull(results);
Assert.Equal(bookRatings.Count, results.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);
// complete rating
Assert.Equal(bookRatings[0].Value, resultList[0].Value);
Assert.Equal(bookRatings[0].MaxValue, resultList[0].MaxValue);
Assert.Equal(bookRatings[0].Source.Value, resultList[0].Source);
Assert.Equal(bookRatings[0].VoteCount.Value, resultList[0].VoteCount);
// 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 source
Assert.Equal(bookRatings[1].Value, resultList[1].Value);
Assert.Equal(bookRatings[1].MaxValue, resultList[1].MaxValue);
Assert.Null(resultList[1].Source);
Assert.Equal(bookRatings[1].VoteCount.Value, resultList[1].VoteCount);
// 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();
// rating without vote count
Assert.Equal(bookRatings[2].Value, resultList[2].Value);
Assert.Equal(bookRatings[2].MaxValue, resultList[2].MaxValue);
Assert.Equal(bookRatings[2].Source.Value, resultList[2].Source);
Assert.Null(resultList[2].VoteCount);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -40,10 +39,10 @@ public class IsbnDtoMappingTests
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);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value, result.Value.Value);
Assert.Equal(dto.Format!.Value, result.Value.Format);
}
[Fact]
@@ -56,10 +55,10 @@ public class IsbnDtoMappingTests
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);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value, result.Value.Value);
Assert.Equal(dto.Format!.Value, result.Value.Format);
}
[Fact]
@@ -72,10 +71,10 @@ public class IsbnDtoMappingTests
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
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(dto.Value, result.Value.Value);
Assert.Equal(IsbnFormat.Isbn13, result.Value.Format); // default format
}
[Fact]
@@ -88,7 +87,7 @@ public class IsbnDtoMappingTests
ErrorOr<Isbn> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
Assert.True(result.IsError);
}
[Fact]
@@ -106,20 +105,20 @@ public class IsbnDtoMappingTests
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.Count);
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<Isbn>> resultList = results.ToList();
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
Assert.All(resultList, result => Assert.False(result.IsError));
resultList[0].Value.Value.Should().Be(dtos[0].Value);
resultList[0].Value.Format.Should().Be(dtos[0].Format!.Value);
Assert.Equal(dtos[0].Value, resultList[0].Value.Value);
Assert.Equal(dtos[0].Format!.Value, resultList[0].Value.Format);
resultList[1].Value.Value.Should().Be(dtos[1].Value);
resultList[1].Value.Format.Should().Be(dtos[1].Format!.Value);
Assert.Equal(dtos[1].Value, resultList[1].Value.Value);
Assert.Equal(dtos[1].Format!.Value, resultList[1].Value.Format);
resultList[2].Value.Value.Should().Be(dtos[2].Value);
resultList[2].Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
Assert.Equal(dtos[2].Value, resultList[2].Value.Value);
Assert.Equal(IsbnFormat.Isbn13, resultList[2].Value.Format); // default format
}
[Fact]
@@ -137,17 +136,17 @@ public class IsbnDtoMappingTests
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.Count);
Assert.NotNull(results);
Assert.Equal(dtos.Count, results.Count());
List<ErrorOr<Isbn>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Value.Should().Be(dtos[0].Value);
Assert.False(resultList[0].IsError);
Assert.Equal(dtos[0].Value, resultList[0].Value.Value);
resultList[1].IsError.Should().BeTrue();
Assert.True(resultList[1].IsError);
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Value.Should().Be(dtos[2].Value);
Assert.False(resultList[2].IsError);
Assert.Equal(dtos[2].Value, resultList[2].Value.Value);
}
}
@@ -1,6 +1,5 @@
#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;
@@ -30,9 +29,9 @@ public class IsbnEntityMappingTests
IsbnDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(entity.Value);
result.Format.Should().Be(entity.Format);
Assert.NotNull(result);
Assert.Equal(entity.Value, result.Value);
Assert.Equal(entity.Format, result.Format);
}
[Theory]
@@ -47,9 +46,9 @@ public class IsbnEntityMappingTests
IsbnDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(value);
result.Format.Should().Be(format);
Assert.NotNull(result);
Assert.Equal(value, result.Value);
Assert.Equal(format, result.Format);
}
[Theory]
@@ -65,8 +64,8 @@ public class IsbnEntityMappingTests
IsbnDto result = entity.ToResponse();
// Assert
result.Value.Should().Be(value);
result.Format.Should().Be(format);
Assert.Equal(value, result.Value);
Assert.Equal(format, result.Format);
}
[Fact]
@@ -79,10 +78,10 @@ public class IsbnEntityMappingTests
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);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(entity.Value, result.Value.Value);
Assert.Equal(entity.Format, result.Value.Format);
}
[Theory]
@@ -98,7 +97,7 @@ public class IsbnEntityMappingTests
ErrorOr<Isbn> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
Assert.True(result.IsError);
}
[Fact]
@@ -115,15 +114,15 @@ public class IsbnEntityMappingTests
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.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);
Assert.False(resultList[i].IsError);
Assert.Equal(entities[i].Value, resultList[i].Value.Value);
Assert.Equal(entities[i].Format, resultList[i].Value.Format);
}
}
@@ -141,14 +140,14 @@ public class IsbnEntityMappingTests
IEnumerable<IsbnDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.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);
Assert.Equal(entities[i].Value, resultList[i].Value);
Assert.Equal(entities[i].Format, resultList[i].Format);
}
}
}
@@ -1,5 +1,4 @@
#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;
@@ -39,9 +38,9 @@ public class IsbnMappingTests
IsbnEntity result = isbn.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(isbn.Value);
result.Format.Should().Be(IsbnFormat.Isbn10);
Assert.NotNull(result);
Assert.Equal(isbn.Value, result.Value);
Assert.Equal(IsbnFormat.Isbn10, result.Format);
}
[Fact]
@@ -54,9 +53,9 @@ public class IsbnMappingTests
IsbnEntity result = isbn.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(isbn.Value);
result.Format.Should().Be(IsbnFormat.Isbn13);
Assert.NotNull(result);
Assert.Equal(isbn.Value, result.Value);
Assert.Equal(IsbnFormat.Isbn13, result.Format);
}
[Fact]
@@ -74,14 +73,14 @@ public class IsbnMappingTests
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(isbns.Count);
Assert.NotNull(results);
Assert.Equal(isbns.Count, results.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);
Assert.Equal(isbns[i].Value, resultList[i].Value);
Assert.Equal(isbns[i].Format, resultList[i].Format);
}
}
@@ -95,7 +94,7 @@ public class IsbnMappingTests
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().BeEmpty();
Assert.NotNull(results);
Assert.Empty(results);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -9,6 +8,7 @@ using Lumina.Contracts.Responses.UsersManagement.Users;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
@@ -29,11 +29,11 @@ public class UserEntityMappingTests
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.Username.Should().Be(entity.Username);
result.CreatedOnUtc.Should().Be(entity.CreatedOnUtc);
result.UpdatedOnUtc.Should().Be(entity.UpdatedOnUtc);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.Username, result.Username);
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
}
[Theory]
@@ -51,8 +51,8 @@ public class UserEntityMappingTests
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
}
[Fact]
@@ -66,8 +66,8 @@ public class UserEntityMappingTests
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UpdatedOnUtc.Should().Be(entity.UpdatedOnUtc);
Assert.NotNull(result);
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
}
[Fact]
@@ -80,11 +80,11 @@ public class UserEntityMappingTests
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.Username.Should().Be(entity.Username);
result.CreatedOnUtc.Should().Be(entity.CreatedOnUtc);
result.UpdatedOnUtc.Should().Be(entity.UpdatedOnUtc);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.Username, result.Username);
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
}
[Fact]
@@ -97,11 +97,16 @@ public class UserEntityMappingTests
IEnumerable<UserResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(3);
results.Should().BeEquivalentTo(entities, options => options
.Including(x => x.Id)
.Including(x => x.Username));
Assert.NotNull(results);
Assert.Equal(3, results.Count());
List<UserResponse> resultsList = [..results];
List<UserEntity> entitiesList = [.. entities];
for (int i = 0; i < resultsList.Count; i++)
{
Assert.Equal(entitiesList[i].Id, resultsList[i].Id);
Assert.Equal(entitiesList[i].Username, resultsList[i].Username);
}
}
[Fact]
@@ -114,8 +119,8 @@ public class UserEntityMappingTests
IEnumerable<UserResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().BeEmpty();
Assert.NotNull(results);
Assert.Empty(results);
}
[Fact]
@@ -129,7 +134,7 @@ public class UserEntityMappingTests
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UpdatedOnUtc.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.UpdatedOnUtc);
}
}
@@ -1,5 +1,4 @@
#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;
@@ -48,21 +47,21 @@ public class UserMappingTests
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
Assert.NotNull(result);
Assert.Same(repositoryEntity, result); // should modify the same instance
Assert.Equal(domainEntity.Username, result.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.Libraries.Should().BeSameAs(repositoryEntity.Libraries);
result.UserPermissions.Should().BeSameAs(repositoryEntity.UserPermissions);
result.UserRole.Should().BeSameAs(repositoryEntity.UserRole);
result.CreatedOnUtc.Should().Be(repositoryEntity.CreatedOnUtc);
result.CreatedBy.Should().Be(repositoryEntity.CreatedBy);
result.UpdatedOnUtc.Should().Be(repositoryEntity.UpdatedOnUtc);
result.UpdatedBy.Should().Be(repositoryEntity.UpdatedBy);
// verify other properties remain unchanged
Assert.Equal(repositoryEntity.Id, result.Id);
Assert.Equal(repositoryEntity.Password, result.Password);
Assert.Equal(repositoryEntity.TotpSecret, result.TotpSecret);
Assert.Same(repositoryEntity.Libraries, result.Libraries);
Assert.Same(repositoryEntity.UserPermissions, result.UserPermissions);
Assert.Same(repositoryEntity.UserRole, result.UserRole);
Assert.Equal(repositoryEntity.CreatedOnUtc, result.CreatedOnUtc);
Assert.Equal(repositoryEntity.CreatedBy, result.CreatedBy);
Assert.Equal(repositoryEntity.UpdatedOnUtc, result.UpdatedOnUtc);
Assert.Equal(repositoryEntity.UpdatedBy, result.UpdatedBy);
}
[Theory]
@@ -95,8 +94,8 @@ public class UserMappingTests
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(newUsername);
Assert.NotNull(result);
Assert.Equal(newUsername, result.Username);
}
[Fact]
@@ -153,8 +152,8 @@ public class UserMappingTests
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
// Assert
result.Should().NotBeNull();
result.Libraries.Should().BeSameAs(libraries);
result.Libraries.Should().HaveCount(2);
Assert.NotNull(result);
Assert.Same(libraries, result.Libraries);
Assert.Equal(2, result.Libraries.Count);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -14,6 +13,7 @@ using NSubstitute;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -73,8 +73,8 @@ public class GetPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().HaveCount(2);
Assert.False(result.IsError);
Assert.Equal(2, result.Value.Count());
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -92,8 +92,8 @@ public class GetPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -114,8 +114,8 @@ public class GetPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -140,8 +140,8 @@ public class GetPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, cancellationToken);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().HaveCount(1);
Assert.False(result.IsError);
Assert.Single(result.Value);
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -68,8 +67,8 @@ public class AddRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().InsertAsync(Arg.Any<RoleEntity>(), Arg.Any<CancellationToken>());
}
@@ -89,8 +88,8 @@ public class AddRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -112,8 +111,8 @@ public class AddRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -133,8 +132,8 @@ public class AddRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Persistence.ErrorPersistingAuthorizationRole);
Assert.True(result.IsError);
Assert.Equal(Errors.Persistence.ErrorPersistingAuthorizationRole, result.FirstError);
}
[Fact]
@@ -171,9 +170,9 @@ public class AddRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Role.RoleName.Should().Be(command.RoleName);
result.Value.Permissions.Should().HaveCount(command.Permissions.Count);
Assert.False(result.IsError);
Assert.Equal(command.RoleName, result.Value.Role.RoleName);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Length);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -65,8 +64,8 @@ public class DeleteRoleCommandHandlerTests
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -85,8 +84,8 @@ public class DeleteRoleCommandHandlerTests
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -106,8 +105,8 @@ public class DeleteRoleCommandHandlerTests
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.AdminRoleCannotBeDeleted);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.AdminRoleCannotBeDeleted, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -127,8 +126,8 @@ public class DeleteRoleCommandHandlerTests
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockRoleRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -151,8 +150,8 @@ public class DeleteRoleCommandHandlerTests
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -174,7 +173,7 @@ public class DeleteRoleCommandHandlerTests
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
Assert.False(result.IsError);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -68,8 +67,8 @@ public class UpdateRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().UpdateAsync(Arg.Any<RoleEntity>(), Arg.Any<CancellationToken>());
}
@@ -89,8 +88,8 @@ public class UpdateRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -112,8 +111,8 @@ public class UpdateRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -133,8 +132,8 @@ public class UpdateRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Persistence.ErrorPersistingAuthorizationRole);
Assert.True(result.IsError);
Assert.Equal(Errors.Persistence.ErrorPersistingAuthorizationRole, result.FirstError);
}
[Fact]
@@ -170,9 +169,9 @@ public class UpdateRoleCommandHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Role.RoleName.Should().Be(command.RoleName);
result.Value.Permissions.Should().HaveCount(command.Permissions.Count);
Assert.False(result.IsError);
Assert.Equal(command.RoleName, result.Value.Role.RoleName);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Length);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -67,8 +66,8 @@ public class GetRolePermissionsQueryHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -88,8 +87,8 @@ public class GetRolePermissionsQueryHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -107,8 +106,8 @@ public class GetRolePermissionsQueryHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
[Fact]
@@ -145,8 +144,8 @@ public class GetRolePermissionsQueryHandlerTests
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Role.RoleName.Should().Be(role.RoleName);
result.Value.Permissions.Should().HaveCount(1);
Assert.False(result.IsError);
Assert.Equal(role.RoleName, result.Value.Role.RoleName);
Assert.Single(result.Value.Permissions);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
using Lumina.Application.Common.DataAccess.UoW;
@@ -14,6 +13,7 @@ using NSubstitute;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -66,8 +66,8 @@ public class GetRolesQueryHandlerTests
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockRoleRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -87,8 +87,8 @@ public class GetRolesQueryHandlerTests
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -111,7 +111,7 @@ public class GetRolesQueryHandlerTests
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().HaveCount(2);
Assert.False(result.IsError);
Assert.Equal(2, result.Value.Count());
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
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;
@@ -57,20 +56,20 @@ public class GetDirectoriesQueryHandlerTests
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<DirectoryResponse>>();
result.Value.Should().HaveCount(directories.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<DirectoryResponse>>(result.Value);
Assert.Equal(directories.Count(), result.Value.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
Assert.Equal(directoriesList[i].Id.Path, resultList[i].Path);
Assert.Equal(directoriesList[i].Name, resultList[i].Name);
Assert.Equal(directoriesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(directoriesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Empty(resultList[i].Items); // since files are not included
}
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements);
@@ -91,20 +90,20 @@ public class GetDirectoriesQueryHandlerTests
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<DirectoryResponse>>();
result.Value.Should().HaveCount(directories.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<DirectoryResponse>>(result.Value);
Assert.Equal(directories.Count(), result.Value.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);
Assert.Equal(directoriesList[i].Id.Path, resultList[i].Path);
Assert.Equal(directoriesList[i].Name, resultList[i].Name);
Assert.Equal(directoriesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(directoriesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(directoriesList[i].Items.Count, resultList[i].Items.Count);
}
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.IncludeHiddenElements);
@@ -123,8 +122,8 @@ public class GetDirectoriesQueryHandlerTests
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
}
@@ -141,8 +140,8 @@ public class GetDirectoriesQueryHandlerTests
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.Empty(result.Value);
_mockDirectoryService.Received(1).GetSubdirectories(query.Path!, query.IncludeHiddenElements);
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
@@ -58,9 +57,9 @@ public class GetDrivesQueryHandlerTests
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDrivesQuery, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
result.Value.Should().HaveCount(drives.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
Assert.Equal(drives.Count(), result.Value.Count());
List<FileSystemTreeNodeResponse> resultList = result.Value.ToList();
List<FileSystemItem> drivesList = drives.ToList();
@@ -70,12 +69,12 @@ public class GetDrivesQueryHandlerTests
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();
Assert.Equal(drive.Id.Path, response.Path);
Assert.Equal(drive.Name, response.Name);
Assert.Equal(FileSystemItemType.Root, response.ItemType);
Assert.False(response.IsExpanded);
Assert.False(response.ChildrenLoaded);
Assert.Empty(response.Children);
}
_mockDriveService.Received(1).GetDrives();
@@ -94,8 +93,8 @@ public class GetDrivesQueryHandlerTests
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockDriveService.Received(1).GetDrives();
}
@@ -112,8 +111,8 @@ public class GetDrivesQueryHandlerTests
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.Empty(result.Value);
_mockDriveService.Received(1).GetDrives();
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
@@ -51,8 +50,8 @@ public class GetFileSystemQueryHandlerTests
FileSystemTypeResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.Should().NotBeNull();
result.PlatformType.Should().Be(platformType);
Assert.NotNull(result);
Assert.Equal(platformType, result.PlatformType);
_mockPlatformContextManager.Received(1).GetCurrentContext();
}
@@ -67,10 +66,10 @@ public class GetFileSystemQueryHandlerTests
ValueTask<FileSystemTypeResponse> resultTask = _sut.Handle(query, CancellationToken.None);
// Assert
resultTask.IsCompleted.Should().BeTrue();
Assert.True(resultTask.IsCompleted);
FileSystemTypeResponse result = await resultTask;
result.Should().NotBeNull();
result.PlatformType.Should().Be(PlatformType.Unix);
Assert.NotNull(result);
Assert.Equal(PlatformType.Unix, result.PlatformType);
}
[Fact]
@@ -86,7 +85,7 @@ public class GetFileSystemQueryHandlerTests
FileSystemTypeResponse result2 = await _sut.Handle(query2, CancellationToken.None);
// Assert
result1.Should().BeEquivalentTo(result2);
Assert.Equal(result1.PlatformType, result2.PlatformType);
_mockPlatformContextManager.Received(1).GetCurrentContext();
}
@@ -98,11 +97,10 @@ public class GetFileSystemQueryHandlerTests
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
CancellationToken cancellationToken = new(true);
// Act
Func<Task> act = async () => await _sut.Handle(query, cancellationToken);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _sut.Handle(query, cancellationToken));
Assert.Null(exception);
_mockPlatformContextManager.Received(1).GetCurrentContext();
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
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;
@@ -57,20 +56,20 @@ public class GetFilesQueryHandlerTests
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<FileResponse>>();
result.Value.Should().HaveCount(files.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<FileResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.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);
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
Assert.Equal(filesList[i].Name, resultList[i].Name);
Assert.Equal(filesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(filesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(filesList[i].Size, resultList[i].Size);
}
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
@@ -91,20 +90,20 @@ public class GetFilesQueryHandlerTests
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<FileResponse>>();
result.Value.Should().HaveCount(files.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<FileResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.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);
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
Assert.Equal(filesList[i].Name, resultList[i].Name);
Assert.Equal(filesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(filesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(filesList[i].Size, resultList[i].Size);
}
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
@@ -123,8 +122,8 @@ public class GetFilesQueryHandlerTests
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
@@ -141,8 +140,8 @@ public class GetFilesQueryHandlerTests
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.Empty(result.Value);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
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;
@@ -57,21 +56,21 @@ public class GetTreeFilesQueryHandlerTests
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
result.Value.Should().HaveCount(files.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.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();
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
Assert.Equal(filesList[i].Name, resultList[i].Name);
Assert.Equal(FileSystemItemType.File, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
}
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
@@ -92,21 +91,21 @@ public class GetTreeFilesQueryHandlerTests
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<FileSystemTreeNodeResponse>>();
result.Value.Should().HaveCount(files.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<FileSystemTreeNodeResponse>>(result.Value);
Assert.Equal(files.Count(), result.Value.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();
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
Assert.Equal(filesList[i].Name, resultList[i].Name);
Assert.Equal(FileSystemItemType.File, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
}
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.IncludeHiddenElements);
@@ -125,8 +124,8 @@ public class GetTreeFilesQueryHandlerTests
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
@@ -143,8 +142,8 @@ public class GetTreeFilesQueryHandlerTests
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.Empty(result.Value);
_mockFileService.Received(1).GetFiles(query.Path!, query.IncludeHiddenElements);
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
@@ -49,9 +48,9 @@ public class CombinePathCommandHandlerTests
ErrorOr<PathSegmentResponse> result = await _sut.Handle(combinePathCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeOfType<PathSegmentResponse>();
result.Value.Path.Should().Be(combinedPath);
Assert.False(result.IsError);
Assert.IsType<PathSegmentResponse>(result.Value);
Assert.Equal(combinedPath, result.Value.Path);
_mockPathService.Received(1).CombinePath(combinePathCommand.OriginalPath!, combinePathCommand.NewPath!);
}
@@ -68,8 +67,8 @@ public class CombinePathCommandHandlerTests
ErrorOr<PathSegmentResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
}
@@ -85,9 +84,9 @@ public class CombinePathCommandHandlerTests
ErrorOr<PathSegmentResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeOfType<PathSegmentResponse>();
result.Value.Path.Should().BeEmpty();
Assert.False(result.IsError);
Assert.IsType<PathSegmentResponse>(result.Value);
Assert.Empty(result.Value.Path);
_mockPathService.Received(1).CombinePath(command.OriginalPath!, command.NewPath!);
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
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;
@@ -57,15 +56,15 @@ public class SplitPathCommandHandlerTests
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(splitPathCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<PathSegmentResponse>>();
result.Value.Should().HaveCount(pathSegments.Count());
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<PathSegmentResponse>>(result.Value);
Assert.Equal(pathSegments.Count(), result.Value.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);
Assert.Equal(segmentsList[i].Name, resultList[i].Path);
_mockPathService.Received(1).ParsePath(splitPathCommand.Path!);
}
@@ -82,8 +81,8 @@ public class SplitPathCommandHandlerTests
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).ParsePath(command.Path!);
}
@@ -100,8 +99,8 @@ public class SplitPathCommandHandlerTests
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.Empty(result.Value);
_mockPathService.Received(1).ParsePath(command.Path!);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
@@ -42,8 +41,8 @@ public class CheckPathExistsQueryHandlerTests
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Exists.Should().BeTrue();
Assert.False(result.IsError);
Assert.True(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
@@ -58,8 +57,8 @@ public class CheckPathExistsQueryHandlerTests
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Exists.Should().BeTrue();
Assert.False(result.IsError);
Assert.True(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
@@ -74,8 +73,8 @@ public class CheckPathExistsQueryHandlerTests
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Exists.Should().BeFalse();
Assert.False(result.IsError);
Assert.False(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!, false);
}
@@ -90,8 +89,8 @@ public class CheckPathExistsQueryHandlerTests
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Exists.Should().BeFalse();
Assert.False(result.IsError);
Assert.False(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
@@ -106,8 +105,8 @@ public class CheckPathExistsQueryHandlerTests
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Exists.Should().BeFalse();
Assert.False(result.IsError);
Assert.False(result.Value.Exists);
_mockPathService.Received(1).Exists(Arg.Any<string>(), Arg.Any<bool>());
}
@@ -123,8 +122,8 @@ public class CheckPathExistsQueryHandlerTests
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Exists.Should().BeTrue();
Assert.False(result.IsError);
Assert.True(result.Value.Exists);
_mockPathService.Received(1).Exists(query.Path!);
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
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;
@@ -56,9 +55,9 @@ public class GetPathParentQueryHandlerTests
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeAssignableTo<IEnumerable<PathSegmentResponse>>();
result.Value.Should().BeEquivalentTo(pathSegmentResponses);
Assert.False(result.IsError);
Assert.IsAssignableFrom<IEnumerable<PathSegmentResponse>>(result.Value);
Assert.Equal(pathSegmentResponses, result.Value);
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
}
@@ -75,8 +74,8 @@ public class GetPathParentQueryHandlerTests
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
}
@@ -93,8 +92,8 @@ public class GetPathParentQueryHandlerTests
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.Empty(result.Value);
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
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;
@@ -49,9 +48,9 @@ public class GetPathRootQueryHandlerTests
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Path.Should().Be(pathSegment.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(pathSegment.Name, result.Value.Path);
_mockPathService.Received(1).GetPathRoot(query.Path!);
}
@@ -68,8 +67,8 @@ public class GetPathRootQueryHandlerTests
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
_mockPathService.Received(1).GetPathRoot(query.Path!);
}
@@ -87,9 +86,9 @@ public class GetPathRootQueryHandlerTests
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Path.Should().Be("/");
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal("/", result.Value.Path);
_mockPathService.Received(1).GetPathRoot(query.Path!);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
@@ -42,8 +41,8 @@ public class GetPathSeparatorQueryHandlerTests
PathSeparatorResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.Should().NotBeNull();
result.Separator.Should().Be(expectedSeparator.ToString());
Assert.NotNull(result);
Assert.Equal(expectedSeparator.ToString(), result.Separator);
_mockPathService.Received(1);
}
@@ -61,8 +60,8 @@ public class GetPathSeparatorQueryHandlerTests
PathSeparatorResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.Should().NotBeNull();
result.Separator.Should().Be(separator.ToString());
Assert.NotNull(result);
Assert.Equal(separator.ToString(), result.Separator);
_mockPathService.Received(1);
}
@@ -79,7 +78,7 @@ public class GetPathSeparatorQueryHandlerTests
PathSeparatorResponse result2 = await _sut.Handle(query, CancellationToken.None);
// Assert
result1.Should().BeEquivalentTo(result2);
Assert.Equal(result1, result2);
_mockPathService.Received(2);
}
@@ -91,9 +90,11 @@ public class GetPathSeparatorQueryHandlerTests
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () => await _sut.Handle(query, cts.Token);
Exception? exception = await Record.ExceptionAsync(
async () => await _sut.Handle(query, cts.Token)
);
// Assert
await act.Should().NotThrowAsync();
Assert.Null(exception);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
@@ -41,7 +40,7 @@ public class ValidatePathQueryHandlerTests
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsValid.Should().BeTrue();
Assert.True(result.IsValid);
_mockPathService.Received(1).IsValidPath(query.Path!);
}
@@ -56,7 +55,7 @@ public class ValidatePathQueryHandlerTests
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsValid.Should().BeFalse();
Assert.False(result.IsValid);
_mockPathService.Received(1).IsValidPath(query.Path!);
}
@@ -71,7 +70,7 @@ public class ValidatePathQueryHandlerTests
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsValid.Should().BeFalse();
Assert.False(result.IsValid);
_mockPathService.Received(1).IsValidPath(Arg.Any<string>());
}
@@ -86,7 +85,7 @@ public class ValidatePathQueryHandlerTests
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsValid.Should().BeFalse();
Assert.False(result.IsValid);
_mockPathService.Received(1).IsValidPath(Arg.Any<string>());
}
}
@@ -2,9 +2,7 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Thumbnails.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
@@ -47,10 +45,10 @@ public class GetThumbnailQueryHandlerTests
ErrorOr<ThumbnailResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Type.Should().Be(thumbnail.Type);
result.Value.Bytes.Should().BeEquivalentTo(thumbnail.Bytes);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(thumbnail.Type, result.Value.Type);
Assert.Equal(thumbnail.Bytes, result.Value.Bytes);
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>());
}
@@ -67,8 +65,8 @@ public class GetThumbnailQueryHandlerTests
ErrorOr<ThumbnailResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, Arg.Any<CancellationToken>());
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.Seed;
@@ -86,10 +85,10 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Username.Should().Be(command.Username);
result.Value.TotpSecret.Should().BeNull();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(command.Username, result.Value.Username);
Assert.Null(result.Value.TotpSecret);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -123,10 +122,10 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Username.Should().Be(command.Username);
result.Value.TotpSecret.Should().Be(qrCodeUri);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(command.Username, result.Value.Username);
Assert.Equal(qrCodeUri, result.Value.TotpSecret);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -147,8 +146,8 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.AdminAccountAlreadyCreated);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.AdminAccountAlreadyCreated, result.FirstError);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -169,8 +168,8 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -193,8 +192,8 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -219,8 +218,8 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockDataSeedService.DidNotReceive().SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -246,8 +245,8 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -276,8 +275,8 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -309,8 +308,8 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -341,9 +340,9 @@ public class SetupApplicationCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Username.Should().Be(command.Username);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(command.Username, result.Value.Username);
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
@@ -1,8 +1,5 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -54,7 +51,7 @@ public class CheckInitializationQueryHandlerTests
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
// Assert
result.IsInitialized.Should().BeTrue();
Assert.True(result.IsInitialized);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -69,7 +66,7 @@ public class CheckInitializationQueryHandlerTests
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
// Assert
result.IsInitialized.Should().BeFalse();
Assert.False(result.IsInitialized);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -85,7 +82,7 @@ public class CheckInitializationQueryHandlerTests
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
// Assert
result.IsInitialized.Should().BeFalse();
Assert.False(result.IsInitialized);
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
}
}
@@ -2,7 +2,6 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
@@ -66,8 +65,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeOfType<BookResponse>();
Assert.False(result.IsError);
Assert.IsType<BookResponse>(result.Value);
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -83,8 +82,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.TitleCannotBeEmpty.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.TitleCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -102,8 +101,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(Errors.WrittenContent.BookAlreadyExists);
Assert.True(result.IsError);
Assert.Contains(Errors.WrittenContent.BookAlreadyExists, result.Errors);
await _mockBookRepository.Received(1).InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -119,8 +118,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.WrittenContent.InvalidIsbn13Format.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.WrittenContent.InvalidIsbn13Format.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -136,8 +135,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.RatingValueMustBePositive.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.RatingValueMustBePositive.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -159,8 +158,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.GenreNameCannotBeEmpty.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.GenreNameCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -182,8 +181,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.TagNameCannotBeEmpty.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.TagNameCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -212,8 +211,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -235,8 +234,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -258,8 +257,8 @@ public class AddBookCommandHandlerTests
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().Contain(e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
Assert.True(result.IsError);
Assert.Contains(result.Errors, e => e.Description == Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>());
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -76,8 +75,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.IsPasswordChanged.Should().BeTrue();
Assert.False(result.IsError);
Assert.True(result.Value.IsPasswordChanged);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockHashService.Received(1).CheckStringAgainstHash(currentPassword, "hashedCurrentPassword");
@@ -99,8 +98,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -129,8 +128,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidCurrentPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidCurrentPassword, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockHashService.Received(1).CheckStringAgainstHash(incorrectPassword, Uri.UnescapeDataString(user.Password));
@@ -167,8 +166,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockHashService.Received(1).CheckStringAgainstHash(currentPassword, "hashedCurrentPassword");
@@ -197,8 +196,8 @@ public class ChangePasswordCommandHandlerTests
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -82,8 +81,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.IsPasswordReset.Should().BeTrue();
Assert.False(result.IsError);
Assert.True(result.Value.IsPasswordReset);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.Received(1).ValidateToken(Arg.Any<byte[]>(), totpCode);
@@ -105,8 +104,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -130,8 +129,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.PasswordResetAlreadyRequested);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.PasswordResetAlreadyRequested, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -154,8 +153,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -186,8 +185,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.Received(1).ValidateToken(Arg.Any<byte[]>(), totpCode);
@@ -222,8 +221,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.Received(1).ValidateToken(Arg.Any<byte[]>(), totpCode);
@@ -251,8 +250,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -277,8 +276,8 @@ public class RecoverPasswordCommandHandlerTests
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(user.Username, Arg.Any<CancellationToken>());
_mockTotpTokenGenerator.DidNotReceive().ValidateToken(Arg.Any<byte[]>(), Arg.Any<string>());
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -88,9 +87,9 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Username.Should().Be(command.Username);
result.Value.TotpSecret.Should().Be(qrCodeUri);
Assert.False(result.IsError);
Assert.Equal(command.Username, result.Value.Username);
Assert.Equal(qrCodeUri, result.Value.TotpSecret);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
_mockHashService.Received(1).HashString(command.Password!);
@@ -119,9 +118,9 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Username.Should().Be(command.Username);
result.Value.TotpSecret.Should().BeNull();
Assert.False(result.IsError);
Assert.Equal(command.Username, result.Value.Username);
Assert.Null(result.Value.TotpSecret);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
_mockHashService.Received(1).HashString(command.Password!);
@@ -146,8 +145,8 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameAlreadyExists);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameAlreadyExists, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -170,8 +169,8 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -192,8 +191,8 @@ public class RegisterUserCommandHandlerTests
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByUsernameAsync(command.Username!, Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -15,6 +14,7 @@ using NSubstitute;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -68,8 +68,8 @@ public class GetUsersQueryHandlerTests
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
}
@@ -89,8 +89,8 @@ public class GetUsersQueryHandlerTests
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -110,7 +110,7 @@ public class GetUsersQueryHandlerTests
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().HaveCount(2);
Assert.False(result.IsError);
Assert.Equal(2, result.Value.Count());
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -85,11 +84,11 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Id.Should().Be(user.Id);
result.Value.Username.Should().Be(user.Username);
result.Value.Token.Should().Be(jwtToken);
result.Value.UsesTotp.Should().BeFalse();
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
Assert.False(result.Value.UsesTotp);
}
[Fact]
@@ -124,11 +123,11 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Id.Should().Be(user.Id);
result.Value.Username.Should().Be(user.Username);
result.Value.Token.Should().Be(jwtToken);
result.Value.UsesTotp.Should().BeTrue();
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
Assert.True(result.Value.UsesTotp);
}
[Fact]
@@ -144,8 +143,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidUsernameOrPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
[Fact]
@@ -170,8 +169,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidUsernameOrPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
}
[Fact]
@@ -200,8 +199,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.TempPasswordExpired);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.TempPasswordExpired, result.FirstError);
await _mockUserRepository.Received(1).UpdateAsync(Arg.Is<UserEntity>(u =>
u.TempPassword == null && u.TempPasswordCreated == null),
@@ -240,11 +239,11 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Id.Should().Be(user.Id);
result.Value.Username.Should().Be(user.Username);
result.Value.Token.Should().Be(jwtToken);
result.Value.UsesTotp.Should().BeFalse();
Assert.False(result.IsError);
Assert.Equal(user.Id, result.Value.Id);
Assert.Equal(user.Username, result.Value.Username);
Assert.Equal(jwtToken, result.Value.Token);
Assert.False(result.Value.UsesTotp);
}
[Fact]
@@ -270,8 +269,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
[Fact]
@@ -303,8 +302,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidTotpCode);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidTotpCode, result.FirstError);
}
[Fact]
@@ -321,8 +320,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -351,8 +350,8 @@ public class LoginUserQueryHandlerTests
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.InvalidUsernameOrPassword);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.InvalidUsernameOrPassword, result.FirstError);
_mockHashService.Received(1).CheckStringAgainstHash(password, hashedPassword);
_mockHashService.Received(1).CheckStringAgainstHash(password, hashedTempPassword);
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -79,8 +78,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(ApplicationErrors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().UpdateAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
}
@@ -98,8 +97,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(DomainErrors.Users.UserDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(DomainErrors.Users.UserDoesNotExist, result.FirstError);
}
[Fact]
@@ -120,8 +119,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(ApplicationErrors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(ApplicationErrors.Authorization.RoleNotFound, result.FirstError);
}
[Fact]
@@ -166,8 +165,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(ApplicationErrors.Authorization.CannotRemoveLastAdmin);
Assert.True(result.IsError);
Assert.Equal(ApplicationErrors.Authorization.CannotRemoveLastAdmin, result.FirstError);
}
[Fact]
@@ -196,8 +195,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -246,10 +245,10 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(command.UserId);
result.Value.Role.Should().Be(role.RoleName);
result.Value.Permissions.Should().HaveCount(command.Permissions.Count);
Assert.False(result.IsError);
Assert.Equal(command.UserId, result.Value.UserId);
Assert.Equal(role.RoleName, result.Value.Role);
Assert.Equal(command.Permissions.Count, result.Value.Permissions.Count);
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -290,8 +289,8 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -325,7 +324,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
@@ -53,10 +52,10 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(userId);
result.Value.Role.Should().BeEquivalentTo(authEntity.Role);
result.Value.Permissions.Should().BeEquivalentTo(authEntity.Permissions);
Assert.False(result.IsError);
Assert.Equal(userId, result.Value.UserId);
Assert.Equal(authEntity.Role, result.Value.Role);
Assert.Equal(authEntity.Permissions, result.Value.Permissions);
}
[Fact]
@@ -79,10 +78,10 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.UserId.Should().Be(targetUserId);
result.Value.Role.Should().BeEquivalentTo(targetAuthEntity.Role);
result.Value.Permissions.Should().BeEquivalentTo(targetAuthEntity.Permissions);
Assert.False(result.IsError);
Assert.Equal(targetUserId, result.Value.UserId);
Assert.Equal(targetAuthEntity.Role, result.Value.Role);
Assert.Equal(targetAuthEntity.Permissions, result.Value.Permissions);
}
[Fact]
@@ -102,8 +101,8 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
}
[Fact]
@@ -123,8 +122,8 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -147,7 +146,7 @@ public class GetAuthorizationQueryHandlerTests
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
}
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -70,8 +68,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -91,8 +89,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -110,8 +108,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
[Fact]
@@ -149,8 +147,8 @@ public class GetUserPermissionsQueryHandlerTests
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().HaveCount(1);
result.Value.First().PermissionName.Should().Be(AuthorizationPermission.CanViewUsers);
Assert.False(result.IsError);
Assert.Single(result.Value);
Assert.Equal(AuthorizationPermission.CanViewUsers, result.Value.First().PermissionName);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
@@ -67,8 +66,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.NotAuthorized);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
}
@@ -88,8 +87,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(error);
Assert.True(result.IsError);
Assert.Equal(error, result.FirstError);
}
[Fact]
@@ -107,8 +106,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authentication.UsernameDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Authentication.UsernameDoesNotExist, result.FirstError);
}
[Fact]
@@ -127,8 +126,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -163,8 +162,8 @@ public class GetUserRoleQueryHandlerTests
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value!.RoleName.Should().Be("TestRole");
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Contains("TestRole", result.Value!.RoleName);
}
}
@@ -24,7 +24,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Authentication;
@@ -35,10 +34,10 @@ public class DataAccessLayerServicesTests
DataAccessLayerServices.AddDataAccessLayerServices(services);
// Assert
services.Should().Contain(sd => sd.ServiceType == typeof(LuminaDbContext));
services.Should().Contain(sd => sd.ServiceType == typeof(IUnitOfWork) && sd.ImplementationType == typeof(UnitOfWork));
services.Should().Contain(sd => sd.ServiceType == typeof(IRepositoryFactory) && sd.ImplementationType == typeof(RepositoryFactory));
services.Should().Contain(sd => sd.ServiceType == typeof(IBookRepository) && sd.ImplementationType == typeof(BookRepository));
Assert.Contains(services, sd => sd.ServiceType == typeof(LuminaDbContext));
Assert.Contains(services, sd => sd.ServiceType == typeof(IUnitOfWork) && sd.ImplementationType == typeof(UnitOfWork));
Assert.Contains(services, sd => sd.ServiceType == typeof(IRepositoryFactory) && sd.ImplementationType == typeof(RepositoryFactory));
Assert.Contains(services, sd => sd.ServiceType == typeof(IBookRepository) && sd.ImplementationType == typeof(BookRepository));
}
[Fact]
@@ -54,12 +53,12 @@ public class DataAccessLayerServicesTests
// Assert
ServiceDescriptor? descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<LuminaDbContext>));
descriptor.Should().NotBeNull();
Assert.NotNull(descriptor);
ServiceProvider serviceProvider = services.BuildServiceProvider();
LuminaDbContext? context = serviceProvider.GetService<LuminaDbContext>();
context.Should().NotBeNull();
context!.Database.GetDbConnection().ConnectionString.Should().Contain("Lumina.db");
Assert.NotNull(context);
Assert.Contains("Lumina.db", context.Database.GetDbConnection().ConnectionString);
}
[Fact]
@@ -78,6 +77,6 @@ public class DataAccessLayerServicesTests
// Assert
IBookRepository? repository = serviceProvider.GetService<IBookRepository>();
repository.Should().NotBeNull();
Assert.NotNull(repository);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
@@ -49,13 +48,13 @@ public class PermissionRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// Check if the permission was added to the context's ChangeTracker
// check if the permission was added to the context's ChangeTracker
EntityEntry<PermissionEntity>? addedPermission = _mockContext.ChangeTracker.Entries<PermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == permissionModel.Id);
addedPermission.Should().NotBeNull();
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == permissionModel.Id);
Assert.NotNull(addedPermission);
}
[Fact]
@@ -71,9 +70,9 @@ public class PermissionRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.PermissionAlreadyExists);
_mockContext.ChangeTracker.Entries<PermissionEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.PermissionAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<PermissionEntity>());
}
[Fact]
@@ -93,10 +92,10 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(3);
result.Value.Should().BeEquivalentTo(permissions);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(permissions, result.Value);
}
[Fact]
@@ -106,9 +105,9 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -130,10 +129,10 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(2);
result.Value.Select(p => p.Id).Should().BeEquivalentTo(requestedIds);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(2, result.Value.Count());
Assert.Equal(requestedIds, result.Value.Select(p => p.Id).ToList());
}
[Fact]
@@ -146,8 +145,8 @@ public class PermissionRepositoryTests
ErrorOr<IEnumerable<PermissionEntity>> result = await _sut.GetByIdsAsync(requestedIds, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.DataAccess.Core.Repositories.Authorization;
using Lumina.DataAccess.Core.UoW;
@@ -46,12 +45,12 @@ public class RolePermissionRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(rolePermissionModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// check if the role permission was added to the context's ChangeTracker
EntityEntry<RolePermissionEntity>? addedRolePermission = _mockContext.ChangeTracker.Entries<RolePermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == rolePermissionModel.Id);
addedRolePermission.Should().NotBeNull();
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == rolePermissionModel.Id);
Assert.NotNull(addedRolePermission);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
@@ -54,13 +53,13 @@ public class RoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// Check if the role was added to the context's ChangeTracker
EntityEntry<RoleEntity>? addedRole = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == role.Id);
addedRole.Should().NotBeNull();
Assert.NotNull(addedRole);
}
[Fact]
@@ -90,9 +89,9 @@ public class RoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleAlreadyExists);
_mockContext.ChangeTracker.Entries<RoleEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
}
[Fact]
@@ -122,9 +121,9 @@ public class RoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleAlreadyExists);
_mockContext.ChangeTracker.Entries<RoleEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<RoleEntity>());
}
[Fact]
@@ -156,10 +155,10 @@ public class RoleRepositoryTests
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(2);
result.Value.Should().BeEquivalentTo(roles);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(2, result.Value.Count());
Assert.Equal(roles, result.Value);
}
[Fact]
@@ -169,9 +168,9 @@ public class RoleRepositoryTests
ErrorOr<IEnumerable<RoleEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -193,9 +192,9 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("Admin", CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(role);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(role, result.Value);
}
[Fact]
@@ -205,8 +204,8 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByNameAsync("NonExistentRole", CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -224,13 +223,12 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(role.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(role, options => options
.Including(x => x.Id)
.Including(x => x.RoleName)
.Including(x => x.CreatedOnUtc)
.Including(x => x.CreatedBy));
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(role.Id, result.Value.Id);
Assert.Equal(role.RoleName, result.Value.RoleName);
Assert.Equal(role.CreatedOnUtc, result.Value.CreatedOnUtc);
Assert.Equal(role.CreatedBy, result.Value.CreatedBy);
}
[Fact]
@@ -243,8 +241,8 @@ public class RoleRepositoryTests
ErrorOr<RoleEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -276,13 +274,13 @@ public class RoleRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
updatedEntry.Should().NotBeNull();
updatedEntry!.Entity.RoleName.Should().Be("SuperAdmin");
Assert.NotNull(updatedEntry);
Assert.Equal("SuperAdmin", updatedEntry!.Entity.RoleName);
}
[Fact]
@@ -301,8 +299,8 @@ public class RoleRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
[Fact]
@@ -333,14 +331,14 @@ public class RoleRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<RoleEntity>? updatedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
updatedEntry.Should().NotBeNull();
updatedEntry!.Entity.RolePermissions.Should().HaveCount(1);
updatedEntry.Entity.RolePermissions.First().Should().BeEquivalentTo(newRolePermission);
Assert.NotNull(updatedEntry);
Assert.Single(updatedEntry!.Entity.RolePermissions);
Assert.Equal(newRolePermission, updatedEntry.Entity.RolePermissions.First());
}
[Fact]
@@ -362,13 +360,13 @@ public class RoleRepositoryTests
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Deleted);
Assert.False(result.IsError);
Assert.Equal(Result.Deleted, result.Value);
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
deletedEntry.Should().NotBeNull();
deletedEntry!.State.Should().Be(EntityState.Deleted);
Assert.NotNull(deletedEntry);
Assert.Equal(EntityState.Deleted, deletedEntry!.State);
}
[Fact]
@@ -381,8 +379,8 @@ public class RoleRepositoryTests
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(nonExistentId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.RoleNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.RoleNotFound, result.FirstError);
}
[Fact]
@@ -401,12 +399,12 @@ public class RoleRepositoryTests
ErrorOr<Deleted> result = await _sut.DeleteByIdAsync(existingRole.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Deleted);
Assert.False(result.IsError);
Assert.Equal(Result.Deleted, result.Value);
EntityEntry<RoleEntity>? deletedEntry = _mockContext.ChangeTracker.Entries<RoleEntity>()
.FirstOrDefault(e => e.Entity.Id == existingRole.Id);
deletedEntry.Should().NotBeNull();
deletedEntry!.State.Should().Be(EntityState.Deleted);
Assert.NotNull(deletedEntry);
Assert.Equal(EntityState.Deleted, deletedEntry!.State);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Errors;
using Lumina.DataAccess.Core.Repositories.Authorization;
@@ -50,12 +49,12 @@ public class UserRoleRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(userRole, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<UserRoleEntity>? addedUserRole = _mockContext.ChangeTracker.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == userRole.Id);
addedUserRole.Should().NotBeNull();
addedUserRole!.State.Should().Be(EntityState.Added);
Assert.NotNull(addedUserRole);
Assert.Equal(EntityState.Added, addedUserRole!.State);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.DataAccess.Core.Repositories.Books;
@@ -50,13 +49,13 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
// Check if the book was added to the context's ChangeTracker
// check if the book was added to the context's ChangeTracker
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
addedBook.Should().NotBeNull();
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
Assert.NotNull(addedBook);
}
[Fact]
@@ -72,9 +71,9 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.WrittenContent.BookAlreadyExists);
_mockContext.ChangeTracker.Entries<BookEntity>().Should().HaveCount(1); // Only the existing book should be in the context}
Assert.True(result.IsError);
Assert.Equal(Errors.WrittenContent.BookAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<BookEntity>()); // only the existing book should be in the context
}
[Fact]
@@ -92,16 +91,16 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
addedBook.Should().NotBeNull();
Assert.NotNull(addedBook);
BookEntity addedBookEntity = addedBook!.Entity;
addedBookEntity.Tags.Should().HaveCount(2);
addedBookEntity.Tags.Should().Contain(t => t.Name == "Existing" && t == existingTag);
addedBookEntity.Tags.Should().Contain(t => t.Name == "New" && t != existingTag);
Assert.Equal(2, addedBookEntity.Tags.Count);
Assert.Contains(addedBookEntity.Tags, t => t.Name == "Existing" && t == existingTag);
Assert.Contains(addedBookEntity.Tags, t => t.Name == "New" && t != existingTag);
}
[Fact]
@@ -119,16 +118,16 @@ public class BookRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<BookEntity>? addedBook = _mockContext.ChangeTracker.Entries<BookEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id);
addedBook.Should().NotBeNull();
Assert.NotNull(addedBook);
BookEntity addedBookEntity = addedBook!.Entity;
addedBookEntity.Genres.Should().HaveCount(2);
addedBookEntity.Genres.Should().Contain(g => g.Name == "Existing" && g == existingGenre);
addedBookEntity.Genres.Should().Contain(g => g.Name == "New" && g != existingGenre);
Assert.Equal(2, addedBookEntity.Genres.Count);
Assert.Contains(addedBookEntity.Genres, g => g.Name == "Existing" && g == existingGenre);
Assert.Contains(addedBookEntity.Genres, g => g.Name == "New" && g != existingGenre);
}
[Fact]
@@ -148,10 +147,10 @@ public class BookRepositoryTests
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(3);
result.Value.Should().BeEquivalentTo(books);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(books, result.Value);
}
[Fact]
@@ -161,9 +160,9 @@ public class BookRepositoryTests
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -181,12 +180,12 @@ public class BookRepositoryTests
ErrorOr<IEnumerable<BookEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(1);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Single(result.Value);
BookEntity retrievedBook = result.Value.First();
retrievedBook.Tags.Should().HaveCount(2);
retrievedBook.Genres.Should().HaveCount(2);
retrievedBook.ISBNs.Should().HaveCount(2);
Assert.Equal(2, retrievedBook.Tags.Count);
Assert.Equal(2, retrievedBook.Genres.Count);
Assert.Equal(2, retrievedBook.ISBNs.Count);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.DataAccess.Core.Repositories.Books;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
@@ -38,7 +37,7 @@ public class RepositoryDictionaryTests
repositoryDictionary.Add<IBookRepository>(bookRepository);
// Assert
repositoryDictionary.Count.Should().Be(1);
Assert.Equal(1, repositoryDictionary.Count);
}
[Fact]
@@ -53,7 +52,7 @@ public class RepositoryDictionaryTests
repositoryDictionary.Clear();
// Assert
repositoryDictionary.Count.Should().Be(0);
Assert.Equal(0, repositoryDictionary.Count);
}
[Fact]
@@ -68,7 +67,7 @@ public class RepositoryDictionaryTests
IBookRepository actual = repositoryDictionary.Get<IBookRepository>(typeof(BookRepository));
// Assert
actual.Should().BeSameAs(expected);
Assert.Same(expected, actual);
}
[Fact]
@@ -78,8 +77,7 @@ public class RepositoryDictionaryTests
RepositoryDictionary repositoryDictionary = new();
// Act & Assert
Action act = () => repositoryDictionary.Add<IBookRepository>(null!);
act.Should().Throw<ArgumentException>().WithMessage("Value cannot be null!");
Assert.Throws<ArgumentException>(() => repositoryDictionary.Add<IBookRepository>(null!));
}
[Fact]
@@ -91,8 +89,8 @@ public class RepositoryDictionaryTests
repositoryDictionary.Add<IBookRepository>(bookRepository);
// Act & Assert
Action act = () => repositoryDictionary.Add<IBookRepository>(bookRepository);
act.Should().Throw<ArgumentException>().WithMessage("Duplicate values are not allowed!");
ArgumentException exception = Assert.Throws<ArgumentException>(() => repositoryDictionary.Add<IBookRepository>(bookRepository));
Assert.Equal("Duplicate values are not allowed!", exception.Message);
}
[Fact]
@@ -103,7 +101,7 @@ public class RepositoryDictionaryTests
RepositoryDictionary repositoryDictionary = new();
// Act & Assert
Action act = () => repositoryDictionary.Add(nonRepository);
act.Should().Throw<ArgumentException>().WithMessage("Value must implement IRepository interface!");
ArgumentException exception = Assert.Throws<ArgumentException>(() => repositoryDictionary.Add(nonRepository));
Assert.Equal("Value must implement IRepository interface!", exception.Message);
}
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Time;
@@ -36,8 +35,8 @@ public class RepositoryFactoryTests
IBookRepository result = repositoryFactory.CreateRepository<IBookRepository>();
// Assert
result.Should().NotBeNull();
result.Should().BeAssignableTo<IBookRepository>();
Assert.NotNull(result);
Assert.IsAssignableFrom<IBookRepository>(result);
}
[Fact]
@@ -50,7 +49,10 @@ public class RepositoryFactoryTests
RepositoryFactory repositoryFactory = new(serviceProvider);
// Act & Assert
Action act = () => repositoryFactory.CreateRepository<IUnregisteredRepository>();
act.Should().Throw<InvalidOperationException>().WithMessage("No service for type 'Lumina.DataAccess.UnitTests.Core.Repositories.Common.Factory.Fixtures.IUnregisteredRepository' has been registered.");
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(
() => repositoryFactory.CreateRepository<IUnregisteredRepository>());
Assert.Equal(
"No service for type 'Lumina.DataAccess.UnitTests.Core.Repositories.Common.Factory.Fixtures.IUnregisteredRepository' has been registered.",
exception.Message);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using EntityFrameworkCore.Testing.NSubstitute;
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.DataAccess.Core.Repositories.Users;
@@ -53,12 +52,12 @@ public class UserRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
EntityEntry<UserEntity>? addedUser = _mockContext.ChangeTracker.Entries<UserEntity>()
.FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == userModel.Id);
addedUser.Should().NotBeNull();
Assert.NotNull(addedUser);
}
[Fact]
@@ -74,9 +73,9 @@ public class UserRepositoryTests
ErrorOr<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Users.UserAlreadyExists);
_mockContext.ChangeTracker.Entries<UserEntity>().Should().HaveCount(1);
Assert.True(result.IsError);
Assert.Equal(Errors.Users.UserAlreadyExists, result.FirstError);
Assert.Single(_mockContext.ChangeTracker.Entries<UserEntity>());
}
[Fact]
@@ -96,10 +95,10 @@ public class UserRepositoryTests
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().HaveCount(3);
result.Value.Should().BeEquivalentTo(users);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(3, result.Value.Count());
Assert.Equal(users, result.Value);
}
[Fact]
@@ -109,9 +108,9 @@ public class UserRepositoryTests
ErrorOr<IEnumerable<UserEntity>> result = await _sut.GetAllAsync(CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEmpty();
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Empty(result.Value);
}
[Fact]
@@ -126,9 +125,9 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync(userModel.Username, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(userModel);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(userModel, result.Value);
}
[Fact]
@@ -138,8 +137,8 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByUsernameAsync("nonexistent", CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -170,14 +169,14 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
UserEntity? modifiedUser = await _mockContext.Users.FirstOrDefaultAsync(u => u.Username == existingUser.Username);
modifiedUser.Should().NotBeNull();
modifiedUser!.Password.Should().Be(updatedUser.Password);
modifiedUser.TempPassword.Should().Be(updatedUser.TempPassword);
modifiedUser.TotpSecret.Should().Be(updatedUser.TotpSecret);
Assert.NotNull(modifiedUser);
Assert.Equal(updatedUser.Password, modifiedUser.Password);
Assert.Equal(updatedUser.TempPassword, modifiedUser.TempPassword);
Assert.Equal(updatedUser.TotpSecret, modifiedUser.TotpSecret);
}
[Fact]
@@ -190,8 +189,8 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(userModel, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Users.UserDoesNotExist);
Assert.True(result.IsError);
Assert.Equal(Errors.Users.UserDoesNotExist, result.FirstError);
}
[Fact]
@@ -206,15 +205,14 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(userModel.Id, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Should().BeEquivalentTo(userModel, options => options
.Including(x => x.Id)
.Including(x => x.Username)
.Including(x => x.Password)
.Including(x => x.Libraries)
.Including(x => x.UserPermissions)
.Including(x => x.UserRole));
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(userModel.Id, result.Value.Id);
Assert.Equal(userModel.Username, result.Value.Username);
Assert.Equal(userModel.Password, result.Value.Password);
Assert.Equal(userModel.Libraries, result.Value.Libraries);
Assert.Equal(userModel.UserPermissions, result.Value.UserPermissions);
Assert.Equal(userModel.UserRole, result.Value.UserRole);
}
[Fact]
@@ -227,8 +225,8 @@ public class UserRepositoryTests
ErrorOr<UserEntity?> result = await _sut.GetByIdAsync(nonExistentId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().BeNull();
Assert.False(result.IsError);
Assert.Null(result.Value);
}
[Fact]
@@ -273,16 +271,16 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
UserEntity? modifiedUser = await _mockContext.Users
.Include(u => u.UserPermissions)
.ThenInclude(up => up.Permission)
.FirstOrDefaultAsync(u => u.Username == existingUser.Username);
modifiedUser.Should().NotBeNull();
modifiedUser!.UserPermissions.Should().HaveCount(1);
modifiedUser.UserPermissions.First().Permission.PermissionName.Should().Be(newPermission.PermissionName);
Assert.NotNull(modifiedUser);
Assert.Single(modifiedUser.UserPermissions);
Assert.Equal(newPermission.PermissionName, modifiedUser.UserPermissions.First().Permission.PermissionName);
}
[Fact]
@@ -338,20 +336,20 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserPermissionEntity>? removedPermission = _mockContext.ChangeTracker
.Entries<UserPermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Deleted);
removedPermission.Should().NotBeNull();
removedPermission!.Entity.PermissionId.Should().Be(oldPermission.Id);
Assert.NotNull(removedPermission);
Assert.Equal(oldPermission.Id, removedPermission.Entity.PermissionId);
EntityEntry<UserPermissionEntity>? addedPermission = _mockContext.ChangeTracker
.Entries<UserPermissionEntity>()
.FirstOrDefault(e => e.State == EntityState.Added);
addedPermission.Should().NotBeNull();
addedPermission!.Entity.PermissionId.Should().Be(newPermission.Id);
Assert.NotNull(addedPermission);
Assert.Equal(newPermission.Id, addedPermission.Entity.PermissionId);
}
[Fact]
@@ -441,22 +439,22 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Deleted);
removedRole.Should().NotBeNull();
removedRole!.Entity.RoleId.Should().Be(oldRole.Id);
Assert.NotNull(removedRole);
Assert.Equal(oldRole.Id, removedRole.Entity.RoleId);
EntityEntry<UserRoleEntity>? addedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added);
addedRole.Should().NotBeNull();
addedRole!.Entity.UserId.Should().Be(existingUser.Id);
addedRole.Entity.RoleId.Should().Be(newRole.Id);
addedRole.Entity.Role.Should().Be(newRole);
Assert.NotNull(addedRole);
Assert.Equal(existingUser.Id, addedRole.Entity.UserId);
Assert.Equal(newRole.Id, addedRole.Entity.RoleId);
Assert.Equal(newRole, addedRole.Entity.Role);
}
[Fact]
@@ -501,18 +499,18 @@ public class UserRepositoryTests
ErrorOr<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Updated);
Assert.False(result.IsError);
Assert.Equal(Result.Updated, result.Value);
EntityEntry<UserRoleEntity>? removedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Deleted);
removedRole.Should().NotBeNull();
removedRole!.Entity.Should().Be(oldUserRole);
Assert.NotNull(removedRole);
Assert.Equal(oldUserRole, removedRole.Entity);
EntityEntry<UserRoleEntity>? addedRole = _mockContext.ChangeTracker
.Entries<UserRoleEntity>()
.FirstOrDefault(e => e.State == EntityState.Added);
addedRole.Should().BeNull();
Assert.Null(addedRole);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -62,8 +61,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
await _mockPermissionRepository
.Received(4)
@@ -90,8 +89,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -112,13 +111,13 @@ public class DataSeedServiceTests
await _sut.SetDefaultAuthorizationPermissionsAsync(adminId, CancellationToken.None);
// Assert
capturedPermissions.Should().BeEquivalentTo(
[
Assert.Equal(new[]
{
AuthorizationPermission.CanViewUsers,
AuthorizationPermission.CanDeleteUsers,
AuthorizationPermission.CanRegisterUsers,
AuthorizationPermission.CanCreateLibraries
]);
}, capturedPermissions);
}
[Fact]
@@ -136,8 +135,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
await mockRoleRepository
.Received(1)
@@ -168,14 +167,14 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
[Fact]
public async Task SetDefaultAuthorizationRolesAsync_ShouldCreateDefaultAdminRole()
public async Task SetDefaultAuthorizationRolesAsync_WhenCalled_ShouldCreateDefaultAdminRole()
{
// Arrange
Guid userId = Guid.NewGuid();
@@ -193,11 +192,11 @@ public class DataSeedServiceTests
await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
// Assert
capturedRoleNames.Should().BeEquivalentTo(["Admin"]);
Assert.Equal(new[] { "Admin" }, capturedRoleNames);
}
[Fact]
public async Task SetDefaultAuthorizationRolesAsync_ShouldSetCorrectAuditProperties()
public async Task SetDefaultAuthorizationRolesAsync_WhenCalled_ShouldSetCorrectAuditProperties()
{
// Arrange
Guid userId = Guid.NewGuid();
@@ -215,11 +214,11 @@ public class DataSeedServiceTests
await _sut.SetDefaultAuthorizationRolesAsync(userId, CancellationToken.None);
// Assert
capturedRole.Should().NotBeNull();
capturedRole!.CreatedBy.Should().Be(userId);
capturedRole.CreatedOnUtc.Should().Be(_fixedUtcNow);
capturedRole.UpdatedBy.Should().BeNull();
capturedRole.UpdatedOnUtc.Should().BeNull();
Assert.NotNull(capturedRole);
Assert.Equal(userId, capturedRole!.CreatedBy);
Assert.Equal(_fixedUtcNow, capturedRole.CreatedOnUtc);
Assert.Null(capturedRole.UpdatedBy);
Assert.Null(capturedRole.UpdatedOnUtc);
}
[Fact]
@@ -251,8 +250,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
await mockRolePermissionRepository
.Received(3)
@@ -282,9 +281,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.AdminAccountNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.AdminAccountNotFound, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -309,8 +307,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -340,8 +338,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -364,8 +362,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -397,8 +395,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(Result.Created);
Assert.False(result.IsError);
Assert.Equal(Result.Created, result.Value);
await mockUserRoleRepository
.Received(1)
@@ -429,9 +427,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.AdminRoleNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.AdminRoleNotFound, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -455,8 +452,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Authorization.AdminAccountNotFound);
Assert.True(result.IsError);
Assert.Equal(Errors.Authorization.AdminAccountNotFound, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -487,8 +484,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -511,8 +508,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -538,8 +535,8 @@ public class DataSeedServiceTests
ErrorOr<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(expectedError);
Assert.True(result.IsError);
Assert.Equal(expectedError, result.FirstError);
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Authentication;
@@ -59,7 +58,7 @@ public class UnitOfWorkTests
unitOfWork.ResetRepositories();
// Assert
unitOfWork.Repositories.Count.Should().Be(0);
Assert.Equal(0, unitOfWork.Repositories.Count);
}
[Fact]
@@ -79,8 +78,8 @@ public class UnitOfWorkTests
unitOfWork.AddRepositories();
// Assert
unitOfWork.Repositories.Count.Should().BeGreaterThan(0);
unitOfWork.Repositories.Count.Should().Be(initialCount);
Assert.True(unitOfWork.Repositories.Count > 0);
Assert.Equal(initialCount, unitOfWork.Repositories.Count);
}
[Fact]
@@ -94,7 +93,7 @@ public class UnitOfWorkTests
UnitOfWork unitOfWork = new(repositoryFactory, dbContext);
// Assert
unitOfWork.Repositories.Count.Should().BeGreaterThan(0);
Assert.True(unitOfWork.Repositories.Count > 0);
}
[Fact]
@@ -113,7 +112,7 @@ public class UnitOfWorkTests
IBookRepository result = unitOfWork.GetRepository<IBookRepository>();
// Assert
result.Should().BeNull();
Assert.Null(result);
}
[Fact]
@@ -128,7 +127,7 @@ public class UnitOfWorkTests
UnitOfWork unitOfWork = (UnitOfWork)serviceProvider.GetRequiredService<IUnitOfWork>();
// Act & Assert
unitOfWork.GetRepository<IBookRepository>().Should().NotBeNull();
Assert.NotNull(unitOfWork.GetRepository<IBookRepository>());
}
[Fact]
@@ -24,7 +24,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="EntityFrameworkCore.Testing.NSubstitute" Version="8.0.0" />
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Domain.Common.Primitives;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -22,8 +21,8 @@ public class OptionalTests
Optional<int> optional = Optional<int>.Some(value);
// Assert
optional.HasValue.Should().BeTrue();
optional.Value.Should().Be(value);
Assert.True(optional.HasValue);
Assert.Equal(value, optional.Value);
}
[Fact]
@@ -33,8 +32,8 @@ public class OptionalTests
Optional<int> optional = Optional<int>.None();
// Assert
optional.HasValue.Should().BeFalse();
optional.Value.Should().Be(default);
Assert.False(optional.HasValue);
Assert.Equal(default, optional.Value);
}
[Fact]
@@ -47,8 +46,8 @@ public class OptionalTests
Optional<string> optional = value;
// Assert
optional.HasValue.Should().BeTrue();
optional.Value.Should().Be(value);
Assert.True(optional.HasValue);
Assert.Equal(value, optional.Value);
}
[Fact]
@@ -61,8 +60,8 @@ public class OptionalTests
Optional<string> optional = Optional<string>.FromNullable(nullableValue);
// Assert
optional.HasValue.Should().BeTrue();
optional.Value.Should().Be(nullableValue);
Assert.True(optional.HasValue);
Assert.Equal(nullableValue, optional.Value);
}
[Fact]
@@ -75,8 +74,8 @@ public class OptionalTests
Optional<string> optional = Optional<string>.FromNullable(nullableValue);
// Assert
optional.HasValue.Should().BeFalse();
optional.Value.Should().BeNull();
Assert.False(optional.HasValue);
Assert.Null(optional.Value);
}
[Fact]
@@ -89,8 +88,8 @@ public class OptionalTests
Optional<int> optional = Optional<int>.FromNullable(nullableValue);
// Assert
optional.HasValue.Should().BeTrue();
optional.Value.Should().Be(nullableValue.Value);
Assert.True(optional.HasValue);
Assert.Equal(nullableValue.Value, optional.Value);
}
[Fact]
@@ -103,8 +102,8 @@ public class OptionalTests
Optional<int> optional = Optional<int>.FromNullable(nullableValue);
// Assert
optional.HasValue.Should().BeFalse();
optional.Value.Should().Be(default);
Assert.False(optional.HasValue);
Assert.Equal(default, optional.Value);
}
[Fact]
@@ -117,7 +116,7 @@ public class OptionalTests
string result = optional.ToString();
// Assert
result.Should().Be("42");
Assert.Equal("42", result);
}
[Fact]
@@ -130,6 +129,6 @@ public class OptionalTests
string result = optional.ToString();
// Assert
result.Should().BeEmpty();
Assert.Empty(result);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
@@ -33,12 +32,12 @@ public class DirectoryTests
ErrorOr<Directory> result = Directory.Create(path, name, dateCreated, dateModified);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(name);
result.Value.DateCreated.Should().Be(dateCreated);
result.Value.DateModified.Should().Be(dateModified);
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(name, result.Value.Name);
Assert.Equal(dateCreated, result.Value.DateCreated);
Assert.Equal(dateModified, result.Value.DateModified);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
}
[Fact]
@@ -54,8 +53,8 @@ public class DirectoryTests
ErrorOr<Directory> result = Directory.Create(invalidPath, name, dateCreated, dateModified);
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.FileSystemManagement.InvalidPath);
Assert.True(result.IsError);
Assert.Equal(Errors.FileSystemManagement.InvalidPath, result.FirstError);
}
[Fact]
@@ -63,7 +62,7 @@ public class DirectoryTests
{
// Arrange
ErrorOr<FileSystemPathId> pathIdResult = FileSystemPathId.Create("/valid/path");
pathIdResult.IsError.Should().BeFalse();
Assert.False(pathIdResult.IsError);
FileSystemPathId pathId = pathIdResult.Value;
string name = "TestDirectory";
Optional<DateTime> dateCreated = DateTime.Now;
@@ -73,13 +72,13 @@ public class DirectoryTests
ErrorOr<Directory> result = Directory.Create(pathId, name, dateCreated, dateModified);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Id.Should().Be(pathId);
result.Value.Name.Should().Be(name);
result.Value.DateCreated.Should().Be(dateCreated);
result.Value.DateModified.Should().Be(dateModified);
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(pathId, result.Value.Id);
Assert.Equal(name, result.Value.Name);
Assert.Equal(dateCreated, result.Value.DateCreated);
Assert.Equal(dateModified, result.Value.DateModified);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
}
[Fact]
@@ -87,7 +86,7 @@ public class DirectoryTests
{
// Arrange
ErrorOr<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
directoryResult.IsError.Should().BeFalse();
Assert.False(directoryResult.IsError);
Directory directory = directoryResult.Value;
DateTime newDate = DateTime.Now;
@@ -95,8 +94,8 @@ public class DirectoryTests
ErrorOr<Updated> result = directory.UpdateLastModified(newDate);
// Assert
result.IsError.Should().BeFalse();
directory.DateModified.Value.Should().Be(newDate);
Assert.False(result.IsError);
Assert.Equal(newDate, directory.DateModified.Value);
}
[Fact]
@@ -104,7 +103,7 @@ public class DirectoryTests
{
// Arrange
ErrorOr<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
directoryResult.IsError.Should().BeFalse();
Assert.False(directoryResult.IsError);
Directory directory = directoryResult.Value;
FileSystemItem item = new FileSystemItemFixture(FileSystemPathId.Create("/mock/path").Value, "MockItem", FileSystemItemType.File);
@@ -112,8 +111,8 @@ public class DirectoryTests
ErrorOr<Updated> result = directory.AddItem(item);
// Assert
result.IsError.Should().BeFalse();
directory.Items.Should().Contain(item);
Assert.False(result.IsError);
Assert.Contains(item, directory.Items);
}
[Fact]
@@ -121,7 +120,7 @@ public class DirectoryTests
{
// Arrange
ErrorOr<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
directoryResult.IsError.Should().BeFalse();
Assert.False(directoryResult.IsError);
Directory directory = directoryResult.Value;
FileSystemItem item = new FileSystemItemFixture(FileSystemPathId.Create("/mock/path").Value, "MockItem", FileSystemItemType.File);
directory.AddItem(item);
@@ -130,7 +129,7 @@ public class DirectoryTests
ErrorOr<Updated> result = directory.RemoveItem(item);
// Assert
result.IsError.Should().BeFalse();
directory.Items.Should().NotContain(item);
Assert.False(result.IsError);
Assert.DoesNotContain(item, directory.Items);
}
}
Loaded 100 of 235 files, more files were not shown because too many files have changed in this diff. Show more