mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 05:11:10 +00:00
Merge branch 'refactor/standardize-test-fixtures-and-docs' into feature/add-artwork-provider-and-metadata-aggregation
This commit is contained in:
commit
4ff184d8a5
388 files changed
+13829
-2814
No files matched your search
+9
-18
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
@@ -17,15 +18,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PermissionEntityMappingTests
|
||||
{
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
PermissionEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
PermissionName = AuthorizationPermission.CanViewUsers
|
||||
};
|
||||
PermissionEntity entity = _permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers);
|
||||
|
||||
// Act
|
||||
PermissionResponse result = entity.ToResponse();
|
||||
@@ -44,11 +43,7 @@ public class PermissionEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentPermissions_ShouldMapCorrectly(AuthorizationPermission permission)
|
||||
{
|
||||
// Arrange
|
||||
PermissionEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
PermissionName = permission
|
||||
};
|
||||
PermissionEntity entity = _permissionEntityFixture.Create(permissionName: permission);
|
||||
|
||||
// Act
|
||||
PermissionResponse result = entity.ToResponse();
|
||||
@@ -65,9 +60,9 @@ public class PermissionEntityMappingTests
|
||||
// Arrange
|
||||
List<PermissionEntity> entities =
|
||||
[
|
||||
new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanViewUsers },
|
||||
new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanDeleteUsers },
|
||||
new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanRegisterUsers }
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers),
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers),
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanRegisterUsers)
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -101,11 +96,7 @@ public class PermissionEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentIds_ShouldMapCorrectly(string idString)
|
||||
{
|
||||
// Arrange
|
||||
PermissionEntity entity = new()
|
||||
{
|
||||
Id = Guid.Parse(idString),
|
||||
PermissionName = AuthorizationPermission.CanViewUsers
|
||||
};
|
||||
PermissionEntity entity = _permissionEntityFixture.Create(id: Guid.Parse(idString), permissionName: AuthorizationPermission.CanViewUsers);
|
||||
|
||||
// Act
|
||||
PermissionResponse result = entity.ToResponse();
|
||||
|
||||
+21
-46
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
@@ -17,15 +18,15 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RoleEntityMappingTests
|
||||
{
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin"
|
||||
};
|
||||
RoleEntity entity = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
// Act
|
||||
RoleResponse result = entity.ToResponse();
|
||||
@@ -41,36 +42,18 @@ public class RoleEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.NewGuid();
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = roleId,
|
||||
RoleName = "Admin"
|
||||
};
|
||||
RoleEntity role = _roleEntityFixture.Create(id: roleId, roleName: "Admin");
|
||||
|
||||
role.RolePermissions =
|
||||
[
|
||||
new()
|
||||
{
|
||||
PermissionId = Guid.NewGuid(),
|
||||
RoleId = roleId,
|
||||
Role = role,
|
||||
Permission = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
PermissionName = AuthorizationPermission.CanViewUsers
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
PermissionId = Guid.NewGuid(),
|
||||
RoleId = roleId,
|
||||
Role = role,
|
||||
Permission = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
PermissionName = AuthorizationPermission.CanDeleteUsers
|
||||
}
|
||||
}
|
||||
_rolePermissionEntityFixture.Create(
|
||||
roleId: roleId,
|
||||
role: role,
|
||||
permission: _permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)),
|
||||
_rolePermissionEntityFixture.Create(
|
||||
roleId: roleId,
|
||||
role: role,
|
||||
permission: _permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers))
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -89,9 +72,9 @@ public class RoleEntityMappingTests
|
||||
// Arrange
|
||||
List<RoleEntity> entities =
|
||||
[
|
||||
new() { Id = Guid.NewGuid(), RoleName = "Admin" },
|
||||
new() { Id = Guid.NewGuid(), RoleName = "User" },
|
||||
new() { Id = Guid.NewGuid(), RoleName = "Guest" }
|
||||
_roleEntityFixture.Create(roleName: "Admin"),
|
||||
_roleEntityFixture.Create(roleName: "User"),
|
||||
_roleEntityFixture.Create(roleName: "Guest")
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -100,7 +83,7 @@ public class RoleEntityMappingTests
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(3, results.Count());
|
||||
List<RoleResponse> resultList = results.ToList();
|
||||
List<RoleResponse> resultList = [.. results];
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
Assert.Equal(entities[i].Id, resultList[i].Id);
|
||||
@@ -129,11 +112,7 @@ public class RoleEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentRoleNames_ShouldMapCorrectly(string roleName)
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = roleName
|
||||
};
|
||||
RoleEntity entity = _roleEntityFixture.Create(roleName: roleName);
|
||||
|
||||
// Act
|
||||
RoleResponse result = entity.ToResponse();
|
||||
@@ -151,11 +130,7 @@ public class RoleEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentIds_ShouldMapCorrectly(string idString)
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity entity = new()
|
||||
{
|
||||
Id = Guid.Parse(idString),
|
||||
RoleName = "Admin"
|
||||
};
|
||||
RoleEntity entity = _roleEntityFixture.Create(id: Guid.Parse(idString), roleName: "Admin");
|
||||
|
||||
// Act
|
||||
RoleResponse result = entity.ToResponse();
|
||||
|
||||
+17
-25
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
@@ -16,16 +17,15 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserAuthorizationEntityMappingTests
|
||||
{
|
||||
private readonly UserAuthorizationEntityFixture _userAuthorizationEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.NewGuid(),
|
||||
Role = "Admin",
|
||||
Permissions = new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
};
|
||||
UserAuthorizationEntity entity = _userAuthorizationEntityFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
|
||||
// Act
|
||||
AuthorizationResponse result = entity.ToResponse();
|
||||
@@ -41,12 +41,9 @@ public class UserAuthorizationEntityMappingTests
|
||||
public void ToResponse_WhenMappingEntityWithEmptyCollections_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.NewGuid(),
|
||||
Role = string.Empty,
|
||||
Permissions = new HashSet<AuthorizationPermission>()
|
||||
};
|
||||
UserAuthorizationEntity entity = _userAuthorizationEntityFixture.Create(
|
||||
role: string.Empty,
|
||||
permissions: new HashSet<AuthorizationPermission>());
|
||||
|
||||
// Act
|
||||
AuthorizationResponse result = entity.ToResponse();
|
||||
@@ -62,17 +59,14 @@ public class UserAuthorizationEntityMappingTests
|
||||
public void ToResponse_WhenMappingEntityWithMultipleRolesAndPermissions_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.NewGuid(),
|
||||
Role = "Admin",
|
||||
Permissions = new HashSet<AuthorizationPermission>
|
||||
UserAuthorizationEntity entity = _userAuthorizationEntityFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission>
|
||||
{
|
||||
AuthorizationPermission.CanViewUsers,
|
||||
AuthorizationPermission.CanDeleteUsers,
|
||||
AuthorizationPermission.CanRegisterUsers
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// Act
|
||||
AuthorizationResponse result = entity.ToResponse();
|
||||
@@ -91,12 +85,10 @@ public class UserAuthorizationEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentUserIds_ShouldMapCorrectly(string userIdString)
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.Parse(userIdString),
|
||||
Role = "Admin",
|
||||
Permissions = new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
};
|
||||
UserAuthorizationEntity entity = _userAuthorizationEntityFixture.Create(
|
||||
userId: Guid.Parse(userIdString),
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
|
||||
// Act
|
||||
AuthorizationResponse result = entity.ToResponse();
|
||||
|
||||
+14
-11
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,11 +17,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreDtoMappingTests
|
||||
{
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidGenreDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = new("Rock");
|
||||
GenreDto genreDto = _genreDtoFixture.Create(name: "Rock");
|
||||
|
||||
// Act
|
||||
Result<Genre> result = genreDto.ToDomainEntity();
|
||||
@@ -39,7 +42,7 @@ public class GenreDtoMappingTests
|
||||
public void ToDomainEntity_WhenMappingDifferentValidGenreDtos_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = new(name);
|
||||
GenreDto genreDto = _genreDtoFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
Result<Genre> result = genreDto.ToDomainEntity();
|
||||
@@ -57,7 +60,7 @@ public class GenreDtoMappingTests
|
||||
public void ToDomainEntity_WhenMappingInvalidGenreDto_ShouldReturnError(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreDto genreDto = new(invalidName);
|
||||
GenreDto genreDto = _genreDtoFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Genre> result = genreDto.ToDomainEntity();
|
||||
@@ -72,10 +75,10 @@ public class GenreDtoMappingTests
|
||||
// Arrange
|
||||
List<GenreDto> genreDtos =
|
||||
[
|
||||
new GenreDto("Rock"),
|
||||
new GenreDto("Jazz"),
|
||||
new GenreDto("Classical"),
|
||||
new GenreDto("Pop")
|
||||
_genreDtoFixture.Create(name: "Rock"),
|
||||
_genreDtoFixture.Create(name: "Jazz"),
|
||||
_genreDtoFixture.Create(name: "Classical"),
|
||||
_genreDtoFixture.Create(name: "Pop")
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -99,10 +102,10 @@ public class GenreDtoMappingTests
|
||||
// Arrange
|
||||
List<GenreDto> genreDtos =
|
||||
[
|
||||
new GenreDto("Rock"),
|
||||
new GenreDto(""),
|
||||
new GenreDto("Jazz"),
|
||||
new GenreDto(" ")
|
||||
_genreDtoFixture.Create(name: "Rock"),
|
||||
_genreDtoFixture.Create(name: ""),
|
||||
_genreDtoFixture.Create(name: "Jazz"),
|
||||
_genreDtoFixture.Create(name: " ")
|
||||
];
|
||||
|
||||
// Act
|
||||
|
||||
+16
-13
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -18,11 +19,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreEntityMappingTests
|
||||
{
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidGenreEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new("Fiction");
|
||||
GenreEntity entity = _genreEntityFixture.Create(name: "Fiction");
|
||||
|
||||
// Act
|
||||
GenreDto result = entity.ToResponse();
|
||||
@@ -40,7 +43,7 @@ public class GenreEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentValidGenreEntities_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new(name);
|
||||
GenreEntity entity = _genreEntityFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
GenreDto result = entity.ToResponse();
|
||||
@@ -57,7 +60,7 @@ public class GenreEntityMappingTests
|
||||
public void ToResponse_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new(invalidName);
|
||||
GenreEntity entity = _genreEntityFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
GenreDto result = entity.ToResponse();
|
||||
@@ -70,7 +73,7 @@ public class GenreEntityMappingTests
|
||||
public void ToDomainEntity_WhenMappingValidGenreEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new("Fiction");
|
||||
GenreEntity entity = _genreEntityFixture.Create(name: "Fiction");
|
||||
|
||||
// Act
|
||||
Result<Genre> result = entity.ToDomainEntity();
|
||||
@@ -88,7 +91,7 @@ public class GenreEntityMappingTests
|
||||
public void ToDomainEntity_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
GenreEntity entity = new(invalidName);
|
||||
GenreEntity entity = _genreEntityFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Genre> result = entity.ToDomainEntity();
|
||||
@@ -104,10 +107,10 @@ public class GenreEntityMappingTests
|
||||
// Arrange
|
||||
List<GenreEntity> entities =
|
||||
[
|
||||
new GenreEntity("Fiction"),
|
||||
new GenreEntity("Mystery"),
|
||||
new GenreEntity("Romance"),
|
||||
new GenreEntity("Thriller")
|
||||
_genreEntityFixture.Create(name: "Fiction"),
|
||||
_genreEntityFixture.Create(name: "Mystery"),
|
||||
_genreEntityFixture.Create(name: "Romance"),
|
||||
_genreEntityFixture.Create(name: "Thriller")
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -131,10 +134,10 @@ public class GenreEntityMappingTests
|
||||
// Arrange
|
||||
List<GenreEntity> entities =
|
||||
[
|
||||
new GenreEntity("Fiction"),
|
||||
new GenreEntity("Mystery"),
|
||||
new GenreEntity("Romance"),
|
||||
new GenreEntity("Thriller")
|
||||
_genreEntityFixture.Create(name: "Fiction"),
|
||||
_genreEntityFixture.Create(name: "Mystery"),
|
||||
_genreEntityFixture.Create(name: "Romance"),
|
||||
_genreEntityFixture.Create(name: "Thriller")
|
||||
];
|
||||
|
||||
// Act
|
||||
|
||||
+14
-11
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,11 +17,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagDtoMappingTests
|
||||
{
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTagDto_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = new("indie");
|
||||
TagDto tagDto = _tagDtoFixture.Create(name: "indie");
|
||||
|
||||
// Act
|
||||
Result<Tag> result = tagDto.ToDomainEntity();
|
||||
@@ -40,7 +43,7 @@ public class TagDtoMappingTests
|
||||
public void ToDomainEntity_WhenMappingDifferentValidTagDtos_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = new(name);
|
||||
TagDto tagDto = _tagDtoFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
Result<Tag> result = tagDto.ToDomainEntity();
|
||||
@@ -58,7 +61,7 @@ public class TagDtoMappingTests
|
||||
public void ToDomainEntity_WhenMappingInvalidTagDto_ShouldReturnError(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagDto tagDto = new(invalidName);
|
||||
TagDto tagDto = _tagDtoFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Tag> result = tagDto.ToDomainEntity();
|
||||
@@ -73,10 +76,10 @@ public class TagDtoMappingTests
|
||||
// Arrange
|
||||
List<TagDto> tagDtos =
|
||||
[
|
||||
new TagDto("indie"),
|
||||
new TagDto("electronic"),
|
||||
new TagDto("instrumental"),
|
||||
new TagDto("live")
|
||||
_tagDtoFixture.Create(name: "indie"),
|
||||
_tagDtoFixture.Create(name: "electronic"),
|
||||
_tagDtoFixture.Create(name: "instrumental"),
|
||||
_tagDtoFixture.Create(name: "live")
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -100,10 +103,10 @@ public class TagDtoMappingTests
|
||||
// Arrange
|
||||
List<TagDto> tagDtos =
|
||||
[
|
||||
new TagDto("indie"),
|
||||
new TagDto(""),
|
||||
new TagDto("electronic"),
|
||||
new TagDto(" ")
|
||||
_tagDtoFixture.Create(name: "indie"),
|
||||
_tagDtoFixture.Create(name: ""),
|
||||
_tagDtoFixture.Create(name: "electronic"),
|
||||
_tagDtoFixture.Create(name: " ")
|
||||
];
|
||||
|
||||
// Act
|
||||
|
||||
+16
-13
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -18,11 +19,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagEntityMappingTests
|
||||
{
|
||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidTagEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new("Fantasy");
|
||||
TagEntity entity = _tagEntityFixture.Create(name: "Fantasy");
|
||||
|
||||
// Act
|
||||
TagDto result = entity.ToResponse();
|
||||
@@ -40,7 +43,7 @@ public class TagEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentValidTagEntities_ShouldMapCorrectly(string name)
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new(name);
|
||||
TagEntity entity = _tagEntityFixture.Create(name: name);
|
||||
|
||||
// Act
|
||||
TagDto result = entity.ToResponse();
|
||||
@@ -57,7 +60,7 @@ public class TagEntityMappingTests
|
||||
public void ToResponse_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new(invalidName);
|
||||
TagEntity entity = _tagEntityFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
TagDto result = entity.ToResponse();
|
||||
@@ -70,7 +73,7 @@ public class TagEntityMappingTests
|
||||
public void ToDomainEntity_WhenMappingValidTagEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new("Fantasy");
|
||||
TagEntity entity = _tagEntityFixture.Create(name: "Fantasy");
|
||||
|
||||
// Act
|
||||
Result<Tag> result = entity.ToDomainEntity();
|
||||
@@ -88,7 +91,7 @@ public class TagEntityMappingTests
|
||||
public void ToDomainEntity_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
|
||||
{
|
||||
// Arrange
|
||||
TagEntity entity = new(invalidName);
|
||||
TagEntity entity = _tagEntityFixture.Create(name: invalidName, includeName: invalidName is not null);
|
||||
|
||||
// Act
|
||||
Result<Tag> result = entity.ToDomainEntity();
|
||||
@@ -104,10 +107,10 @@ public class TagEntityMappingTests
|
||||
// Arrange
|
||||
List<TagEntity> entities =
|
||||
[
|
||||
new TagEntity("Fantasy"),
|
||||
new TagEntity("Young Adult"),
|
||||
new TagEntity("Historical"),
|
||||
new TagEntity("Coming of Age")
|
||||
_tagEntityFixture.Create(name: "Fantasy"),
|
||||
_tagEntityFixture.Create(name: "Young Adult"),
|
||||
_tagEntityFixture.Create(name: "Historical"),
|
||||
_tagEntityFixture.Create(name: "Coming of Age")
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -131,10 +134,10 @@ public class TagEntityMappingTests
|
||||
// Arrange
|
||||
List<TagEntity> entities =
|
||||
[
|
||||
new TagEntity("Fantasy"),
|
||||
new TagEntity("Young Adult"),
|
||||
new TagEntity("Historical"),
|
||||
new TagEntity("Coming of Age")
|
||||
_tagEntityFixture.Create(name: "Fantasy"),
|
||||
_tagEntityFixture.Create(name: "Young Adult"),
|
||||
_tagEntityFixture.Create(name: "Historical"),
|
||||
_tagEntityFixture.Create(name: "Coming of Age")
|
||||
];
|
||||
|
||||
// Act
|
||||
|
||||
+22
-64
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
@@ -19,6 +19,9 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenConten
|
||||
public class AddBookRequestMappingTests
|
||||
{
|
||||
private readonly AddBookRequestFixture _requestFixture = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||
private readonly MediaContributorRoleDtoFixture _mediaContributorRoleDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
|
||||
@@ -54,36 +57,12 @@ public class AddBookRequestMappingTests
|
||||
public void ToCommand_WhenMappingMinimalRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = new(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
Path: "/books/test.epub",
|
||||
Metadata: new WrittenContentMetadataDto(
|
||||
Title: "Test Book",
|
||||
OriginalTitle: null,
|
||||
Description: null,
|
||||
ReleaseInfo: null,
|
||||
Genres: null,
|
||||
Tags: null,
|
||||
Language: null,
|
||||
OriginalLanguage: null,
|
||||
Publisher: null,
|
||||
PageCount: null),
|
||||
Format: null,
|
||||
Edition: null,
|
||||
VolumeNumber: null,
|
||||
Series: null,
|
||||
ASIN: null,
|
||||
GoodreadsId: null,
|
||||
LCCN: null,
|
||||
OCLCNumber: null,
|
||||
OpenLibraryId: null,
|
||||
LibraryThingId: null,
|
||||
GoogleBooksId: null,
|
||||
BarnesAndNobleId: null,
|
||||
AppleBooksId: null,
|
||||
ISBNs: null,
|
||||
Contributors: null,
|
||||
Ratings: null);
|
||||
AddBookRequest request = _requestFixture.Create(
|
||||
libraryId: Guid.NewGuid(),
|
||||
path: "/books/test.epub",
|
||||
metadata: _writtenContentMetadataDtoFixture.Create(title: "Test Book"),
|
||||
includeOptionalProperties: false
|
||||
);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
@@ -113,42 +92,21 @@ public class AddBookRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequestWithCollections_ShouldMapCollectionsCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddBookRequest request = new(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
Path: "/books/test.epub",
|
||||
Metadata: new WrittenContentMetadataDto(
|
||||
Title: "Test Book",
|
||||
OriginalTitle: null,
|
||||
Description: null,
|
||||
ReleaseInfo: null,
|
||||
Genres: null,
|
||||
Tags: null,
|
||||
Language: null,
|
||||
OriginalLanguage: null,
|
||||
Publisher: null,
|
||||
PageCount: null),
|
||||
Format: null,
|
||||
Edition: null,
|
||||
VolumeNumber: null,
|
||||
Series: null,
|
||||
ASIN: null,
|
||||
GoodreadsId: null,
|
||||
LCCN: null,
|
||||
OCLCNumber: null,
|
||||
OpenLibraryId: null,
|
||||
LibraryThingId: null,
|
||||
GoogleBooksId: null,
|
||||
BarnesAndNobleId: null,
|
||||
AppleBooksId: null,
|
||||
ISBNs: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
|
||||
Contributors:
|
||||
AddBookRequest request = _requestFixture.Create(
|
||||
libraryId: Guid.NewGuid(),
|
||||
path: "/books/test.epub",
|
||||
metadata: _writtenContentMetadataDtoFixture.Create(title: "Test Book"),
|
||||
isbns: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
|
||||
contributors:
|
||||
[
|
||||
new(
|
||||
new MediaContributorNameDto("John Doe", "John Smith Doe"),
|
||||
new MediaContributorRoleDto("Author", "Writing")
|
||||
_mediaContributorNameDtoFixture.Create(displayName: "John Doe", legalName: "John Smith Doe"),
|
||||
_mediaContributorRoleDtoFixture.Create(name: "Author", category: "Writing")
|
||||
)
|
||||
],
|
||||
Ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)]);
|
||||
ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)],
|
||||
includeOptionalProperties: false
|
||||
);
|
||||
|
||||
// Act
|
||||
AddBookCommand result = request.ToCommand();
|
||||
|
||||
+26
-26
@@ -4,7 +4,8 @@ using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -23,6 +24,9 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenConten
|
||||
public class BookEntityMappingTests
|
||||
{
|
||||
private readonly BookEntityFixture _bookEntityFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
private readonly PaginatedResultDtoFixture<BookEntity> _paginatedResultDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidBookEntity_ShouldMapCorrectly()
|
||||
@@ -297,12 +301,12 @@ public class BookEntityMappingTests
|
||||
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
|
||||
Assert.Equal(bookEntity.ISBNs.Select(i => _isbnDtoFixture.Create(value: i.Value, format: i.Format)), result.ISBNs);
|
||||
Assert.Equal(bookEntity.Ratings.Select(r => _bookRatingDtoFixture.Create(
|
||||
value: r.Value,
|
||||
maxValue: r.MaxValue,
|
||||
source: r.Source,
|
||||
voteCount: r.VoteCount
|
||||
)), result.Ratings);
|
||||
Assert.Equal(bookEntity.CreatedOnUtc, result.CreatedOnUtc);
|
||||
Assert.Equal(bookEntity.UpdatedOnUtc, result.UpdatedOnUtc);
|
||||
@@ -343,21 +347,19 @@ public class BookEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
PaginatedResultDto<BookEntity> paginatedBookEntities = new()
|
||||
{
|
||||
Data = bookEntities,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 2,
|
||||
NumberOfPages = 1
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBookEntities = _paginatedResultDtoFixture.Create(
|
||||
data: bookEntities,
|
||||
currentPage: 1,
|
||||
perPage: 10,
|
||||
count: 2,
|
||||
numberOfPages: 1);
|
||||
|
||||
// Act
|
||||
PaginatedResponse<BookResponse> result = paginatedBookEntities.ToResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(paginatedBookEntities.Data.Count(), result.Data.Count());
|
||||
Assert.Equal(paginatedBookEntities.Data.Count, result.Data.Count);
|
||||
Assert.Equal(paginatedBookEntities.CurrentPage, result.CurrentPage);
|
||||
Assert.Equal(paginatedBookEntities.PerPage, result.PerPage);
|
||||
Assert.Equal(paginatedBookEntities.Count, result.Count);
|
||||
@@ -406,7 +408,7 @@ public class BookEntityMappingTests
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(results);
|
||||
Assert.Equal(bookEntities.Count, results.Count());
|
||||
Assert.Equal(bookEntities.Count, results.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -414,21 +416,19 @@ public class BookEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
PaginatedResultDto<BookEntity> paginatedBookEntities = new()
|
||||
{
|
||||
Data = bookEntities,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 2,
|
||||
NumberOfPages = 1
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBookEntities = _paginatedResultDtoFixture.Create(
|
||||
data: bookEntities,
|
||||
currentPage: 1,
|
||||
perPage: 10,
|
||||
count: 2,
|
||||
numberOfPages: 1);
|
||||
|
||||
// Act
|
||||
PaginatedResponse<BookLiteResponse> result = paginatedBookEntities.ToLiteResponses();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(paginatedBookEntities.Data.Count(), result.Data.Count());
|
||||
Assert.Equal(paginatedBookEntities.Data.Count, result.Data.Count);
|
||||
Assert.Equal(paginatedBookEntities.CurrentPage, result.CurrentPage);
|
||||
Assert.Equal(paginatedBookEntities.PerPage, result.PerPage);
|
||||
Assert.Equal(paginatedBookEntities.Count, result.Count);
|
||||
|
||||
+3
-2
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
@@ -21,6 +21,7 @@ public class BookMetadataDtoMappingTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
private readonly BookMetadataDtoFixture _bookMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenCalledWithValidMetadata_ShouldApplyItAndMarkTheBookAsEnriched()
|
||||
@@ -59,7 +60,7 @@ public class BookMetadataDtoMappingTests
|
||||
title: "The Fellowship of the Ring",
|
||||
goodreadsId: "3") with
|
||||
{
|
||||
Genres = [new GenreDto("")]
|
||||
Genres = [_genreDtoFixture.Create(name: "")]
|
||||
};
|
||||
|
||||
// Act
|
||||
|
||||
+12
-9
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
@@ -19,11 +20,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenConten
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnEntityMappingTests
|
||||
{
|
||||
private readonly IsbnEntityFixture _isbnEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new("0-7475-3269-9", IsbnFormat.Isbn10);
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
@@ -40,7 +43,7 @@ public class IsbnEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentValidIsbnEntities_ShouldMapCorrectly(string value, IsbnFormat format)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new(value, format);
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: value, format: format);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
@@ -58,7 +61,7 @@ public class IsbnEntityMappingTests
|
||||
public void ToResponse_WhenMappingInvalidIsbnEntity_ShouldPreserveValues(string? value, IsbnFormat? format)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new(value, format);
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: value, format: format, includeValue: value is not null);
|
||||
|
||||
// Act
|
||||
IsbnDto result = entity.ToResponse();
|
||||
@@ -72,7 +75,7 @@ public class IsbnEntityMappingTests
|
||||
public void ToDomainEntity_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new("0-7475-3269-9", IsbnFormat.Isbn10);
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = entity.ToDomainEntity();
|
||||
@@ -91,7 +94,7 @@ public class IsbnEntityMappingTests
|
||||
public void ToDomainEntity_WhenMappingInvalidIsbnEntity_ShouldReturnError(string? invalidValue)
|
||||
{
|
||||
// Arrange
|
||||
IsbnEntity entity = new(invalidValue, null);
|
||||
IsbnEntity entity = _isbnEntityFixture.Create(value: invalidValue, includeValue: invalidValue is not null);
|
||||
|
||||
// Act
|
||||
Result<Isbn> result = entity.ToDomainEntity();
|
||||
@@ -106,8 +109,8 @@ public class IsbnEntityMappingTests
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
new IsbnEntity("0-7475-3269-9", IsbnFormat.Isbn10),
|
||||
new IsbnEntity("978-0-7475-3269-9", IsbnFormat.Isbn13)
|
||||
_isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10),
|
||||
_isbnEntityFixture.Create(value: "978-0-7475-3269-9", format: IsbnFormat.Isbn13)
|
||||
];
|
||||
|
||||
// Act
|
||||
@@ -132,8 +135,8 @@ public class IsbnEntityMappingTests
|
||||
// Arrange
|
||||
List<IsbnEntity> entities =
|
||||
[
|
||||
new IsbnEntity("0-7475-3269-9", IsbnFormat.Isbn10),
|
||||
new IsbnEntity("978-0-7475-3269-9", IsbnFormat.Isbn13)
|
||||
_isbnEntityFixture.Create(value: "0-7475-3269-9", format: IsbnFormat.Isbn10),
|
||||
_isbnEntityFixture.Create(value: "978-0-7475-3269-9", format: IsbnFormat.Isbn13)
|
||||
];
|
||||
|
||||
// Act
|
||||
|
||||
+13
-63
@@ -4,10 +4,11 @@ using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.UsersManagement.Users;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
|
||||
using System;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
@@ -21,6 +22,8 @@ namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
|
||||
public class UserMappingTests
|
||||
{
|
||||
private readonly UserFixture _userFixture = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingValidUser_ShouldOnlyUpdateUsername()
|
||||
@@ -28,19 +31,7 @@ public class UserMappingTests
|
||||
// Arrange
|
||||
User domainEntity = _userFixture.Create(username: "newusername");
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
TotpSecret = "totpsecret",
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedOnUtc = null
|
||||
};
|
||||
UserEntity repositoryEntity = _userEntityFixture.Create(username: "oldusername", password: "hashedpassword");
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
@@ -73,18 +64,7 @@ public class UserMappingTests
|
||||
// Arrange
|
||||
User domainEntity = _userFixture.Create(username: newUsername);
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedOnUtc = null
|
||||
};
|
||||
UserEntity repositoryEntity = _userEntityFixture.Create(username: "oldusername", password: "hashedpassword");
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
@@ -102,44 +82,14 @@ public class UserMappingTests
|
||||
|
||||
List<LibraryEntity> libraries =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 1",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations = [],
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 2",
|
||||
LibraryType = LibraryType.Movie,
|
||||
ContentLocations = [],
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
}
|
||||
_libraryEntityFixture.Create(title: "Library 1", libraryType: LibraryType.Book, contentLocations: []),
|
||||
_libraryEntityFixture.Create(title: "Library 2", libraryType: LibraryType.Movie, contentLocations: [])
|
||||
];
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
Libraries = libraries,
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedOnUtc = null
|
||||
};
|
||||
UserEntity repositoryEntity = _userEntityFixture.Create(
|
||||
username: "oldusername",
|
||||
password: "hashedpassword",
|
||||
libraries: libraries);
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
|
||||
+12
-8
@@ -6,6 +6,8 @@ using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPermissions;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Core.Admin.Authorization.Permissions.Queries.GetPermissions;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
@@ -32,6 +34,8 @@ public class GetPermissionsQueryHandlerTests
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly GetPermissionsQueryHandler _sut;
|
||||
private readonly Guid _userId;
|
||||
private readonly GetPermissionsQueryFixture _getPermissionsQueryFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPermissionsQueryHandlerTests"/> class.
|
||||
@@ -57,11 +61,11 @@ public class GetPermissionsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenUserIsAdmin_ShouldReturnPermissions()
|
||||
{
|
||||
// Arrange
|
||||
GetPermissionsQuery query = new();
|
||||
GetPermissionsQuery query = _getPermissionsQueryFixture.Create();
|
||||
IEnumerable<PermissionEntity> permissions =
|
||||
[
|
||||
new PermissionEntity { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanViewUsers },
|
||||
new PermissionEntity { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanDeleteUsers }
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers),
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers)
|
||||
];
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -83,7 +87,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenUserIsNotAdmin_ShouldReturnNotAuthorizedError()
|
||||
{
|
||||
// Arrange
|
||||
GetPermissionsQuery query = new();
|
||||
GetPermissionsQuery query = _getPermissionsQueryFixture.Create();
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(false);
|
||||
@@ -102,7 +106,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenUserIsNotAuthenticated_ShouldReturnNotAuthorizedError()
|
||||
{
|
||||
// Arrange
|
||||
GetPermissionsQuery query = new();
|
||||
GetPermissionsQuery query = _getPermissionsQueryFixture.Create();
|
||||
_mockCurrentUserService.UserId.Returns((Guid?)null);
|
||||
|
||||
// Act
|
||||
@@ -119,7 +123,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenGetAllPermissionsReturnsError_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
GetPermissionsQuery query = new();
|
||||
GetPermissionsQuery query = _getPermissionsQueryFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to retrieve permissions");
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -141,10 +145,10 @@ public class GetPermissionsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenCancellationRequested_ShouldStillCompleteOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetPermissionsQuery query = new();
|
||||
GetPermissionsQuery query = _getPermissionsQueryFixture.Create();
|
||||
IEnumerable<PermissionEntity> permissions =
|
||||
[
|
||||
new PermissionEntity { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanViewUsers }
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)
|
||||
];
|
||||
CancellationToken cancellationToken = new(true);
|
||||
|
||||
|
||||
+11
-16
@@ -7,12 +7,14 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -33,6 +35,9 @@ public class AddRoleCommandHandlerTests
|
||||
private readonly IRoleRepository _mockRoleRepository;
|
||||
private readonly AddRoleCommandHandler _sut;
|
||||
private readonly AddRoleCommandFixture _addRoleCommandFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
/// <summary>
|
||||
@@ -163,22 +168,12 @@ public class AddRoleCommandHandlerTests
|
||||
// Arrange
|
||||
AddRoleCommand command = _addRoleCommandFixture.Create();
|
||||
Guid roleId = Guid.NewGuid();
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = roleId,
|
||||
RoleName = command.RoleName,
|
||||
RolePermissions = [.. command.Permissions.Select(p => new RolePermissionEntity
|
||||
{
|
||||
RoleId = roleId,
|
||||
PermissionId = p,
|
||||
Role = null!,
|
||||
Permission = new()
|
||||
{
|
||||
Id = p,
|
||||
PermissionName = AuthorizationPermission.CanViewUsers
|
||||
}
|
||||
})]
|
||||
};
|
||||
List<RolePermissionEntity> rolePermissions = [.. command.Permissions.Select(permissionId =>
|
||||
_rolePermissionEntityFixture.Create(
|
||||
roleId: roleId,
|
||||
permissionId: permissionId,
|
||||
permission: _permissionEntityFixture.Create(id: permissionId, permissionName: AuthorizationPermission.CanViewUsers)))];
|
||||
RoleEntity role = _roleEntityFixture.Create(id: roleId, roleName: command.RoleName, includeRolePermissions: true, rolePermissions: rolePermissions);
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
+5
-3
@@ -7,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using NSubstitute;
|
||||
@@ -30,6 +31,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
private readonly IRoleRepository _mockRoleRepository;
|
||||
private readonly DeleteRoleCommandHandler _sut;
|
||||
private readonly DeleteRoleCommandFixture _deleteRoleCommandFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
/// <summary>
|
||||
@@ -115,7 +117,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleCommand command = _deleteRoleCommandFixture.Create();
|
||||
RoleEntity adminRole = new() { Id = command.RoleId, RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(id: command.RoleId, roleName: "Admin");
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
@@ -157,7 +159,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleCommand command = _deleteRoleCommandFixture.Create();
|
||||
RoleEntity role = new() { Id = command.RoleId, RoleName = "TestRole" };
|
||||
RoleEntity role = _roleEntityFixture.Create(id: command.RoleId, roleName: "TestRole");
|
||||
Error error = Error.Failure("Database.Error", "Failed to delete role");
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -181,7 +183,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleCommand command = _deleteRoleCommandFixture.Create();
|
||||
RoleEntity role = new() { Id = command.RoleId, RoleName = "TestRole" };
|
||||
RoleEntity role = _roleEntityFixture.Create(id: command.RoleId, roleName: "TestRole");
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
+11
-16
@@ -7,12 +7,14 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -33,6 +35,9 @@ public class UpdateRoleCommandHandlerTests
|
||||
private readonly IRoleRepository _mockRoleRepository;
|
||||
private readonly UpdateRoleCommandHandler _sut;
|
||||
private readonly UpdateRoleCommandFixture _updateRoleCommandFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
/// <summary>
|
||||
@@ -162,22 +167,12 @@ public class UpdateRoleCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleCommand command = _updateRoleCommandFixture.Create();
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = command.RoleId,
|
||||
RoleName = command.RoleName,
|
||||
RolePermissions = [.. command.Permissions.Select(p => new RolePermissionEntity
|
||||
{
|
||||
RoleId = command.RoleId,
|
||||
PermissionId = p,
|
||||
Role = null!,
|
||||
Permission = new()
|
||||
{
|
||||
Id = p,
|
||||
PermissionName = AuthorizationPermission.CanViewUsers
|
||||
}
|
||||
})]
|
||||
};
|
||||
List<RolePermissionEntity> rolePermissions = [.. command.Permissions.Select(permissionId =>
|
||||
_rolePermissionEntityFixture.Create(
|
||||
roleId: command.RoleId,
|
||||
permissionId: permissionId,
|
||||
permission: _permissionEntityFixture.Create(id: permissionId, permissionName: AuthorizationPermission.CanViewUsers)))];
|
||||
RoleEntity role = _roleEntityFixture.Create(id: command.RoleId, roleName: command.RoleName, includeRolePermissions: true, rolePermissions: rolePermissions);
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
+13
-18
@@ -7,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -32,6 +33,9 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
private readonly IRoleRepository _mockRoleRepository;
|
||||
private readonly GetRolePermissionsQueryHandler _sut;
|
||||
private readonly GetRolePermissionsQueryFixture _getRolePermissionsQueryFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
/// <summary>
|
||||
@@ -136,25 +140,16 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetRolePermissionsQuery query = _getRolePermissionsQueryFixture.Create();
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = query.RoleId,
|
||||
RoleName = "TestRole",
|
||||
RolePermissions =
|
||||
RoleEntity role = _roleEntityFixture.Create(
|
||||
id: query.RoleId,
|
||||
roleName: "TestRole",
|
||||
rolePermissions:
|
||||
[
|
||||
new()
|
||||
{
|
||||
RoleId = query.RoleId,
|
||||
PermissionId = Guid.NewGuid(),
|
||||
Role = null!,
|
||||
Permission = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
PermissionName = AuthorizationPermission.CanViewUsers
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
_rolePermissionEntityFixture.Create(
|
||||
roleId: query.RoleId,
|
||||
permission: _permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers))
|
||||
],
|
||||
includeRolePermissions: true);
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
+4
-2
@@ -6,6 +6,7 @@ using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Queries.GetRoles;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -31,6 +32,7 @@ public class GetRolesQueryHandlerTests
|
||||
private readonly IRoleRepository _mockRoleRepository;
|
||||
private readonly GetRolesQueryHandler _sut;
|
||||
private readonly GetRolesQueryFixture _getRolesQueryFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
/// <summary>
|
||||
@@ -114,8 +116,8 @@ public class GetRolesQueryHandlerTests
|
||||
GetRolesQuery query = _getRolesQueryFixture.Create();
|
||||
IEnumerable<RoleEntity> roles =
|
||||
[
|
||||
new RoleEntity { Id = Guid.NewGuid(), RoleName = "Admin" },
|
||||
new RoleEntity { Id = Guid.NewGuid(), RoleName = "User" }
|
||||
_roleEntityFixture.Create(roleName: "Admin"),
|
||||
_roleEntityFixture.Create(roleName: "User")
|
||||
];
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
|
||||
+4
-2
@@ -4,6 +4,7 @@ using AutoFixture.AutoNSubstitute;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
@@ -30,6 +31,7 @@ public class GetPathParentQueryHandlerTests
|
||||
private readonly GetPathParentQueryHandler _sut;
|
||||
private readonly PathSegmentFixture _pathSegmentFixture = new();
|
||||
private readonly GetPathParentQueryFixture _getPathParentQueryFixture = new();
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture = new();
|
||||
|
||||
public GetPathParentQueryHandlerTests()
|
||||
{
|
||||
@@ -50,7 +52,7 @@ public class GetPathParentQueryHandlerTests
|
||||
IEnumerable<PathSegment> pathSegments = _pathSegmentFixture.CreateMany();
|
||||
|
||||
// Create PathSegmentResponses based on the PathSegments
|
||||
IEnumerable<PathSegmentResponse> pathSegmentResponses = pathSegments.Select(segment => new PathSegmentResponse(segment.Name));
|
||||
IEnumerable<PathSegmentResponse> pathSegmentResponses = pathSegments.Select(segment => _pathSegmentResponseFixture.Create(path: segment.Name));
|
||||
|
||||
_mockPathService.GoUpOneLevel(query.Path!)
|
||||
.Returns(Result.From(pathSegments));
|
||||
@@ -60,7 +62,7 @@ public class GetPathParentQueryHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.IsAssignableFrom<IEnumerable<PathSegmentResponse>>(result.Value);
|
||||
Assert.IsType<IEnumerable<PathSegmentResponse>>(result.Value, exactMatch: false);
|
||||
Assert.Equal(pathSegmentResponses, result.Value);
|
||||
_mockPathService.Received(1).GoUpOneLevel(query.Path!);
|
||||
}
|
||||
|
||||
+5
-3
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
|
||||
using Lumina.Contracts.Responses.UsersManagement;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using NSubstitute;
|
||||
@@ -25,6 +26,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly IUserRepository _mockUserRepository;
|
||||
private readonly CheckInitializationQueryHandler _sut;
|
||||
private readonly CheckInitializationQueryFixture _checkInitializationQueryFixture = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -49,7 +51,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(Result.From(users.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(_checkInitializationQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsInitialized);
|
||||
@@ -64,7 +66,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(_checkInitializationQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
@@ -80,7 +82,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(_checkInitializationQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
|
||||
+8
-8
@@ -7,7 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrariesScan;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.CancelLibrariesScan;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
@@ -15,7 +15,6 @@ using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -35,6 +34,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IDomainEventsQueue _mockDomainEventsQueue;
|
||||
private readonly CancelLibrariesScanCommandHandler _sut;
|
||||
private readonly CancelLibrariesScanCommandFixture _cancelLibrariesScanCommandFixture = new();
|
||||
private readonly LibraryScanEntityFixture _libraryScanEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
_mockLibraryScanRepository.GetRunningScansAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryScanEntity>>(runningScans));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(new CancelLibrariesScanCommand(), CancellationToken.None);
|
||||
Result<Success> result = await _sut.HandleAsync(_cancelLibrariesScanCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -96,7 +96,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(new CancelLibrariesScanCommand(), CancellationToken.None);
|
||||
Result<Success> result = await _sut.HandleAsync(_cancelLibrariesScanCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -111,7 +111,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns((Guid?)null);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(new CancelLibrariesScanCommand(), CancellationToken.None);
|
||||
Result<Success> result = await _sut.HandleAsync(_cancelLibrariesScanCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -128,7 +128,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get running scans"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(new CancelLibrariesScanCommand(), CancellationToken.None);
|
||||
Result<Success> result = await _sut.HandleAsync(_cancelLibrariesScanCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -146,7 +146,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to update library scan"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(new CancelLibrariesScanCommand(), CancellationToken.None);
|
||||
Result<Success> result = await _sut.HandleAsync(_cancelLibrariesScanCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -161,7 +161,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
_mockLibraryScanRepository.GetRunningScansAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryScanEntity>>(runningScans));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(new CancelLibrariesScanCommand(), CancellationToken.None);
|
||||
Result<Success> result = await _sut.HandleAsync(_cancelLibrariesScanCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+10
-9
@@ -7,8 +7,8 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibraries;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Commands.ScanLibraries;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using NSubstitute;
|
||||
@@ -37,6 +37,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IDomainEventsQueue _mockDomainEventsQueue;
|
||||
private readonly ScanLibrariesCommandHandler _sut;
|
||||
private readonly ScanLibrariesCommandFixture _scanLibrariesCommandFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly LibraryScanEntityFixture _libraryScanEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
@@ -79,7 +80,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
_mockLibraryRepository.GetAllEnabledAndUnlockedAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryEntity>>(libraries));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -105,7 +106,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -122,7 +123,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns((Guid?)null);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -139,7 +140,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get libraries"));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -161,7 +162,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
.Returns(Result.From<IEnumerable<LibraryScanEntity>>([runningScan]));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -181,7 +182,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to insert library scan"));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -198,7 +199,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get past month scans"));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -214,7 +215,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
_mockLibraryRepository.GetAllEnabledAndUnlockedAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryEntity>>(libraries));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(new ScanLibrariesCommand(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanResponse>> result = await _sut.HandleAsync(_scanLibrariesCommandFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+6
-5
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
using Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
@@ -30,6 +31,7 @@ public class LibraryDeletedDomainEventHandlerTests
|
||||
private readonly IPathService _mockPathService;
|
||||
private readonly LibraryDeletedDomainEventHandler _sut;
|
||||
private readonly LibraryFixture _libraryFixture = new();
|
||||
private readonly MediaSettingsDtoFixture _mediaSettingsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryDeletedDomainEventHandlerTests"/> class.
|
||||
@@ -41,11 +43,10 @@ public class LibraryDeletedDomainEventHandlerTests
|
||||
_mockEnvironmentContext.DirectoryProviderService.Returns(_mockDirectoryProviderService);
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
|
||||
MediaSettingsDto mediaSettings = new()
|
||||
{
|
||||
RootDirectory = "Media",
|
||||
LibrariesDirectory = "Libraries"
|
||||
};
|
||||
MediaSettingsDto mediaSettings = _mediaSettingsDtoFixture.Create(
|
||||
rootDirectory: "Media",
|
||||
librariesDirectory: "Libraries",
|
||||
booksDirectory: "Books");
|
||||
IOptions<MediaSettingsDto> mediaSettingsOptions = Substitute.For<IOptions<MediaSettingsDto>>();
|
||||
mediaSettingsOptions.Value.Returns(mediaSettings);
|
||||
|
||||
|
||||
+6
-5
@@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
@@ -44,6 +45,7 @@ public class LibrarySavedDomainEventHandlerTests
|
||||
private readonly LibraryFixture _libraryFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly FileSystemPathIdFixture _fileSystemPathIdFixture = new();
|
||||
private readonly MediaSettingsDtoFixture _mediaSettingsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibrarySavedDomainEventHandlerTests"/> class.
|
||||
@@ -62,11 +64,10 @@ public class LibrarySavedDomainEventHandlerTests
|
||||
_mockEnvironmentContext.FileTypeService.Returns(_mockFileTypeService);
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
|
||||
MediaSettingsDto mediaSettings = new()
|
||||
{
|
||||
RootDirectory = "Media",
|
||||
LibrariesDirectory = "Libraries"
|
||||
};
|
||||
MediaSettingsDto mediaSettings = _mediaSettingsDtoFixture.Create(
|
||||
rootDirectory: "Media",
|
||||
librariesDirectory: "Libraries",
|
||||
booksDirectory: "Books");
|
||||
IOptions<MediaSettingsDto> mediaSettingsOptions = Substitute.For<IOptions<MediaSettingsDto>>();
|
||||
mediaSettingsOptions.Value.Returns(mediaSettings);
|
||||
|
||||
|
||||
+6
-8
@@ -5,8 +5,8 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
@@ -14,13 +14,12 @@ using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.Library
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Events;
|
||||
@@ -52,7 +51,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
|
||||
// default stubs: the scanning service starts the scan successfully
|
||||
_mockMediaLibraryScanningService.StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<bool>(), Arg.Any<CancellationToken>())
|
||||
_mockMediaLibraryScanningService.StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
|
||||
_sut = new LibraryScanQueuedDomainEventHandler(_mockMediaLibraryScanningService, _mockDomainEventsQueue, _mockUnitOfWork);
|
||||
@@ -74,7 +73,6 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
await _mockMediaLibraryScanningService.Received(1).StartScanAsync(
|
||||
Arg.Is<LibraryScan>(libraryScan => libraryScan.Id.Value == scan.Id),
|
||||
scan.Library.LibraryType,
|
||||
scan.Library.DownloadMetadataFromWeb,
|
||||
Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -93,7 +91,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.Equal(error, exception.EventualConsistencyError);
|
||||
await _mockMediaLibraryScanningService.DidNotReceive().StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<bool>(), Arg.Any<CancellationToken>());
|
||||
await _mockMediaLibraryScanningService.DidNotReceive().StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -110,7 +108,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.Equal(DomainErrors.LibraryScanning.LibraryScanNotFound, exception.EventualConsistencyError);
|
||||
await _mockMediaLibraryScanningService.DidNotReceive().StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<bool>(), Arg.Any<CancellationToken>());
|
||||
await _mockMediaLibraryScanningService.DidNotReceive().StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -122,7 +120,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
Error error = Error.Failure(description: "Failed to start scan");
|
||||
_mockMediaLibraryScanningService.StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<bool>(), Arg.Any<CancellationToken>())
|
||||
_mockMediaLibraryScanningService.StartScanAsync(Arg.Any<LibraryScan>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
|
||||
+6
-5
@@ -7,13 +7,13 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetEnabledLibraries;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Queries.GetEnabledLibraries;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -31,6 +31,7 @@ public class GetEnabledLibrariesQueryHandlerTests
|
||||
private readonly IAuthorizationService _mockAuthorizationService;
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly GetEnabledLibrariesQueryHandler _sut;
|
||||
private readonly GetEnabledLibrariesQueryFixture _getEnabledLibrariesQueryFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
@@ -65,7 +66,7 @@ public class GetEnabledLibrariesQueryHandlerTests
|
||||
_mockLibraryRepository.GetAllEnabledAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryEntity>>(libraries));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetEnabledLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getEnabledLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -88,7 +89,7 @@ public class GetEnabledLibrariesQueryHandlerTests
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetEnabledLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getEnabledLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -103,7 +104,7 @@ public class GetEnabledLibrariesQueryHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns((Guid?)null);
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetEnabledLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getEnabledLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -119,7 +120,7 @@ public class GetEnabledLibrariesQueryHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get enabled libraries"));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetEnabledLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getEnabledLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+6
-5
@@ -7,13 +7,13 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraries;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Queries.GetLibraries;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -31,6 +31,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
private readonly IAuthorizationService _mockAuthorizationService;
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly GetLibrariesQueryHandler _sut;
|
||||
private readonly GetLibrariesQueryFixture _getLibrariesQueryFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
@@ -65,7 +66,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
_mockLibraryRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryEntity>>(libraries));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -88,7 +89,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -103,7 +104,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns((Guid?)null);
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -119,7 +120,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get libraries"));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(new GetLibrariesQuery(), CancellationToken.None);
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+3
-12
@@ -7,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Queries.GetLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -14,7 +15,6 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,6 +38,7 @@ public class GetLibraryQueryHandlerTests
|
||||
private readonly GetLibraryQueryHandler _sut;
|
||||
private readonly Guid _userId;
|
||||
private readonly GetLibraryQueryFixture _getLibraryQueryFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryQueryHandlerTests"/> class.
|
||||
@@ -57,17 +58,7 @@ public class GetLibraryQueryHandlerTests
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From((LibraryEntity?)new LibraryEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = _userId,
|
||||
Title = "Test Library",
|
||||
LibraryType = LibraryType.EBook,
|
||||
ContentLocations = [],
|
||||
CreatedBy = _userId,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = null
|
||||
}));
|
||||
.Returns(Result.From((LibraryEntity?)_libraryEntityFixture.Create(userId: _userId, title: "Test Library", libraryType: LibraryType.EBook, contentLocations: [])));
|
||||
_mockValidator.Validate(Arg.Any<GetLibraryQuery>()).Returns([]);
|
||||
|
||||
_sut = new GetLibraryQueryHandler(_mockAuthorizationService, _mockCurrentUserService, _mockUnitOfWork, _mockValidator);
|
||||
|
||||
+7
-5
@@ -7,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetRunningLibraryScans;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.Management.Queries.GetRunningLibraryScans;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress;
|
||||
@@ -37,6 +38,7 @@ public class GetRunningLibraryScansQueryHandlerTests
|
||||
private readonly ICurrentUserService _mockCurrentUserService;
|
||||
private readonly IMediaLibrariesScanProgressTracker _mockMediaLibrariesScanProgressTracker;
|
||||
private readonly GetRunningLibraryScansQueryHandler _sut;
|
||||
private readonly GetRunningLibraryScansQueryFixture _getRunningLibraryScansQueryFixture = new();
|
||||
private readonly LibraryScanEntityFixture _libraryScanEntityFixture = new();
|
||||
private readonly MediaLibraryScanProgressFixture _mediaLibraryScanProgressFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
@@ -80,7 +82,7 @@ public class GetRunningLibraryScansQueryHandlerTests
|
||||
_mockLibraryScanRepository.GetRunningScansAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryScanEntity>>(runningScans));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(new GetRunningLibraryScansQuery(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(_getRunningLibraryScansQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -100,7 +102,7 @@ public class GetRunningLibraryScansQueryHandlerTests
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(new GetRunningLibraryScansQuery(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(_getRunningLibraryScansQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -114,7 +116,7 @@ public class GetRunningLibraryScansQueryHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns((Guid?)null);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(new GetRunningLibraryScansQuery(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(_getRunningLibraryScansQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -130,7 +132,7 @@ public class GetRunningLibraryScansQueryHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get running scans"));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(new GetRunningLibraryScansQuery(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(_getRunningLibraryScansQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -146,7 +148,7 @@ public class GetRunningLibraryScansQueryHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get scan progress"));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(new GetRunningLibraryScansQuery(), CancellationToken.None);
|
||||
Result<IEnumerable<MediaLibraryScanProgressResponse>> result = await _sut.HandleAsync(_getRunningLibraryScansQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+17
-16
@@ -8,8 +8,8 @@ using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.Fixtures.Common.Setup;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -34,6 +34,12 @@ public class AddBookCommandHandlerTests
|
||||
private readonly IBookRepository _mockBookRepository;
|
||||
private readonly AddBookCommandHandler _sut;
|
||||
private readonly AddBookCommandFixture _commandBookFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly LanguageInfoDtoFixture _languageInfoDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddBookCommandHandlerTests"/> class.
|
||||
@@ -98,7 +104,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.Create();
|
||||
bookCommand = bookCommand with { ISBNs = [new IsbnDto("invalid", IsbnFormat.Isbn13)] };
|
||||
bookCommand = bookCommand with { ISBNs = [_isbnDtoFixture.Create(value: "invalid", format: IsbnFormat.Isbn13)] };
|
||||
|
||||
// Act
|
||||
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
@@ -115,7 +121,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.Create();
|
||||
bookCommand = bookCommand with { Ratings = [new BookRatingDto(-1, 5, null, null)] };
|
||||
bookCommand = bookCommand with { Ratings = [_bookRatingDtoFixture.Create(value: -1, maxValue: 5, includeOptionalProperties: false)] };
|
||||
|
||||
// Act
|
||||
Result<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
@@ -136,7 +142,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Genres = [new GenreDto("")]
|
||||
Genres = [_genreDtoFixture.Create(name: "")]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -159,7 +165,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Tags = [new TagDto("")]
|
||||
Tags = [_tagDtoFixture.Create(name: "")]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -182,14 +188,9 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
ReleaseInfo = new ReleaseInfoDto(
|
||||
OriginalReleaseDate: new DateOnly(2025, 1, 1),
|
||||
ReReleaseDate: new DateOnly(2024, 1, 1),
|
||||
OriginalReleaseYear: null,
|
||||
ReReleaseYear: null,
|
||||
ReleaseCountry: null,
|
||||
ReleaseVersion: null
|
||||
)
|
||||
ReleaseInfo = _releaseInfoDtoFixture.Create(
|
||||
originalReleaseDate: new DateOnly(2025, 1, 1),
|
||||
reReleaseDate: new DateOnly(2024, 1, 1))
|
||||
}
|
||||
};
|
||||
|
||||
@@ -212,7 +213,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Language = new LanguageInfoDto("", "English", null)
|
||||
Language = _languageInfoDtoFixture.Create(languageCode: "", languageName: "English")
|
||||
}
|
||||
};
|
||||
|
||||
@@ -235,7 +236,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
OriginalLanguage = new LanguageInfoDto("", "English", null)
|
||||
OriginalLanguage = _languageInfoDtoFixture.Create(languageCode: "", languageName: "English")
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+14
@@ -1881,4 +1881,18 @@ public class AddBookCommandValidatorTests
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationError(Errors.Metadata.RatingVoteCountMustBePositive);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenLibraryIdIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.Create();
|
||||
bookCommand = bookCommand with { LibraryId = Guid.Empty };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.WrittenContent.BookLibraryCannotBeNull);
|
||||
}
|
||||
}
|
||||
+9
-41
@@ -2,12 +2,15 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
@@ -18,12 +21,9 @@ using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
|
||||
@@ -43,6 +43,7 @@ public class GetBooksQueryHandlerTests
|
||||
private readonly Guid _userId;
|
||||
private readonly BookEntityFixture _bookEntityFixture = new();
|
||||
private readonly GetBooksQueryFixture _getBooksQueryFixture = new();
|
||||
private readonly PaginatedResultDtoFixture<BookEntity> _paginatedResultDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetBooksQueryHandlerTests"/> class.
|
||||
@@ -73,14 +74,7 @@ public class GetBooksQueryHandlerTests
|
||||
GetBooksQuery query = _getBooksQueryFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = bookEntities,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 2,
|
||||
NumberOfPages = 1
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: bookEntities, currentPage: 1, perPage: 10, count: 2, numberOfPages: 1);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
@@ -106,14 +100,7 @@ public class GetBooksQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksQuery query = _getBooksQueryFixture.Create();
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = [],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 0,
|
||||
NumberOfPages = 0
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
@@ -157,14 +144,7 @@ public class GetBooksQueryHandlerTests
|
||||
// Arrange
|
||||
GetBooksQuery query = _getBooksQueryFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = [],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 0,
|
||||
NumberOfPages = 0
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
@@ -190,20 +170,8 @@ public class GetBooksQueryHandlerTests
|
||||
public async Task HandleAsync_WhenQueryHasNoPaginationData_ShouldQueryRepositoryWithoutPagination()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksQuery query = new(
|
||||
PaginationData: null,
|
||||
Filter: new LibraryFilterDto { LibraryId = Guid.NewGuid() },
|
||||
SortBy: null,
|
||||
SortOrder: SortOrder.Ascending
|
||||
);
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = [],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 0,
|
||||
NumberOfPages = 0
|
||||
};
|
||||
GetBooksQuery query = _getBooksQueryFixture.Create(includePaginationData: false, libraryId: Guid.NewGuid(), sortOrder: SortOrder.Ascending);
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
|
||||
+9
-41
@@ -2,12 +2,15 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
@@ -18,12 +21,9 @@ using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
|
||||
@@ -43,6 +43,7 @@ public class GetBooksLiteQueryHandlerTests
|
||||
private readonly Guid _userId;
|
||||
private readonly BookEntityFixture _bookEntityFixture = new();
|
||||
private readonly GetBooksLiteQueryFixture _getBooksLiteQueryFixture = new();
|
||||
private readonly PaginatedResultDtoFixture<BookEntity> _paginatedResultDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetBooksLiteQueryHandlerTests"/> class.
|
||||
@@ -73,14 +74,7 @@ public class GetBooksLiteQueryHandlerTests
|
||||
GetBooksLiteQuery query = _getBooksLiteQueryFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<BookEntity> bookEntities = _bookEntityFixture.CreateMany(2);
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = bookEntities,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 2,
|
||||
NumberOfPages = 1
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: bookEntities, currentPage: 1, perPage: 10, count: 2, numberOfPages: 1);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
@@ -106,14 +100,7 @@ public class GetBooksLiteQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteQuery query = _getBooksLiteQueryFixture.Create();
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = [],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 0,
|
||||
NumberOfPages = 0
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
@@ -157,14 +144,7 @@ public class GetBooksLiteQueryHandlerTests
|
||||
// Arrange
|
||||
GetBooksLiteQuery query = _getBooksLiteQueryFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = [],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 0,
|
||||
NumberOfPages = 0
|
||||
};
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
@@ -190,20 +170,8 @@ public class GetBooksLiteQueryHandlerTests
|
||||
public async Task HandleAsync_WhenQueryHasNoPaginationData_ShouldQueryRepositoryWithoutPagination()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteQuery query = new(
|
||||
PaginationData: null,
|
||||
Filter: new LibraryFilterDto { LibraryId = Guid.NewGuid() },
|
||||
SortBy: null,
|
||||
SortOrder: SortOrder.Ascending
|
||||
);
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = new()
|
||||
{
|
||||
Data = [],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 0,
|
||||
NumberOfPages = 0
|
||||
};
|
||||
GetBooksLiteQuery query = _getBooksLiteQueryFixture.Create(includePaginationData: false, libraryId: Guid.NewGuid(), sortOrder: SortOrder.Ascending);
|
||||
PaginatedResultDto<BookEntity> paginatedBooks = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0);
|
||||
_mockBookRepository.GetPaginatedAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
|
||||
+7
-5
@@ -4,13 +4,14 @@ using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Fixtures.Core.Plugins.Queries.GetPlugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.Plugins.Queries.GetPlugins;
|
||||
@@ -24,6 +25,8 @@ public class GetPluginsQueryHandlerTests
|
||||
private readonly IUnitOfWork _mockUnitOfWork;
|
||||
private readonly IPluginRepository _mockPluginRepository;
|
||||
private readonly GetPluginsQueryHandler _sut;
|
||||
private readonly GetPluginsQueryFixture _getPluginsQueryFixture = new();
|
||||
private readonly PluginEntityFixture _pluginEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPluginsQueryHandlerTests"/> class.
|
||||
@@ -40,12 +43,11 @@ public class GetPluginsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenCalled_ShouldReturnAllDetectedPlugins()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntityFixture pluginFixture = new();
|
||||
List<PluginEntity> plugins = [pluginFixture.Create(), pluginFixture.Create()];
|
||||
List<PluginEntity> plugins = [_pluginEntityFixture.Create(), _pluginEntityFixture.Create()];
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
|
||||
Result<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(_getPluginsQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -62,7 +64,7 @@ public class GetPluginsQueryHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get plugins"));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
|
||||
Result<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(_getPluginsQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+3
-4
@@ -2,18 +2,16 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Lumina.Application.Common.Infrastructure.Themes;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemeArchive;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -35,6 +33,7 @@ public class GetThemeArchiveQueryHandlerTests
|
||||
private readonly GetThemeArchiveQueryHandler _sut;
|
||||
private readonly GetThemeArchiveQueryFixture _getThemeArchiveQueryFixture = new();
|
||||
private readonly ThemeEntityFixture _themeEntityFixture = new();
|
||||
private readonly ThemeArchiveDtoFixture _themeArchiveDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeArchiveQueryHandlerTests"/> class.
|
||||
@@ -136,7 +135,7 @@ public class GetThemeArchiveQueryHandlerTests
|
||||
_mockThemeRepository.GetByThemeIdAsync(query.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeService.BuildArchiveAsync(theme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new ThemeArchiveDto(bytes, fileName, contentType)));
|
||||
.Returns(Result.From(_themeArchiveDtoFixture.Create(bytes: bytes, fileName: fileName, contentType: contentType)));
|
||||
|
||||
// Act
|
||||
Result<ThemeArchiveResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
+4
-5
@@ -2,19 +2,17 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Lumina.Application.Common.Infrastructure.Themes;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemeAsset;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -36,6 +34,7 @@ public class GetThemeAssetQueryHandlerTests
|
||||
private readonly GetThemeAssetQueryHandler _sut;
|
||||
private readonly GetThemeAssetQueryFixture _getThemeAssetQueryFixture = new();
|
||||
private readonly ThemeEntityFixture _themeEntityFixture = new();
|
||||
private readonly ThemeAssetDtoFixture _themeAssetDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThemeAssetQueryHandlerTests"/> class.
|
||||
@@ -135,7 +134,7 @@ public class GetThemeAssetQueryHandlerTests
|
||||
_mockThemeRepository.GetByThemeIdAsync(query.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeService.GetAssetAsync(theme.ThemeId, query.AssetPath!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new ThemeAssetDto(bytes, contentType)));
|
||||
.Returns(Result.From(_themeAssetDtoFixture.Create(bytes: bytes, contentType: contentType)));
|
||||
|
||||
// Act
|
||||
Result<ThemeAssetResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -203,7 +202,7 @@ public class GetThemeAssetQueryHandlerTests
|
||||
_mockThemeRepository.GetByThemeIdAsync(query.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeService.GetAssetAsync(theme.ThemeId, query.AssetPath!, Arg.Any<CancellationToken>())
|
||||
.Returns(assetError, Result.From(new ThemeAssetDto(restoredBytes, contentType)));
|
||||
.Returns(assetError, Result.From(_themeAssetDtoFixture.Create(bytes: restoredBytes, contentType: contentType)));
|
||||
_mockThemeService.RestoreBundledThemeAsync(theme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
|
||||
|
||||
+42
-76
@@ -8,6 +8,7 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
@@ -40,7 +41,11 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
private readonly IPermissionRepository _mockPermissionRepository;
|
||||
private readonly UpdateUserRoleAndPermissionsCommandHandler _sut;
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly UserRoleEntityFixture _userRoleEntityFixture = new();
|
||||
private readonly UserPermissionEntityFixture _userPermissionEntityFixture = new();
|
||||
private readonly UpdateUserRoleAndPermissionsCommandFixture _updateUserRoleAndPermissionsCommandFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
/// <summary>
|
||||
@@ -150,28 +155,18 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsCommand command = _updateUserRoleAndPermissionsCommandFixture.Create(roleId: Guid.NewGuid());
|
||||
RoleEntity adminRole = new() { RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
Guid userId = Guid.NewGuid();
|
||||
UserRoleEntity userRole = _userRoleEntityFixture.Create(userId: userId, role: adminRole);
|
||||
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = userId,
|
||||
Username = "testAdmin",
|
||||
Password = "hashedPassword",
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = new UserRoleEntity
|
||||
{
|
||||
UserId = userId,
|
||||
RoleId = Guid.NewGuid(),
|
||||
User = null!,
|
||||
Role = adminRole
|
||||
},
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = userId
|
||||
};
|
||||
UserEntity user = _userEntityFixture.Create(
|
||||
id: userId,
|
||||
username: "testAdmin",
|
||||
password: "hashedPassword",
|
||||
userRole: userRole,
|
||||
includeUserRole: true);
|
||||
|
||||
RoleEntity newRole = new() { RoleName = "User" };
|
||||
RoleEntity newRole = _roleEntityFixture.Create(roleName: "User");
|
||||
IEnumerable<UserEntity> users = [user];
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -197,9 +192,9 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsCommand command = _updateUserRoleAndPermissionsCommandFixture.Create(roleId: Guid.NewGuid());
|
||||
UserEntity user = _userEntityFixture.Create();
|
||||
RoleEntity role = new() { RoleName = "TestRole" };
|
||||
IEnumerable<PermissionEntity> permissions = command.Permissions.Select(p =>
|
||||
new PermissionEntity { Id = p, PermissionName = AuthorizationPermission.CanViewUsers });
|
||||
RoleEntity role = _roleEntityFixture.Create(roleName: "TestRole");
|
||||
IEnumerable<PermissionEntity> permissions = command.Permissions.Select(permissionId =>
|
||||
_permissionEntityFixture.Create(id: permissionId, permissionName: AuthorizationPermission.CanViewUsers));
|
||||
Error error = Error.Failure("Database.Error", "Failed to update user");
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -227,30 +222,18 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsCommand command = _updateUserRoleAndPermissionsCommandFixture.Create(roleId: Guid.NewGuid());
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = command.UserId,
|
||||
Username = "testUser",
|
||||
Password = "hashedPassword",
|
||||
Libraries = [],
|
||||
UserPermissions = [.. command.Permissions.Select((p, i) => new UserPermissionEntity
|
||||
{
|
||||
UserId = command.UserId,
|
||||
PermissionId = p,
|
||||
User = null!,
|
||||
Permission = new PermissionEntity
|
||||
{
|
||||
Id = p,
|
||||
PermissionName = (AuthorizationPermission)(i + 1)
|
||||
}
|
||||
})],
|
||||
UserRole = null,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = command.UserId
|
||||
};
|
||||
RoleEntity role = new() { RoleName = "TestRole" };
|
||||
IEnumerable<PermissionEntity> permissions = command.Permissions.Select((p, i) =>
|
||||
new PermissionEntity { Id = p, PermissionName = (AuthorizationPermission)(i + 1) });
|
||||
UserEntity user = _userEntityFixture.Create(id: command.UserId, username: "testUser", password: "hashedPassword");
|
||||
|
||||
List<UserPermissionEntity> userPermissions = [.. command.Permissions.Select((permissionId, index) =>
|
||||
_userPermissionEntityFixture.Create(
|
||||
user: user,
|
||||
permission: _permissionEntityFixture.Create(id: permissionId, permissionName: (AuthorizationPermission)(index + 1))))];
|
||||
foreach (UserPermissionEntity userPermission in userPermissions)
|
||||
user.UserPermissions.Add(userPermission);
|
||||
|
||||
RoleEntity role = _roleEntityFixture.Create(roleName: "TestRole");
|
||||
IEnumerable<PermissionEntity> permissions = command.Permissions.Select((permissionId, index) =>
|
||||
_permissionEntityFixture.Create(id: permissionId, permissionName: (AuthorizationPermission)(index + 1)));
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
@@ -279,23 +262,16 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsCommand command = _updateUserRoleAndPermissionsCommandFixture.Create(roleId: Guid.NewGuid());
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = command.UserId,
|
||||
Username = "testUser",
|
||||
Password = "hashedPassword",
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = new UserRoleEntity
|
||||
{
|
||||
UserId = command.UserId,
|
||||
RoleId = Guid.NewGuid(),
|
||||
User = null!,
|
||||
Role = new RoleEntity { RoleName = "Admin" }
|
||||
},
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = command.UserId
|
||||
};
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
UserRoleEntity userRole = _userRoleEntityFixture.Create(userId: command.UserId, role: adminRole);
|
||||
|
||||
UserEntity user = _userEntityFixture.Create(
|
||||
id: command.UserId,
|
||||
username: "testUser",
|
||||
password: "hashedPassword",
|
||||
userRole: userRole,
|
||||
includeUserRole: true);
|
||||
|
||||
Error error = Error.Failure("Database.Error", "Failed to get users");
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -303,7 +279,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(new RoleEntity { RoleName = "User" });
|
||||
.Returns(_roleEntityFixture.Create(roleName: "User"));
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
@@ -320,17 +296,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsCommand command = _updateUserRoleAndPermissionsCommandFixture.Create(roleId: Guid.NewGuid());
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = command.UserId,
|
||||
Username = "testUser",
|
||||
Password = "hashedPassword",
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = command.UserId
|
||||
};
|
||||
UserEntity user = _userEntityFixture.Create(id: command.UserId, username: "testUser", password: "hashedPassword");
|
||||
Error error = Error.Failure("Database.Error", "Failed to get permissions");
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -338,7 +304,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(new RoleEntity { RoleName = "User" });
|
||||
.Returns(_roleEntityFixture.Create(roleName: "User"));
|
||||
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
|
||||
+14
-18
@@ -7,6 +7,8 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -34,6 +36,9 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
private readonly IUserRepository _mockUserRepository;
|
||||
private readonly GetUserPermissionsQueryHandler _sut;
|
||||
private readonly GetUserPermissionsQueryFixture _getUserPermissionsQueryFixture = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly UserPermissionEntityFixture _userPermissionEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
/// <summary>
|
||||
@@ -138,26 +143,17 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsQuery query = _getUserPermissionsQueryFixture.Create();
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = query.UserId!.Value,
|
||||
Username = "testUser",
|
||||
Password = "hashedPassword",
|
||||
Libraries = [],
|
||||
UserPermissions =
|
||||
UserEntity user = _userEntityFixture.Create(
|
||||
username: "testUser",
|
||||
password: "hashedPassword",
|
||||
id: query.UserId!.Value,
|
||||
userPermissions:
|
||||
[
|
||||
new()
|
||||
{
|
||||
UserId = query.UserId!.Value,
|
||||
PermissionId = Guid.NewGuid(),
|
||||
User = null!,
|
||||
Permission = new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanViewUsers }
|
||||
}
|
||||
_userPermissionEntityFixture.Create(
|
||||
_userEntityFixture.Create(id: query.UserId!.Value),
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers))
|
||||
],
|
||||
UserRole = null,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = query.UserId!.Value
|
||||
};
|
||||
includeUserPermissions: true);
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
+11
-17
@@ -7,6 +7,7 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
@@ -32,6 +33,8 @@ public class GetUserRoleQueryHandlerTests
|
||||
private readonly IUserRepository _mockUserRepository;
|
||||
private readonly GetUserRoleQueryHandler _sut;
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly UserRoleEntityFixture _userRoleEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly GetUserRoleQueryFixture _getUserRoleQueryFixture = new();
|
||||
private readonly Guid _userId;
|
||||
|
||||
@@ -157,23 +160,14 @@ public class GetUserRoleQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleQuery query = _getUserRoleQueryFixture.Create();
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = query.UserId!.Value,
|
||||
Username = "testUser",
|
||||
Password = "hashedPassword",
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = new()
|
||||
{
|
||||
UserId = query.UserId!.Value,
|
||||
RoleId = Guid.NewGuid(),
|
||||
User = null!,
|
||||
Role = new() { Id = Guid.NewGuid(), RoleName = "TestRole" }
|
||||
},
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = query.UserId!.Value
|
||||
};
|
||||
UserEntity user = _userEntityFixture.Create(
|
||||
username: "testUser",
|
||||
password: "hashedPassword",
|
||||
id: query.UserId!.Value,
|
||||
userRole: _userRoleEntityFixture.Create(
|
||||
userId: query.UserId!.Value,
|
||||
role: _roleEntityFixture.Create(roleName: "TestRole")),
|
||||
includeUserRole: true);
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
Reference in new issue
Block a user