mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 17: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);
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
@@ -84,7 +83,7 @@ public class AddBookRequestTests
|
||||
AddBookRequest sut = _addBookRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
(Guid libraryId, string path, WrittenContentMetadataDto? metadata, BookFormat? format, string? edition, int? volumeNumber, BookSeriesDto? series, string? asin, string? goodreadsId, string? lccn, string? oclcNumber, string? openLibraryId, string? libraryThingId, string? googleBooksId, string? barnesAndNobleId, string? appleBooksId, List<IsbnDto>? isbns, List<MediaContributorDto>? contributors, List<BookRatingDto>? ratings) = sut;
|
||||
(Guid libraryId, string path, WrittenContentMetadataDto? metadata, BookFormat? format, string? edition, float? volumeNumber, BookSeriesDto? series, string? asin, string? goodreadsId, string? lccn, string? oclcNumber, string? openLibraryId, string? libraryThingId, string? googleBooksId, string? barnesAndNobleId, string? appleBooksId, List<IsbnDto>? isbns, List<MediaContributorDto>? contributors, List<BookRatingDto>? ratings) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.LibraryId, libraryId);
|
||||
|
||||
+2
-2
@@ -72,7 +72,7 @@ public class GetBooksLiteRequestTests
|
||||
GetBooksLiteRequest sut = _getBooksLiteRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
(Guid libraryId, int? currentPage, int? perPage, string? searchTerm, string? filterAlphaKey, bool ignoreThePrefixForAlphaPicker, string? sortBy, SortOrder? sortOrder) = sut;
|
||||
(Guid libraryId, int? currentPage, int? perPage, string? searchTerm, string? filterAlphaKey, bool shouldIgnoreThePrefixForAlphaPicker, string? sortBy, SortOrder? sortOrder) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.LibraryId, libraryId);
|
||||
@@ -80,7 +80,7 @@ public class GetBooksLiteRequestTests
|
||||
Assert.Equal(sut.PerPage, perPage);
|
||||
Assert.Equal(sut.SearchTerm, searchTerm);
|
||||
Assert.Equal(sut.FilterAlphaKey, filterAlphaKey);
|
||||
Assert.Equal(sut.IgnoreThePrefixForAlphaPicker, ignoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(sut.ShouldIgnoreThePrefixForAlphaPicker, shouldIgnoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(sut.SortBy, sortBy);
|
||||
Assert.Equal(sut.SortOrder, sortOrder);
|
||||
}
|
||||
|
||||
+23
-103
@@ -26,6 +26,8 @@ public class RoleRepositoryTests
|
||||
{
|
||||
private readonly LuminaDbContext _mockContext;
|
||||
private readonly RoleRepository _sut;
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RoleRepositoryTests"/> class.
|
||||
@@ -40,13 +42,7 @@ public class RoleRepositoryTests
|
||||
public async Task InsertAsync_WhenRoleDoesNotExist_ShouldAddRoleToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity role = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
|
||||
@@ -65,24 +61,12 @@ public class RoleRepositoryTests
|
||||
public async Task InsertAsync_WhenRoleWithSameIdExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RoleEntity newRole = new()
|
||||
{
|
||||
Id = existingRole.Id,
|
||||
RoleName = "SuperAdmin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity newRole = _roleEntityFixture.Create(id: existingRole.Id, roleName: "SuperAdmin");
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
@@ -97,24 +81,12 @@ public class RoleRepositoryTests
|
||||
public async Task InsertAsync_WhenRoleWithSameNameExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RoleEntity newRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity newRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
@@ -131,20 +103,8 @@ public class RoleRepositoryTests
|
||||
// Arrange
|
||||
List<RoleEntity> roles =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "User",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
}
|
||||
_roleEntityFixture.Create(roleName: "Admin"),
|
||||
_roleEntityFixture.Create(roleName: "User")
|
||||
];
|
||||
|
||||
_mockContext.Roles.AddRange(roles);
|
||||
@@ -176,13 +136,7 @@ public class RoleRepositoryTests
|
||||
public async Task GetByNameAsync_WhenRoleExists_ShouldReturnRoleWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity role = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(role);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -211,8 +165,7 @@ public class RoleRepositoryTests
|
||||
public async Task GetByIdAsync_WhenRoleExists_ShouldReturnRoleWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RolePermissionEntity rolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity role = rolePermission.Role;
|
||||
|
||||
_mockContext.Roles.Add(role);
|
||||
@@ -248,26 +201,14 @@ public class RoleRepositoryTests
|
||||
public async Task UpdateAsync_WhenRoleExists_ShouldUpdateRoleAndReturnUpdated()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RoleEntity updatedRole = new()
|
||||
{
|
||||
Id = existingRole.Id,
|
||||
RoleName = "SuperAdmin",
|
||||
CreatedOnUtc = existingRole.CreatedOnUtc,
|
||||
CreatedBy = existingRole.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity updatedRole = _roleEntityFixture.Create(id: existingRole.Id, roleName: "SuperAdmin", createdBy: existingRole.CreatedBy, createdOnUtc: existingRole.CreatedOnUtc);
|
||||
updatedRole.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedRole.UpdatedBy = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
@@ -286,13 +227,7 @@ public class RoleRepositoryTests
|
||||
public async Task UpdateAsync_WhenRoleDoesNotExist_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity nonExistentRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity nonExistentRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
|
||||
@@ -306,25 +241,17 @@ public class RoleRepositoryTests
|
||||
public async Task UpdateAsync_WhenRoleHasPermissions_ShouldUpdatePermissionsAndReturnUpdated()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RolePermissionEntity rolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity existingRole = rolePermission.Role;
|
||||
existingRole.RolePermissions = [rolePermission];
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RolePermissionEntity newRolePermission = rolePermissionFixture.Create();
|
||||
RoleEntity updatedRole = new()
|
||||
{
|
||||
Id = existingRole.Id,
|
||||
RoleName = existingRole.RoleName,
|
||||
RolePermissions = [newRolePermission],
|
||||
CreatedOnUtc = existingRole.CreatedOnUtc,
|
||||
CreatedBy = existingRole.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = Guid.NewGuid()
|
||||
};
|
||||
RolePermissionEntity newRolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity updatedRole = _roleEntityFixture.Create(id: existingRole.Id, roleName: existingRole.RoleName, rolePermissions: [newRolePermission], includeRolePermissions: true, createdBy: existingRole.CreatedBy, createdOnUtc: existingRole.CreatedOnUtc);
|
||||
updatedRole.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedRole.UpdatedBy = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
@@ -344,13 +271,7 @@ public class RoleRepositoryTests
|
||||
public async Task DeleteByIdAsync_WhenRoleExists_ShouldDeleteRoleAndReturnDeleted()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -386,8 +307,7 @@ public class RoleRepositoryTests
|
||||
public async Task DeleteByIdAsync_WhenRoleHasPermissions_ShouldDeleteRoleWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RolePermissionEntity rolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity existingRole = rolePermission.Role;
|
||||
existingRole.RolePermissions = [rolePermission];
|
||||
|
||||
|
||||
+1
-7
@@ -125,13 +125,7 @@ public class DirectoryScanFingerprintRepositoryTests : IDisposable
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
DateTime newLastWriteTimeUtc = DateTime.UtcNow.AddDays(1);
|
||||
DirectoryScanFingerprintEntity updatedFingerprint = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = libraryId,
|
||||
Path = "/dir1",
|
||||
LastWriteTimeUtc = newLastWriteTimeUtc
|
||||
};
|
||||
DirectoryScanFingerprintEntity updatedFingerprint = _directoryScanFingerprintEntityFixture.Create(libraryId: libraryId, path: "/dir1", lastWriteTimeUtc: newLastWriteTimeUtc);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpsertRangeAsync([updatedFingerprint], CancellationToken.None);
|
||||
|
||||
+6
-12
@@ -163,18 +163,12 @@ public class LibraryRepositoryTests
|
||||
_mockContext.Libraries.Add(library);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
LibraryEntity updatedLibrary = new()
|
||||
{
|
||||
Id = library.Id,
|
||||
UserId = library.UserId,
|
||||
Title = "Updated Title",
|
||||
LibraryType = library.LibraryType,
|
||||
ContentLocations = [new LibraryContentLocationEntity { Path = "/new/path" }],
|
||||
CreatedOnUtc = library.CreatedOnUtc,
|
||||
CreatedBy = library.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = library.UserId
|
||||
};
|
||||
LibraryEntity updatedLibrary = _libraryEntityFixture.Create(
|
||||
id: library.Id,
|
||||
userId: library.UserId,
|
||||
title: "Updated Title",
|
||||
libraryType: library.LibraryType,
|
||||
contentLocations: ["/new/path"]);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedLibrary, CancellationToken.None);
|
||||
|
||||
+3
-13
@@ -149,19 +149,9 @@ public class LibraryScanRepositoryTests
|
||||
_mockContext.LibraryScans.Add(libraryScan);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
LibraryScanEntity updatedScan = new()
|
||||
{
|
||||
Id = libraryScan.Id,
|
||||
LibraryId = libraryScan.LibraryId,
|
||||
UserId = libraryScan.UserId,
|
||||
Status = LibraryScanJobStatus.Completed,
|
||||
Library = libraryScan.Library,
|
||||
User = libraryScan.User,
|
||||
CreatedOnUtc = libraryScan.CreatedOnUtc,
|
||||
CreatedBy = libraryScan.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = libraryScan.UserId
|
||||
};
|
||||
LibraryScanEntity updatedScan = _libraryScanEntityFixture.Create(id: libraryScan.Id, libraryId: libraryScan.LibraryId, userId: libraryScan.UserId, status: LibraryScanJobStatus.Completed, libraryEntity: libraryScan.Library, createdOnUtc: libraryScan.CreatedOnUtc);
|
||||
updatedScan.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedScan.UpdatedBy = libraryScan.UserId;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedScan, CancellationToken.None);
|
||||
|
||||
+4
-2
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
|
||||
using Lumina.DataAccess.Core.Repositories.Libraries;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -39,6 +40,7 @@ public class LibraryScanStagingResultsRepositoryTests : IDisposable
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly LibraryScanEntityFixture _libraryScanEntityFixture = new();
|
||||
private readonly HashedFileSystemFileDtoFixture _hashedFileSystemFileDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanStagingResultsRepositoryTests"/> class.
|
||||
@@ -235,8 +237,8 @@ public class LibraryScanStagingResultsRepositoryTests : IDisposable
|
||||
|
||||
List<HashedFileSystemFileDto> hashedFiles =
|
||||
[
|
||||
new HashedFileSystemFileDto { Path = "/books/a.epub", Size = 10, Ticks = 100, CurrentHash = 999, OldHash = 0 },
|
||||
new HashedFileSystemFileDto { Path = "/books/b.epub", Size = 20, Ticks = 200, CurrentHash = 888, OldHash = 0 }
|
||||
_hashedFileSystemFileDtoFixture.Create(path: "/books/a.epub", size: 10, ticks: 100, currentHash: 999, oldHash: 0),
|
||||
_hashedFileSystemFileDtoFixture.Create(path: "/books/b.epub", size: 20, ticks: 200, currentHash: 888, oldHash: 0)
|
||||
];
|
||||
|
||||
// Act
|
||||
|
||||
+62
-174
@@ -30,6 +30,9 @@ public class UserRepositoryTests
|
||||
private readonly UserRepository _sut;
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly UserRoleEntityFixture _userRoleEntityFixture = new();
|
||||
private readonly UserPermissionEntityFixture _userPermissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserRepositoryTests"/> class.
|
||||
@@ -143,20 +146,11 @@ public class UserRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Create updated user with same Id but different properties
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username, // Keep username as it's used for lookup
|
||||
Password = "NewPassword123",
|
||||
TempPassword = "TempPass456",
|
||||
TotpSecret = "NewSecret",
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedBy = existingUser.Id,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: "NewPassword123");
|
||||
updatedUser.TempPassword = "TempPass456";
|
||||
updatedUser.TotpSecret = "NewSecret";
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -235,30 +229,13 @@ public class UserRepositoryTests
|
||||
_mockContext.Permissions.Add(newPermission);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = "NewPassword",
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = existingUser.Id,
|
||||
User = existingUser,
|
||||
PermissionId = newPermission.Id,
|
||||
Permission = newPermission,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = existingUser.Id
|
||||
}
|
||||
],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow
|
||||
};
|
||||
UserPermissionEntity newUserPermission = _userPermissionEntityFixture.Create(existingUser, newPermission);
|
||||
newUserPermission.CreatedOnUtc = DateTime.UtcNow;
|
||||
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: "NewPassword", userPermissions: [newUserPermission], includeUserPermissions: true);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -280,50 +257,24 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenUserHasExistingPermissions_ShouldRemoveOldPermissionsAndAddNew()
|
||||
{
|
||||
// Arrange
|
||||
UserEntityFixture userFixture = new();
|
||||
PermissionEntityFixture permissionFixture = new();
|
||||
UserPermissionEntityFixture userPermissionFixture = new();
|
||||
UserEntity existingUser = _userEntityFixture.Create();
|
||||
PermissionEntity oldPermission = _permissionEntityFixture.Create();
|
||||
PermissionEntity newPermission = _permissionEntityFixture.Create();
|
||||
|
||||
UserEntity existingUser = userFixture.Create();
|
||||
PermissionEntity oldPermission = permissionFixture.Create();
|
||||
PermissionEntity newPermission = permissionFixture.Create();
|
||||
|
||||
UserEntity userWithPermissions = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = existingUser.Libraries,
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
userPermissionFixture.Create(existingUser, oldPermission)
|
||||
],
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
UpdatedOnUtc = existingUser.UpdatedOnUtc,
|
||||
UpdatedBy = existingUser.UpdatedBy
|
||||
};
|
||||
UserEntity userWithPermissions = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userPermissions: [_userPermissionEntityFixture.Create(existingUser, oldPermission)], includeUserPermissions: true);
|
||||
userWithPermissions.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
userWithPermissions.CreatedBy = existingUser.CreatedBy;
|
||||
userWithPermissions.UpdatedOnUtc = existingUser.UpdatedOnUtc;
|
||||
userWithPermissions.UpdatedBy = existingUser.UpdatedBy;
|
||||
|
||||
_mockContext.Users.Add(userWithPermissions);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = existingUser.Libraries,
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
userPermissionFixture.Create(existingUser, newPermission)
|
||||
],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = existingUser.Id
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userPermissions: [_userPermissionEntityFixture.Create(existingUser, newPermission)], includeUserPermissions: true);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedUser.UpdatedBy = existingUser.Id;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -349,84 +300,40 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenUserRoleChanges_ShouldRemoveOldRoleAndAddNew()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity oldRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "OldRole",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity oldRole = _roleEntityFixture.Create(roleName: "OldRole");
|
||||
oldRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
oldRole.CreatedBy = Guid.NewGuid();
|
||||
|
||||
RoleEntity newRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "NewRole",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity newRole = _roleEntityFixture.Create(roleName: "NewRole");
|
||||
newRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
newRole.CreatedBy = Guid.NewGuid();
|
||||
|
||||
UserEntity existingUser = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "TestUser",
|
||||
Password = "TestPass",
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
UserEntity existingUser = _userEntityFixture.Create(username: "TestUser", password: "TestPass");
|
||||
existingUser.CreatedOnUtc = DateTime.UtcNow;
|
||||
existingUser.CreatedBy = Guid.NewGuid();
|
||||
|
||||
UserRoleEntity oldUserRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = existingUser.Id,
|
||||
User = existingUser,
|
||||
RoleId = oldRole.Id,
|
||||
Role = oldRole,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
UserRoleEntity oldUserRole = _userRoleEntityFixture.Create(userId: existingUser.Id, user: existingUser, roleId: oldRole.Id, role: oldRole);
|
||||
oldUserRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
oldUserRole.CreatedBy = Guid.NewGuid();
|
||||
|
||||
existingUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = [],
|
||||
UserRole = oldUserRole,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
CreatedBy = existingUser.CreatedBy
|
||||
};
|
||||
DateTime originalCreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
Guid originalCreatedBy = existingUser.CreatedBy;
|
||||
existingUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userRole: oldUserRole, includeUserRole: true);
|
||||
existingUser.CreatedOnUtc = originalCreatedOnUtc;
|
||||
existingUser.CreatedBy = originalCreatedBy;
|
||||
|
||||
_mockContext.Users.Add(existingUser);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserRoleEntity newUserRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = existingUser.Id,
|
||||
User = existingUser,
|
||||
RoleId = newRole.Id,
|
||||
Role = newRole,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = existingUser.Id
|
||||
};
|
||||
UserRoleEntity newUserRole = _userRoleEntityFixture.Create(userId: existingUser.Id, user: existingUser, roleId: newRole.Id, role: newRole);
|
||||
newUserRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
newUserRole.CreatedBy = existingUser.Id;
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = [],
|
||||
UserRole = newUserRole,
|
||||
UserPermissions = [],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = existingUser.Id
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userRole: newUserRole, includeUserRole: true);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedUser.UpdatedBy = existingUser.Id;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -454,39 +361,20 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenRemovingUserRole_ShouldRemoveRoleAndNotAddNew()
|
||||
{
|
||||
// Arrange
|
||||
UserEntityFixture userFixture = new();
|
||||
UserRoleEntityFixture userRoleFixture = new();
|
||||
UserRoleEntity oldUserRole = _userRoleEntityFixture.Create();
|
||||
|
||||
UserRoleEntity oldUserRole = userRoleFixture.Create();
|
||||
|
||||
UserEntity existingUser = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "TestUser",
|
||||
Password = "TestPass",
|
||||
Libraries = [],
|
||||
UserRole = oldUserRole,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
UserEntity existingUser = _userEntityFixture.Create(username: "TestUser", password: "TestPass", userRole: oldUserRole, includeUserRole: true);
|
||||
existingUser.CreatedOnUtc = DateTime.UtcNow;
|
||||
existingUser.CreatedBy = Guid.NewGuid();
|
||||
|
||||
_mockContext.Users.Add(existingUser);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = existingUser.Id
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedUser.UpdatedBy = existingUser.Id;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
|
||||
+3
-3
@@ -119,7 +119,7 @@ public class UserSettingsRepositoryTests
|
||||
Assert.Equal(settings.UserId, result.Value.UserId);
|
||||
Assert.Equal(settings.IsPaginationEnabled, result.Value.IsPaginationEnabled);
|
||||
Assert.Equal(settings.ItemsPerPage, result.Value.ItemsPerPage);
|
||||
Assert.Equal(settings.IgnoreThePrefixForAlphaPicker, result.Value.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(settings.ShouldIgnoreThePrefixForAlphaPicker, result.Value.ShouldIgnoreThePrefixForAlphaPicker);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -146,7 +146,7 @@ public class UserSettingsRepositoryTests
|
||||
userId: existingSettings.UserId,
|
||||
isPaginationEnabled: false,
|
||||
itemsPerPage: 12,
|
||||
ignoreThePrefixForAlphaPicker: true);
|
||||
shouldIgnoreThePrefixForAlphaPicker: true);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedSettings, CancellationToken.None);
|
||||
@@ -160,7 +160,7 @@ public class UserSettingsRepositoryTests
|
||||
Assert.Equal(existingSettings.UserId, modifiedSettings.UserId);
|
||||
Assert.False(modifiedSettings.IsPaginationEnabled);
|
||||
Assert.Equal(12, modifiedSettings.ItemsPerPage);
|
||||
Assert.True(modifiedSettings.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.True(modifiedSettings.ShouldIgnoreThePrefixForAlphaPicker);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -6,6 +6,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.DataAccess.Core.Seed;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -31,6 +32,9 @@ public class DataSeedServiceTests
|
||||
private readonly IPermissionRepository _mockPermissionRepository;
|
||||
private readonly DataSeedService _sut;
|
||||
private readonly DateTime _fixedUtcNow;
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DataSeedServiceTests"/> class.
|
||||
@@ -226,12 +230,12 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
List<PermissionEntity> permissions =
|
||||
[
|
||||
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)
|
||||
];
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -291,7 +295,7 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
Error expectedError = Error.Failure("Permissions.NotFound", "Failed to retrieve permissions");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -318,8 +322,8 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
List<PermissionEntity> permissions = [new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanViewUsers }];
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
List<PermissionEntity> permissions = [_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)];
|
||||
Error expectedError = Error.Failure("RolePermission.InsertFailed", "Failed to insert role permission");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -373,9 +377,8 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
UserEntityFixture userFixture = new();
|
||||
UserEntity adminUser = userFixture.Create();
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
UserEntity adminUser = _userEntityFixture.Create();
|
||||
// Use the adminUser.Id instead of the randomly generated userId
|
||||
userId = adminUser.Id;
|
||||
|
||||
@@ -437,7 +440,7 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
IUserRepository mockUserRepository = Substitute.For<IUserRepository>();
|
||||
@@ -463,8 +466,8 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
UserEntity adminUser = new UserEntityFixture().Create();
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
UserEntity adminUser = _userEntityFixture.Create();
|
||||
|
||||
Error expectedError = Error.Failure("UserRole.InsertFailed", "Failed to insert user role");
|
||||
|
||||
@@ -519,7 +522,7 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
Error expectedError = Error.Failure("User.NotFound", "Failed to retrieve user");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
|
||||
+20
-7
@@ -20,7 +20,6 @@ using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
@@ -72,7 +71,7 @@ public class MediaLibraryScanningServiceTests
|
||||
IMediaTypeScanner scanner = CreateScanner([job]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -95,7 +94,7 @@ public class MediaLibraryScanningServiceTests
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Running);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
@@ -111,11 +110,11 @@ public class MediaLibraryScanningServiceTests
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
IMediaTypeScanner scanner = Substitute.For<IMediaTypeScanner>();
|
||||
scanner.CreateScanJobsForLibrary(Arg.Any<LibraryId>(), Arg.Any<bool>()).Returns(_ => throw new NotImplementedException());
|
||||
scanner.CreateScanJobsForLibrary(Arg.Any<LibraryId>()).Returns(_ => throw new NotImplementedException());
|
||||
_mockScannerFactory.CreateLibraryScanner(LibraryType.Book).Returns(scanner);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -135,7 +134,7 @@ public class MediaLibraryScanningServiceTests
|
||||
IMediaTypeScanner scanner = CreateScanner([firstRoot, secondRoot]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
@@ -180,14 +179,24 @@ public class MediaLibraryScanningServiceTests
|
||||
Assert.Equal(userId, leafJob.UserId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mocked <see cref="IMediaTypeScanner"/> and registers it with the mocked scanner factory.
|
||||
/// </summary>
|
||||
/// <param name="jobs">The scan jobs the scanner returns when asked to create scan jobs for a library.</param>
|
||||
/// <returns>The created mocked scanner.</returns>
|
||||
private IMediaTypeScanner CreateScanner(List<IMediaLibraryScanJob> jobs)
|
||||
{
|
||||
IMediaTypeScanner scanner = Substitute.For<IMediaTypeScanner>();
|
||||
scanner.CreateScanJobsForLibrary(Arg.Any<LibraryId>(), Arg.Any<bool>()).Returns(jobs);
|
||||
scanner.CreateScanJobsForLibrary(Arg.Any<LibraryId>()).Returns(jobs);
|
||||
_mockScannerFactory.CreateLibraryScanner(LibraryType.Book).Returns(scanner);
|
||||
return scanner;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a mocked scan job with the given children.
|
||||
/// </summary>
|
||||
/// <param name="children">The child scan jobs of the created job.</param>
|
||||
/// <returns>The created mocked scan job.</returns>
|
||||
private static IMediaLibraryScanJob CreateJob(List<IMediaLibraryScanJob> children)
|
||||
{
|
||||
IMediaLibraryScanJob job = Substitute.For<IMediaLibraryScanJob>();
|
||||
@@ -195,6 +204,10 @@ public class MediaLibraryScanningServiceTests
|
||||
return job;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts and drains the scan jobs currently enqueued on the scan queue channel.
|
||||
/// </summary>
|
||||
/// <returns>The number of enqueued scan jobs.</returns>
|
||||
private int CountEnqueuedJobs()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
+10
-31
@@ -1,8 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
@@ -42,33 +40,7 @@ public class BookLibraryTypeScannerTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenDownloadMetadataFromWebIsFalse_ShouldCreateJobChainWithoutMetadataEnrichment()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
TestScanJob discoveryJob = CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
TestScanJob diffJob = CreateJob<IMediaLibraryScanDiffJob>();
|
||||
TestScanJob hashJob = CreateJob<IMediaLibraryScanHashJob>();
|
||||
TestScanJob saveJob = CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
List<IMediaLibraryScanJob> rootJobs = [.. sut.CreateScanJobsForLibrary(libraryId, downloadMetadataFromWeb: false)];
|
||||
|
||||
// Assert
|
||||
IMediaLibraryScanJob rootJob = Assert.Single(rootJobs);
|
||||
Assert.Same(discoveryJob, rootJob);
|
||||
Assert.Contains(diffJob, discoveryJob.Children);
|
||||
Assert.Contains(discoveryJob, diffJob.Parents);
|
||||
Assert.Contains(hashJob, diffJob.Children);
|
||||
Assert.Contains(diffJob, hashJob.Parents);
|
||||
Assert.Contains(saveJob, hashJob.Children);
|
||||
Assert.Contains(hashJob, saveJob.Parents);
|
||||
_mockJobFactory.DidNotReceive().CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(Arg.Any<LibraryId>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenDownloadMetadataFromWebIsTrue_ShouldCreateJobChainWithMetadataEnrichment()
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldCreateJobChainWithMetadataEnrichment()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
@@ -80,12 +52,17 @@ public class BookLibraryTypeScannerTests
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
List<IMediaLibraryScanJob> rootJobs = [.. sut.CreateScanJobsForLibrary(libraryId, downloadMetadataFromWeb: true)];
|
||||
List<IMediaLibraryScanJob> rootJobs = [.. sut.CreateScanJobsForLibrary(libraryId)];
|
||||
|
||||
// Assert
|
||||
IMediaLibraryScanJob rootJob = Assert.Single(rootJobs);
|
||||
Assert.Same(discoveryJob, rootJob);
|
||||
Assert.Contains(diffJob, discoveryJob.Children);
|
||||
Assert.Contains(discoveryJob, diffJob.Parents);
|
||||
Assert.Contains(hashJob, diffJob.Children);
|
||||
Assert.Contains(diffJob, hashJob.Parents);
|
||||
Assert.Contains(saveJob, hashJob.Children);
|
||||
Assert.Contains(hashJob, saveJob.Parents);
|
||||
Assert.Contains(enrichmentJob, saveJob.Children);
|
||||
Assert.Contains(saveJob, enrichmentJob.Parents);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
@@ -100,16 +77,18 @@ public class BookLibraryTypeScannerTests
|
||||
CreateJob<IMediaLibraryScanDiffJob>();
|
||||
CreateJob<IMediaLibraryScanHashJob>();
|
||||
CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
_ = sut.CreateScanJobsForLibrary(libraryId, downloadMetadataFromWeb: false).ToList();
|
||||
_ = sut.CreateScanJobsForLibrary(libraryId).ToList();
|
||||
|
||||
// Assert
|
||||
_mockJobFactory.Received(1).CreateJob<IBooksFileSystemDiscoveryJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanDiffJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanHashJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanResultsSaveJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
}
|
||||
|
||||
private TestScanJob CreateJob<TJob>() where TJob : class, IMediaLibraryScanJob
|
||||
|
||||
+7
-28
@@ -3,11 +3,12 @@ using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Plugins;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Plugins;
|
||||
using Lumina.Infrastructure.Core.Plugins;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Plugins;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -40,6 +41,7 @@ public class PluginDetectionSyncJobTests
|
||||
private readonly IPluginManager _mockPluginManager;
|
||||
private readonly ILogger<PluginDetectionSyncJob> _mockLogger;
|
||||
private readonly PluginLoadErrorDtoFixture _pluginLoadErrorDtoFixture;
|
||||
private readonly PluginEntityFixture _pluginEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginDetectionSyncJobTests"/> class.
|
||||
@@ -166,8 +168,8 @@ public class PluginDetectionSyncJobTests
|
||||
_mockPluginManager.GetPlugins().Returns([loadedPlugin]);
|
||||
_mockPluginRepository.UpsertAsync(Arg.Any<PluginEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Updated));
|
||||
PluginEntity loadedPluginRow = CreatePluginEntity(loadedPlugin.Id, loadedPlugin.Name, PluginLoadStatus.Loaded);
|
||||
PluginEntity stalePluginRow = CreatePluginEntity(Guid.NewGuid(), "Stale Plugin", PluginLoadStatus.Loaded);
|
||||
PluginEntity loadedPluginRow = _pluginEntityFixture.Create(id: loadedPlugin.Id, name: loadedPlugin.Name, loadStatus: PluginLoadStatus.Loaded);
|
||||
PluginEntity stalePluginRow = _pluginEntityFixture.Create(name: "Stale Plugin", loadStatus: PluginLoadStatus.Loaded);
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From((IEnumerable<PluginEntity>)[loadedPluginRow, stalePluginRow]));
|
||||
_mockPluginRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -194,7 +196,7 @@ public class PluginDetectionSyncJobTests
|
||||
PluginLoadErrorDto loadError = _pluginLoadErrorDtoFixture.Create(
|
||||
assemblyName: "MyPlugin",
|
||||
errorMessage: "Failed to load plugin assembly 'MyPlugin.dll': unexpected error");
|
||||
PluginEntity staleLoadedRow = CreatePluginEntity(previouslyLoadedPlugin.Id, previouslyLoadedPlugin.Name, PluginLoadStatus.Loaded);
|
||||
PluginEntity staleLoadedRow = _pluginEntityFixture.Create(id: previouslyLoadedPlugin.Id, name: previouslyLoadedPlugin.Name, loadStatus: PluginLoadStatus.Loaded);
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From((IEnumerable<PluginEntity>)[staleLoadedRow]));
|
||||
_mockPluginRepository.DeleteByIdAsync(previouslyLoadedPlugin.Id, Arg.Any<CancellationToken>())
|
||||
@@ -254,29 +256,6 @@ public class PluginDetectionSyncJobTests
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a stored plugin row with the provided identity.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the plugin row.</param>
|
||||
/// <param name="name">The name of the plugin row.</param>
|
||||
/// <param name="loadStatus">The load status of the plugin row.</param>
|
||||
/// <returns>The created plugin entity.</returns>
|
||||
private static PluginEntity CreatePluginEntity(Guid id, string name, PluginLoadStatus loadStatus)
|
||||
{
|
||||
return new PluginEntity
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
Author = "Test Author",
|
||||
Version = "1.0.0",
|
||||
Description = "Test plugin description",
|
||||
LoadStatus = loadStatus,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedBy = default
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Derives the stable plugin Id expected for a failing plugin assembly, mirroring the detection job logic.
|
||||
/// </summary>
|
||||
@@ -285,6 +264,6 @@ public class PluginDetectionSyncJobTests
|
||||
private static Guid DeriveExpectedId(string assemblyName)
|
||||
{
|
||||
byte[] hash = SHA256.HashData(Encoding.UTF8.GetBytes(assemblyName));
|
||||
return new Guid(hash.Take(16).ToArray());
|
||||
return new Guid([.. hash.Take(16)]);
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Core.Plugins;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
@@ -27,6 +27,7 @@ public class PluginInstallerTests : IDisposable
|
||||
{
|
||||
private readonly string _pluginsDirectory;
|
||||
private readonly PluginInstaller _sut;
|
||||
private readonly PluginsSettingsDtoFixture _pluginsSettingsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginInstallerTests"/> class.
|
||||
@@ -36,7 +37,7 @@ public class PluginInstallerTests : IDisposable
|
||||
_pluginsDirectory = Path.Combine(AppContext.BaseDirectory, $".test-plugins-{Guid.NewGuid():N}");
|
||||
ILogger<PluginInstaller> mockLogger = Substitute.For<ILogger<PluginInstaller>>();
|
||||
IOptions<PluginsSettingsDto> mockOptions = Substitute.For<IOptions<PluginsSettingsDto>>();
|
||||
mockOptions.Value.Returns(new PluginsSettingsDto { Directory = Path.GetFileName(_pluginsDirectory) });
|
||||
mockOptions.Value.Returns(_pluginsSettingsDtoFixture.Create(directory: Path.GetFileName(_pluginsDirectory)));
|
||||
_sut = new PluginInstaller(mockOptions, mockLogger);
|
||||
}
|
||||
|
||||
|
||||
+4
-24
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Infrastructure.Core.Plugins;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -26,6 +27,7 @@ public class PluginSettingsStoreTests
|
||||
private readonly IPluginRepository _mockPluginRepository;
|
||||
private readonly ILogger<PluginSettingsStore> _mockLogger;
|
||||
private readonly PluginSettingsStore _sut;
|
||||
private readonly PluginEntityFixture _pluginEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PluginSettingsStoreTests"/> class.
|
||||
@@ -46,7 +48,7 @@ public class PluginSettingsStoreTests
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
Dictionary<string, string> expectedSettings = new() { ["ApiKey"] = "test-key", ["Enabled"] = "true" };
|
||||
PluginEntity pluginEntity = CreatePluginEntity(pluginId, JsonSerializer.Serialize(expectedSettings));
|
||||
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, settingsJson: JsonSerializer.Serialize(expectedSettings));
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(pluginEntity));
|
||||
|
||||
@@ -63,7 +65,7 @@ public class PluginSettingsStoreTests
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
PluginEntity pluginEntity = CreatePluginEntity(pluginId, settingsJson: null);
|
||||
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, includeSettingsJson: false);
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(pluginEntity));
|
||||
|
||||
@@ -103,26 +105,4 @@ public class PluginSettingsStoreTests
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a plugin entity with the provided identity and serialized settings.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the plugin.</param>
|
||||
/// <param name="settingsJson">The serialized settings of the plugin.</param>
|
||||
/// <returns>The created plugin entity.</returns>
|
||||
private static PluginEntity CreatePluginEntity(Guid id, string? settingsJson)
|
||||
{
|
||||
return new PluginEntity
|
||||
{
|
||||
Id = id,
|
||||
Name = "Test Plugin",
|
||||
Author = "Test Author",
|
||||
Version = "1.0.0",
|
||||
Description = "Test plugin description",
|
||||
SettingsJson = settingsJson,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
}
|
||||
+19
-8
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +28,9 @@ public class AddRoleEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<AddRoleCommand, Result<RolePermissionsResponse>> _mockHandler;
|
||||
private readonly AddRoleEndpoint _sut;
|
||||
private readonly RolePermissionsResponseFixture _rolePermissionsResponseFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddRoleEndpointTests"/> class.
|
||||
@@ -40,9 +45,11 @@ public class AddRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithRoleResponse()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new("Admin", [Guid.NewGuid()]);
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(roleName: "Admin", permissions: [Guid.NewGuid()]);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RolePermissionsResponse expectedResponse = new(new RoleDto(Guid.NewGuid(), "Admin"), []);
|
||||
RolePermissionsResponse expectedResponse = _rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []);
|
||||
_mockHandler.HandleAsync(Arg.Any<AddRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -58,7 +65,7 @@ public class AddRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new("Admin", [Guid.NewGuid()]);
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(roleName: "Admin", permissions: [Guid.NewGuid()]);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Creation.Failed", "Failed to create role.");
|
||||
_mockHandler.HandleAsync(Arg.Any<AddRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -84,10 +91,12 @@ public class AddRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendAddRoleCommandToSender()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new("Admin", [Guid.NewGuid()]);
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(roleName: "Admin", permissions: [Guid.NewGuid()]);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<AddRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RolePermissionsResponse(new RoleDto(Guid.NewGuid(), "Admin"), [])));
|
||||
.Returns(Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: [])));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -114,11 +123,13 @@ public class AddRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RolePermissionsResponse(new RoleDto(Guid.NewGuid(), "Admin"), []));
|
||||
return Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new AddRoleRequest("Admin", []), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_addRoleRequestFixture.Create(roleName: "Admin", permissions: []), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+6
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.DeleteRole;
|
||||
@@ -23,6 +24,7 @@ public class DeleteRoleEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<DeleteRoleCommand, Result<Deleted>> _mockHandler;
|
||||
private readonly DeleteRoleEndpoint _sut;
|
||||
private readonly DeleteRoleRequestFixture _deleteRoleRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteRoleEndpointTests"/> class.
|
||||
@@ -37,7 +39,7 @@ public class DeleteRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnNoContent()
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleRequest request = new(Guid.NewGuid());
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Deleted));
|
||||
@@ -53,7 +55,7 @@ public class DeleteRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleRequest request = new(Guid.NewGuid());
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Deletion.Failed", "Failed to delete role.");
|
||||
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -80,7 +82,7 @@ public class DeleteRoleEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.NewGuid();
|
||||
DeleteRoleRequest request = new(roleId);
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(roleId: roleId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Deleted));
|
||||
@@ -112,7 +114,7 @@ public class DeleteRoleEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new DeleteRoleRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_deleteRoleRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+20
-14
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +28,10 @@ public class GetRolePermissionsEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetRolePermissionsQuery, Result<RolePermissionsResponse>> _mockHandler;
|
||||
private readonly GetRolePermissionsEndpoint _sut;
|
||||
private readonly RolePermissionsResponseFixture _rolePermissionsResponseFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly PermissionDtoFixture _permissionDtoFixture = new();
|
||||
private readonly GetRolePermissionsRequestFixture _getRolePermissionsRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolePermissionsEndpointTests"/> class.
|
||||
@@ -40,11 +46,11 @@ public class GetRolePermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
GetRolePermissionsRequest request = new(Guid.NewGuid());
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RolePermissionsResponse expectedResponse = new(
|
||||
new RoleDto(Guid.NewGuid(), "Admin"),
|
||||
[new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
RolePermissionsResponse expectedResponse = _rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: [_permissionDtoFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)]
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolePermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -61,7 +67,7 @@ public class GetRolePermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetRolePermissionsRequest request = new(Guid.NewGuid());
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Permissions.NotFound", "Role permissions not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolePermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -88,12 +94,12 @@ public class GetRolePermissionsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.NewGuid();
|
||||
GetRolePermissionsRequest request = new(roleId);
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(roleId: roleId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolePermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "Admin"),
|
||||
[]
|
||||
.Returns(Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []
|
||||
)));
|
||||
|
||||
// Act
|
||||
@@ -119,14 +125,14 @@ public class GetRolePermissionsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "Admin"),
|
||||
[]
|
||||
return Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []
|
||||
));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetRolePermissionsRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getRolePermissionsRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRoles;
|
||||
@@ -25,6 +26,7 @@ public class GetRolesEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetRolesQuery, Result<IEnumerable<RoleResponse>>> _mockHandler;
|
||||
private readonly GetRolesEndpoint _sut;
|
||||
private readonly RoleResponseFixture _roleResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolesEndpointTests"/> class.
|
||||
@@ -42,8 +44,8 @@ public class GetRolesEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<RoleResponse> expectedResponse =
|
||||
[
|
||||
new RoleResponse(Guid.NewGuid(), "Admin")
|
||||
];
|
||||
_roleResponseFixture.Create(roleName: "Admin")
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -88,7 +90,7 @@ public class GetRolesEndpointTests
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new List<RoleResponse>
|
||||
{
|
||||
new(Guid.NewGuid(), "Admin")
|
||||
_roleResponseFixture.Create(roleName: "Admin")
|
||||
} as IEnumerable<RoleResponse>));
|
||||
|
||||
// Act
|
||||
|
||||
+20
-14
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,10 @@ public class UpdateRoleEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<UpdateRoleCommand, Result<RolePermissionsResponse>> _mockHandler;
|
||||
private readonly UpdateRoleEndpoint _sut;
|
||||
private readonly UpdateRoleRequestFixture _updateRoleRequestFixture = new();
|
||||
private readonly RolePermissionsResponseFixture _rolePermissionsResponseFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly PermissionDtoFixture _permissionDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateRoleEndpointTests"/> class.
|
||||
@@ -41,11 +47,11 @@ public class UpdateRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithUpdatedRole()
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(roleName: "UpdatedAdmin");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RolePermissionsResponse expectedResponse = new(
|
||||
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
|
||||
[new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
RolePermissionsResponse expectedResponse = _rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "UpdatedAdmin"),
|
||||
permissions: [_permissionDtoFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)]
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -62,7 +68,7 @@ public class UpdateRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(roleName: "UpdatedAdmin");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Update.Failed", "Failed to update role.");
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -88,12 +94,12 @@ public class UpdateRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendUpdateRoleCommandToSender()
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(roleName: "UpdatedAdmin");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
|
||||
[]
|
||||
.Returns(Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "UpdatedAdmin"),
|
||||
permissions: []
|
||||
)));
|
||||
|
||||
// Act
|
||||
@@ -122,15 +128,15 @@ public class UpdateRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
|
||||
[]
|
||||
return Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "UpdatedAdmin"),
|
||||
permissions: []
|
||||
));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(
|
||||
new UpdateRoleRequest(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]),
|
||||
_updateRoleRequestFixture.Create(roleName: "UpdatedAdmin"),
|
||||
cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
|
||||
+7
-5
@@ -2,8 +2,9 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.FileSystem.GetType;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -24,6 +25,7 @@ public class GetTypeEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetFileSystemQuery, FileSystemTypeResponse> _mockHandler;
|
||||
private readonly GetTypeEndpoint _sut;
|
||||
private readonly FileSystemTypeResponseFixture _fileSystemTypeResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTypeEndpointTests"/> class.
|
||||
@@ -39,7 +41,7 @@ public class GetTypeEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
FileSystemTypeResponse expectedResponse = new(PlatformType.Windows);
|
||||
FileSystemTypeResponse expectedResponse = _fileSystemTypeResponseFixture.Create(platformType: PlatformType.Windows);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -58,7 +60,7 @@ public class GetTypeEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
FileSystemTypeResponse expectedResponse = new(platformType);
|
||||
FileSystemTypeResponse expectedResponse = _fileSystemTypeResponseFixture.Create(platformType: platformType);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -76,7 +78,7 @@ public class GetTypeEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new FileSystemTypeResponse(PlatformType.Windows));
|
||||
.Returns(_fileSystemTypeResponseFixture.Create(platformType: PlatformType.Windows));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
@@ -99,7 +101,7 @@ public class GetTypeEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new FileSystemTypeResponse(PlatformType.Windows);
|
||||
return _fileSystemTypeResponseFixture.Create(platformType: PlatformType.Windows);
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +28,7 @@ public class CheckPathExistsEndpointTests
|
||||
private readonly IQueryHandler<CheckPathExistsQuery, Result<PathExistsResponse>> _mockHandler;
|
||||
private readonly CheckPathExistsEndpoint _sut;
|
||||
private readonly CheckPathExistsRequestFixture _checkPathExistsRequestFixture = new();
|
||||
private readonly PathExistsResponseFixture _pathExistsResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckPathExistsEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class CheckPathExistsEndpointTests
|
||||
// Arrange
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathExistsResponse expectedResponse = new(true);
|
||||
PathExistsResponse expectedResponse = _pathExistsResponseFixture.Create(exists: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -62,7 +64,7 @@ public class CheckPathExistsEndpointTests
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathExistsResponse(true));
|
||||
.Returns(_pathExistsResponseFixture.Create(exists: true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -88,7 +90,7 @@ public class CheckPathExistsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new PathExistsResponse(true));
|
||||
return Result.From(_pathExistsResponseFixture.Create(exists: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +28,7 @@ public class ValidatePathEndpointTests
|
||||
private readonly IQueryHandler<ValidatePathQuery, Result<PathValidResponse>> _mockHandler;
|
||||
private readonly ValidatePathEndpoint _sut;
|
||||
private readonly ValidatePathRequestFixture _validatePathRequestFixture = new();
|
||||
private readonly PathValidResponseFixture _pathValidResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ValidatePathEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class ValidatePathEndpointTests
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathValidResponse expectedResponse = new(true);
|
||||
PathValidResponse expectedResponse = _pathValidResponseFixture.Create(isValid: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -62,7 +64,7 @@ public class ValidatePathEndpointTests
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathValidResponse(true));
|
||||
.Returns(_pathValidResponseFixture.Create(isValid: true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -114,7 +116,7 @@ public class ValidatePathEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new PathValidResponse(true));
|
||||
return Result.From(_pathValidResponseFixture.Create(isValid: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+1
-2
@@ -6,7 +6,6 @@ using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.AddLibrary;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -104,7 +103,7 @@ public class AddLibraryEndpointTests
|
||||
command.CoverImage == request.CoverImage &&
|
||||
command.IsEnabled == request.IsEnabled &&
|
||||
command.IsLocked == request.IsLocked &&
|
||||
command.DownloadMetadataFromWeb == request.DownloadMetadataFromWeb &&
|
||||
command.CanDownloadMetadataFromWeb == request.CanDownloadMetadataFromWeb &&
|
||||
command.ShouldSaveMetadataInMediaDirectories == request.ShouldSaveMetadataInMediaDirectories &&
|
||||
command.ShouldSkipUnchangedDirectoriesDuringScan == request.ShouldSkipUnchangedDirectoriesDuringScan),
|
||||
Arg.Is(cancellationToken));
|
||||
|
||||
+4
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibraries;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.ScanLibraries;
|
||||
@@ -25,6 +26,7 @@ public class ScanLibrariesEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<ScanLibrariesCommand, Result<IEnumerable<MediaLibraryScanResponse>>> _mockHandler;
|
||||
private readonly ScanLibrariesEndpoint _sut;
|
||||
private readonly MediaLibraryScanResponseFixture _mediaLibraryScanResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScanLibrariesEndpointTests"/> class.
|
||||
@@ -42,8 +44,8 @@ public class ScanLibrariesEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<MediaLibraryScanResponse> expectedResponses =
|
||||
[
|
||||
new MediaLibraryScanResponse(Guid.NewGuid(), Guid.NewGuid()),
|
||||
new MediaLibraryScanResponse(Guid.NewGuid(), Guid.NewGuid())
|
||||
_mediaLibraryScanResponseFixture.Create(),
|
||||
_mediaLibraryScanResponseFixture.Create()
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<ScanLibrariesCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponses));
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class ScanLibraryEndpointTests
|
||||
private readonly ICommandHandler<ScanLibraryCommand, Result<MediaLibraryScanResponse>> _mockHandler;
|
||||
private readonly ScanLibraryEndpoint _sut;
|
||||
private readonly ScanLibraryRequestFixture _scanLibraryRequestFixture = new();
|
||||
private readonly MediaLibraryScanResponseFixture _mediaLibraryScanResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScanLibraryEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class ScanLibraryEndpointTests
|
||||
// Arrange
|
||||
ScanLibraryRequest request = _scanLibraryRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
MediaLibraryScanResponse expectedResponse = new(Guid.NewGuid(), request.Id);
|
||||
MediaLibraryScanResponse expectedResponse = _mediaLibraryScanResponseFixture.Create(libraryId: request.Id);
|
||||
_mockHandler.HandleAsync(Arg.Any<ScanLibraryCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class ScanLibraryEndpointTests
|
||||
ScanLibraryRequest request = _scanLibraryRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ScanLibraryCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new MediaLibraryScanResponse(Guid.NewGuid(), request.Id)));
|
||||
.Returns(Result.From(_mediaLibraryScanResponseFixture.Create(libraryId: request.Id)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -113,7 +115,7 @@ public class ScanLibraryEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new MediaLibraryScanResponse(Guid.NewGuid(), request.Id));
|
||||
return Result.From(_mediaLibraryScanResponseFixture.Create(libraryId: request.Id));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+1
-2
@@ -6,7 +6,6 @@ using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.UpdateLibrary;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -106,7 +105,7 @@ public class UpdateLibraryEndpointTests
|
||||
command.CoverImage == request.CoverImage &&
|
||||
command.IsEnabled == request.IsEnabled &&
|
||||
command.IsLocked == request.IsLocked &&
|
||||
command.DownloadMetadataFromWeb == request.DownloadMetadataFromWeb &&
|
||||
command.CanDownloadMetadataFromWeb == request.CanDownloadMetadataFromWeb &&
|
||||
command.ShouldSaveMetadataInMediaDirectories == request.ShouldSaveMetadataInMediaDirectories &&
|
||||
command.ShouldSkipUnchangedDirectoriesDuringScan == request.ShouldSkipUnchangedDirectoriesDuringScan),
|
||||
Arg.Is(cancellationToken));
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBook;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -19,12 +20,13 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Library.WrittenConten
|
||||
public class GetBookEndpointTests
|
||||
{
|
||||
private readonly GetBookEndpoint _sut = Factory.Create<GetBookEndpoint>();
|
||||
private readonly GetBookRequestFixture _getBookRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldReturnOkResult()
|
||||
{
|
||||
// Arrange
|
||||
GetBookRequest request = new(Guid.NewGuid().ToString());
|
||||
GetBookRequest request = _getBookRequestFixture.Create(id: Guid.NewGuid().ToString());
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
// Act
|
||||
|
||||
+5
-12
@@ -2,15 +2,14 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Responses.Common;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -34,6 +33,7 @@ public class GetBooksEndpointTests
|
||||
private readonly GetBooksEndpoint _sut;
|
||||
private readonly GetBooksRequestFixture _getBooksRequestFixture = new();
|
||||
private readonly BookResponseFixture _bookResponseFixture = new();
|
||||
private readonly PaginatedResponseFixture<BookResponse> _paginatedResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetBooksEndpointTests"/> class.
|
||||
@@ -171,19 +171,12 @@ public class GetBooksEndpointTests
|
||||
/// </summary>
|
||||
/// <param name="bookCount">The number of book responses to include in the data collection.</param>
|
||||
/// <returns>A configured paginated response instance.</returns>
|
||||
private static PaginatedResponse<BookResponse> CreatePaginatedResponse(int bookCount, BookResponseFixture bookResponseFixture)
|
||||
private PaginatedResponse<BookResponse> CreatePaginatedResponse(int bookCount, BookResponseFixture bookResponseFixture)
|
||||
{
|
||||
List<BookResponse> books = [];
|
||||
for (int index = 0; index < bookCount; index++)
|
||||
books.Add(bookResponseFixture.Create());
|
||||
|
||||
return new PaginatedResponse<BookResponse>
|
||||
{
|
||||
Data = books,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = bookCount,
|
||||
NumberOfPages = bookCount > 0 ? 1 : 0
|
||||
};
|
||||
return _paginatedResponseFixture.Create(data: books, currentPage: 1, perPage: 10, count: bookCount, numberOfPages: bookCount > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
+12
-15
@@ -3,11 +3,13 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Responses.Common;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooksLite;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -30,6 +32,8 @@ public class GetBooksLiteEndpointTests
|
||||
private readonly IQueryHandler<GetBooksLiteQuery, Result<PaginatedResponse<BookLiteResponse>>> _mockHandler;
|
||||
private readonly GetBooksLiteEndpoint _sut;
|
||||
private readonly GetBooksLiteRequestFixture _getBooksLiteRequestFixture = new();
|
||||
private readonly BookLiteResponseFixture _bookLiteResponseFixture = new();
|
||||
private readonly PaginatedResponseFixture<BookLiteResponse> _paginatedResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetBooksLiteEndpointTests"/> class.
|
||||
@@ -167,24 +171,17 @@ public class GetBooksLiteEndpointTests
|
||||
/// </summary>
|
||||
/// <param name="bookCount">The number of book responses to include in the data collection.</param>
|
||||
/// <returns>A configured paginated response instance.</returns>
|
||||
private static PaginatedResponse<BookLiteResponse> CreatePaginatedResponse(int bookCount)
|
||||
private PaginatedResponse<BookLiteResponse> CreatePaginatedResponse(int bookCount)
|
||||
{
|
||||
List<BookLiteResponse> books = [];
|
||||
for (int index = 0; index < bookCount; index++)
|
||||
books.Add(new BookLiteResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
Title: "Test Book",
|
||||
ReleaseYear: 2001,
|
||||
CoverPath: null
|
||||
books.Add(_bookLiteResponseFixture.Create(
|
||||
id: Guid.NewGuid(),
|
||||
title: "Test Book",
|
||||
releaseYear: 2001,
|
||||
coverPath: null
|
||||
));
|
||||
|
||||
return new PaginatedResponse<BookLiteResponse>
|
||||
{
|
||||
Data = books,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = bookCount,
|
||||
NumberOfPages = bookCount > 0 ? 1 : 0
|
||||
};
|
||||
return _paginatedResponseFixture.Create(data: books, currentPage: 1, perPage: 10, count: bookCount, numberOfPages: bookCount > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.UsersManagement;
|
||||
using Lumina.Contracts.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -23,6 +24,7 @@ public class CheckInitializationEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<CheckInitializationQuery, InitializationResponse> _mockHandler;
|
||||
private readonly CheckInitializationEndpoint _sut;
|
||||
private readonly InitializationResponseFixture _initializationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckInitializationEndpointTests"/> class.
|
||||
@@ -38,7 +40,7 @@ public class CheckInitializationEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
InitializationResponse expectedResponse = new(IsInitialized: true);
|
||||
InitializationResponse expectedResponse = _initializationResponseFixture.Create(isInitialized: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -56,7 +58,7 @@ public class CheckInitializationEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new InitializationResponse(IsInitialized: true));
|
||||
.Returns(_initializationResponseFixture.Create(isInitialized: true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
@@ -81,7 +83,7 @@ public class CheckInitializationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new InitializationResponse(IsInitialized: true);
|
||||
return _initializationResponseFixture.Create(isInitialized: true);
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class SetupApplicationEndpointTests
|
||||
private readonly ICommandHandler<SetupApplicationCommand, Result<RegistrationResponse>> _mockHandler;
|
||||
private readonly SetupApplicationEndpoint _sut;
|
||||
private readonly RegistrationRequestFixture _registrationRequestFixture = new();
|
||||
private readonly RegistrationResponseFixture _registrationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetupApplicationEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class SetupApplicationEndpointTests
|
||||
// Arrange
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
|
||||
RegistrationResponse expectedResponse = _registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123");
|
||||
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -88,7 +90,7 @@ public class SetupApplicationEndpointTests
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
|
||||
.Returns(Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -118,7 +120,7 @@ public class SetupApplicationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
|
||||
return Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123"));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class ChangePasswordEndpointTests
|
||||
private readonly ICommandHandler<ChangePasswordCommand, Result<ChangePasswordResponse>> _mockHandler;
|
||||
private readonly ChangePasswordEndpoint _sut;
|
||||
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
||||
private readonly ChangePasswordResponseFixture _changePasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChangePasswordEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class ChangePasswordEndpointTests
|
||||
// Arrange
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
ChangePasswordResponse expectedResponse = new(IsPasswordChanged: true);
|
||||
ChangePasswordResponse expectedResponse = _changePasswordResponseFixture.Create(isPasswordChanged: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -86,7 +88,7 @@ public class ChangePasswordEndpointTests
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new ChangePasswordResponse(true)));
|
||||
.Returns(Result.From(_changePasswordResponseFixture.Create(isPasswordChanged: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -116,7 +118,7 @@ public class ChangePasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new ChangePasswordResponse(true));
|
||||
return Result.From(_changePasswordResponseFixture.Create(isPasswordChanged: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.UsersManagement.Users;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
|
||||
@@ -25,6 +26,7 @@ public class GetUsersEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUsersQuery, Result<IEnumerable<UserResponse>>> _mockHandler;
|
||||
private readonly GetUsersEndpoint _sut;
|
||||
private readonly UserResponseFixture _userResponseFixture = new();
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUsersEndpointTests"/> class.
|
||||
/// </summary>
|
||||
@@ -41,7 +43,7 @@ public class GetUsersEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<UserResponse> expectedResponse =
|
||||
[
|
||||
new UserResponse(Guid.NewGuid(), "testUser", DateTime.UtcNow, null)
|
||||
_userResponseFixture.Create(username: "testUser", createdOnUtc: DateTime.UtcNow, updatedOnUtc: null)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +28,7 @@ public class LoginEndpointTests
|
||||
private readonly IQueryHandler<LoginUserQuery, Result<LoginResponse>> _mockHandler;
|
||||
private readonly LoginEndpoint _sut;
|
||||
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||
private readonly LoginResponseFixture _loginResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LoginEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class LoginEndpointTests
|
||||
// Arrange
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
LoginResponse expectedResponse = new(Guid.NewGuid(), "testUser", "jwt_token", true);
|
||||
LoginResponse expectedResponse = _loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class LoginEndpointTests
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true)));
|
||||
.Returns(Result.From(_loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -116,7 +118,7 @@ public class LoginEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true));
|
||||
return Result.From(_loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class RecoverPasswordEndpointTests
|
||||
private readonly ICommandHandler<RecoverPasswordCommand, Result<RecoverPasswordResponse>> _mockHandler;
|
||||
private readonly RecoverPasswordEndpoint _sut;
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
private readonly RecoverPasswordResponseFixture _recoverPasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RecoverPasswordEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RecoverPasswordEndpointTests
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RecoverPasswordResponse expectedResponse = new(IsPasswordReset: true);
|
||||
RecoverPasswordResponse expectedResponse = _recoverPasswordResponseFixture.Create(isPasswordReset: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -86,7 +88,7 @@ public class RecoverPasswordEndpointTests
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RecoverPasswordResponse(true)));
|
||||
.Returns(Result.From(_recoverPasswordResponseFixture.Create(isPasswordReset: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -114,7 +116,7 @@ public class RecoverPasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RecoverPasswordResponse(true));
|
||||
return Result.From(_recoverPasswordResponseFixture.Create(isPasswordReset: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class RegisterEndpointTests
|
||||
private readonly ICommandHandler<RegisterUserCommand, Result<RegistrationResponse>> _mockHandler;
|
||||
private readonly RegisterEndpoint _sut;
|
||||
private readonly RegistrationRequestFixture _registrationRequestFixture = new();
|
||||
private readonly RegistrationResponseFixture _registrationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegisterEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RegisterEndpointTests
|
||||
// Arrange
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
|
||||
RegistrationResponse expectedResponse = _registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123");
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class RegisterEndpointTests
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
|
||||
.Returns(Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -117,7 +119,7 @@ public class RegisterEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
|
||||
return Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123"));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+8
-6
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -30,6 +31,7 @@ public class GetAuthorizationEndpointTests
|
||||
private readonly IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly GetAuthorizationEndpoint _sut;
|
||||
private readonly GetAuthorizationRequestFixture _getAuthorizationRequestFixture = new();
|
||||
private readonly AuthorizationResponseFixture _authorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAuthorizationEndpointTests"/> class.
|
||||
@@ -46,10 +48,10 @@ public class GetAuthorizationEndpointTests
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
AuthorizationResponse expectedResponse = new(
|
||||
request.UserId!.Value,
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
AuthorizationResponse expectedResponse = _authorizationResponseFixture.Create(
|
||||
userId: request.UserId!.Value,
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -97,7 +99,7 @@ public class GetAuthorizationEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
.Returns(Result.From(_authorizationResponseFixture.Create(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
@@ -128,7 +130,7 @@ public class GetAuthorizationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new AuthorizationResponse(
|
||||
return Result.From(_authorizationResponseFixture.Create(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
|
||||
+10
-6
@@ -2,6 +2,8 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,8 @@ public class GetUserPermissionsEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserPermissionsQuery, Result<IEnumerable<PermissionResponse>>> _mockHandler;
|
||||
private readonly GetUserPermissionsEndpoint _sut;
|
||||
private readonly PermissionResponseFixture _permissionResponseFixture = new();
|
||||
private readonly GetUserPermissionsRequestFixture _getUserPermissionsRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserPermissionsEndpointTests"/> class.
|
||||
@@ -41,12 +45,12 @@ public class GetUserPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.NewGuid());
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<PermissionResponse> expectedResponse =
|
||||
[
|
||||
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanViewUsers),
|
||||
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers)
|
||||
_permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanViewUsers),
|
||||
_permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -63,7 +67,7 @@ public class GetUserPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.NewGuid());
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("User.Permissions.NotFound", "User permissions not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -90,7 +94,7 @@ public class GetUserPermissionsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserPermissionsRequest request = new(userId);
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(userId: userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>));
|
||||
@@ -122,7 +126,7 @@ public class GetUserPermissionsEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserPermissionsRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getUserPermissionsRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+11
-7
@@ -2,6 +2,8 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -25,6 +27,8 @@ public class GetUserRoleEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserRoleQuery, Result<RoleResponse?>> _mockHandler;
|
||||
private readonly GetUserRoleEndpoint _sut;
|
||||
private readonly RoleResponseFixture _roleResponseFixture = new();
|
||||
private readonly GetUserRoleRequestFixture _getUserRoleRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserRoleEndpointTests"/> class.
|
||||
@@ -39,9 +43,9 @@ public class GetUserRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithRole()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.NewGuid());
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RoleResponse expectedResponse = new(Guid.NewGuid(), "Admin");
|
||||
RoleResponse expectedResponse = _roleResponseFixture.Create(roleName: "Admin");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<RoleResponse?>(expectedResponse));
|
||||
|
||||
@@ -57,7 +61,7 @@ public class GetUserRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.NewGuid());
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("User.Role.NotFound", "User role not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -84,10 +88,10 @@ public class GetUserRoleEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserRoleRequest request = new(userId);
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(userId: userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin")));
|
||||
.Returns(Result.From<RoleResponse?>(_roleResponseFixture.Create(roleName: "Admin")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -112,11 +116,11 @@ public class GetUserRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin"));
|
||||
return Result.From<RoleResponse?>(_roleResponseFixture.Create(roleName: "Admin"));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserRoleRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getUserRoleRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+17
-28
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,8 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<UpdateUserRoleAndPermissionsCommand, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly UpdateUserRoleAndPermissionsEndpoint _sut;
|
||||
private readonly UpdateUserRoleAndPermissionsRequestFixture _updateUserRoleAndPermissionsRequestFixture = new();
|
||||
private readonly AuthorizationResponseFixture _authorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateUserRoleAndPermissionsEndpointTests"/> class.
|
||||
@@ -41,16 +45,11 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithAuthorization()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
AuthorizationResponse expectedResponse = new(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
AuthorizationResponse expectedResponse = _authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -67,11 +66,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Authorization.Update.Failed", "Failed to update user role and permissions.");
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -97,17 +92,12 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendUpdateUserRoleAndPermissionsCommandToSender()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
.Returns(Result.From(_authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
)));
|
||||
|
||||
// Act
|
||||
@@ -136,16 +126,15 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
return Result.From(_authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(
|
||||
new UpdateUserRoleAndPermissionsRequest(Guid.NewGuid(), Guid.NewGuid(), [Guid.NewGuid()]),
|
||||
_updateUserRoleAndPermissionsRequestFixture.Create(),
|
||||
cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
|
||||
@@ -5,6 +5,7 @@ using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Exceptions;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Api;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
@@ -26,7 +27,7 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Api;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ApiHttpClientTests
|
||||
{
|
||||
private const string TEST_ENCRYPTION_KEY = "FLYO0QRo6u2VzoFOgNkkEwYNGtqhJ3QGZd7iAHNEJeM=";
|
||||
private readonly ServerConfigurationDtoFixture _serverConfigurationDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public async Task GetAsync_WhenApiReturnsSuccess_ShouldDeserializeResponseContent()
|
||||
@@ -36,7 +37,7 @@ public class ApiHttpClientTests
|
||||
ApiHttpClient sut = CreateSut(messageHandler);
|
||||
|
||||
// Act
|
||||
Lumina.Presentation.Web.Common.DTO.Libraries.LibraryDto[] result = await sut.GetAsync<Lumina.Presentation.Web.Common.DTO.Libraries.LibraryDto[]>("libraries", CancellationToken.None);
|
||||
Web.Common.DTO.Libraries.LibraryDto[] result = await sut.GetAsync<Web.Common.DTO.Libraries.LibraryDto[]>("libraries", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Single(result);
|
||||
@@ -152,21 +153,35 @@ public class ApiHttpClientTests
|
||||
Assert.Equal("image/png", blob.ContentType);
|
||||
}
|
||||
|
||||
private static ApiHttpClient CreateSut(TestApiHttpMessageHandler messageHandler, string? token = null)
|
||||
/// <summary>
|
||||
/// Creates the system under test configured with the provided message handler.
|
||||
/// </summary>
|
||||
/// <param name="messageHandler">The message handler backing the inner <see cref="HttpClient"/>.</param>
|
||||
/// <param name="token">Optional token claim to place on the current HTTP context user.</param>
|
||||
/// <returns>The created <see cref="ApiHttpClient"/>.</returns>
|
||||
private ApiHttpClient CreateSut(TestApiHttpMessageHandler messageHandler, string? token = null)
|
||||
{
|
||||
HttpClient httpClient = new(messageHandler);
|
||||
IHttpContextAccessor httpContextAccessor = Substitute.For<IHttpContextAccessor>();
|
||||
if (token is not null)
|
||||
{
|
||||
DefaultHttpContext httpContext = new();
|
||||
httpContext.User = new ClaimsPrincipal(new ClaimsIdentity([new Claim("Token", token)], "TestAuthentication"));
|
||||
DefaultHttpContext httpContext = new()
|
||||
{
|
||||
User = new ClaimsPrincipal(new ClaimsIdentity([new Claim("Token", token)], "TestAuthentication"))
|
||||
};
|
||||
httpContextAccessor.HttpContext.Returns(httpContext);
|
||||
}
|
||||
IOptionsSnapshot<ServerConfigurationDto> serverConfigurationOptions = Substitute.For<IOptionsSnapshot<ServerConfigurationDto>>();
|
||||
serverConfigurationOptions.Value.Returns(new ServerConfigurationDto { ApiVersion = '1', BaseAddress = "http://localhost", Port = 5214 });
|
||||
serverConfigurationOptions.Value.Returns(_serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: 5214));
|
||||
return new ApiHttpClient(httpClient, httpContextAccessor, serverConfigurationOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="HttpResponseMessage"/> with the given status code and JSON body.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">The HTTP status code of the response.</param>
|
||||
/// <param name="json">The JSON payload of the response body.</param>
|
||||
/// <returns>The created <see cref="HttpResponseMessage"/>.</returns>
|
||||
private static HttpResponseMessage CreateJsonResponse(HttpStatusCode statusCode, string json)
|
||||
{
|
||||
return new HttpResponseMessage(statusCode)
|
||||
|
||||
+7
-5
@@ -3,6 +3,7 @@ using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Responses.Authorization;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Responses.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -23,6 +24,7 @@ public class AuthorizationServiceTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly AuthorizationService _sut;
|
||||
private readonly Guid _userId;
|
||||
private readonly GetAuthorizationResponseFixture _getAuthorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AuthorizationServiceTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", [AuthorizationPermission.CanCreateLibraries]));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: [AuthorizationPermission.CanCreateLibraries]));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None);
|
||||
@@ -57,7 +59,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", [AuthorizationPermission.CanViewUsers]));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: [AuthorizationPermission.CanViewUsers]));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None);
|
||||
@@ -71,7 +73,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", []));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: []));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.IsInRoleAsync("Admin", CancellationToken.None);
|
||||
@@ -85,7 +87,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "User", []));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "User", permissions: []));
|
||||
|
||||
// Act
|
||||
bool result = await _sut.IsInRoleAsync("Admin", CancellationToken.None);
|
||||
@@ -99,7 +101,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetAsync<GetAuthorizationResponse>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new GetAuthorizationResponse(_userId, "Admin", []));
|
||||
.Returns(_getAuthorizationResponseFixture.Create(userId: _userId, role: "Admin", permissions: []));
|
||||
|
||||
// Act
|
||||
await _sut.HasPermissionAsync(AuthorizationPermission.CanViewUsers, CancellationToken.None);
|
||||
|
||||
+10
-8
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Security;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -15,6 +16,7 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Security;
|
||||
public class CryptographyServiceTests
|
||||
{
|
||||
private const string TEST_ENCRYPTION_KEY = "FLYO0QRo6u2VzoFOgNkkEwYNGtqhJ3QGZd7iAHNEJeM=";
|
||||
private readonly EncryptionSettingsDtoFixture _encryptionSettingsDtoFixture = new();
|
||||
private readonly CryptographyService _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -22,7 +24,7 @@ public class CryptographyServiceTests
|
||||
/// </summary>
|
||||
public CryptographyServiceTests()
|
||||
{
|
||||
EncryptionSettingsDto settings = new() { SecretKey = TEST_ENCRYPTION_KEY };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: TEST_ENCRYPTION_KEY);
|
||||
_sut = new CryptographyService(Options.Create(settings));
|
||||
}
|
||||
|
||||
@@ -30,25 +32,25 @@ public class CryptographyServiceTests
|
||||
public void Encrypt_WhenCalled_ShouldReturnCiphertextThatDecryptsToPlaintext()
|
||||
{
|
||||
// Arrange
|
||||
const string plaintext = "sensitive-data";
|
||||
const string PLAINTEXT = "sensitive-data";
|
||||
|
||||
// Act
|
||||
string ciphertext = _sut.Encrypt(plaintext);
|
||||
string ciphertext = _sut.Encrypt(PLAINTEXT);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(plaintext, ciphertext);
|
||||
Assert.Equal(plaintext, _sut.Decrypt(ciphertext));
|
||||
Assert.NotEqual(PLAINTEXT, ciphertext);
|
||||
Assert.Equal(PLAINTEXT, _sut.Decrypt(ciphertext));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Encrypt_WhenCalledTwice_ShouldReturnDifferentCiphertexts()
|
||||
{
|
||||
// Arrange
|
||||
const string plaintext = "sensitive-data";
|
||||
const string PLAINTEXT = "sensitive-data";
|
||||
|
||||
// Act
|
||||
string firstCiphertext = _sut.Encrypt(plaintext);
|
||||
string secondCiphertext = _sut.Encrypt(plaintext);
|
||||
string firstCiphertext = _sut.Encrypt(PLAINTEXT);
|
||||
string secondCiphertext = _sut.Encrypt(PLAINTEXT);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstCiphertext, secondCiphertext);
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Validators;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.UnitTests.Common.Setup;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -16,13 +17,14 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Validators;
|
||||
public class EncryptionSettingsModelValidatorTests
|
||||
{
|
||||
private const string VALID_BASE64_KEY = "FLYO0QRo6u2VzoFOgNkkEwYNGtqhJ3QGZd7iAHNEJeM=";
|
||||
private readonly EncryptionSettingsDtoFixture _encryptionSettingsDtoFixture = new();
|
||||
private readonly EncryptionSettingsDtoValidator _validator = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenSecretKeyIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
EncryptionSettingsDto settings = new() { SecretKey = string.Empty };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: string.Empty);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(settings);
|
||||
@@ -35,7 +37,7 @@ public class EncryptionSettingsModelValidatorTests
|
||||
public void Validate_WhenSecretKeyIsNotBase64_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
EncryptionSettingsDto settings = new() { SecretKey = "not-base64-key!" };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: "not-base64-key!");
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(settings);
|
||||
@@ -48,7 +50,7 @@ public class EncryptionSettingsModelValidatorTests
|
||||
public void Validate_WhenSecretKeyIsValidBase64_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
EncryptionSettingsDto settings = new() { SecretKey = VALID_BASE64_KEY };
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: VALID_BASE64_KEY);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(settings);
|
||||
|
||||
+6
-4
@@ -2,6 +2,7 @@
|
||||
using Lumina.Presentation.Web.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Validators;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Configuration;
|
||||
using Lumina.Presentation.Web.UnitTests.Common.Setup;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -15,13 +16,14 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Validators;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ServerConfigurationModelValidatorTests
|
||||
{
|
||||
private readonly ServerConfigurationDtoFixture _serverConfigurationDtoFixture = new();
|
||||
private readonly ServerConfigurationDtoValidator _validator = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenBaseAddressIsEmpty_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = string.Empty, Port = 5214 };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: string.Empty, port: 5214);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
@@ -36,7 +38,7 @@ public class ServerConfigurationModelValidatorTests
|
||||
public void Validate_WhenPortIsAtBoundary_ShouldNotHaveValidationError(ushort port)
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = "http://localhost", Port = port };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: port);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
@@ -51,7 +53,7 @@ public class ServerConfigurationModelValidatorTests
|
||||
public void Validate_WhenApiVersionIsAtBoundary_ShouldNotHaveValidationError(char apiVersion)
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = apiVersion, BaseAddress = "http://localhost", Port = 5214 };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: apiVersion, baseAddress: "http://localhost", port: 5214);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
@@ -64,7 +66,7 @@ public class ServerConfigurationModelValidatorTests
|
||||
public void Validate_WhenConfigurationIsValid_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
ServerConfigurationDto configuration = new() { ApiVersion = '1', BaseAddress = "http://localhost", Port = 5214 };
|
||||
ServerConfigurationDto configuration = _serverConfigurationDtoFixture.Create(apiVersion: '1', baseAddress: "http://localhost", port: 5214);
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(configuration);
|
||||
|
||||
+5
-1
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Requests.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Authorization.Roles.AddRole;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Authorization;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -29,6 +30,9 @@ public class AddRoleEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly AddRoleEndpoint _sut;
|
||||
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly PermissionDtoFixture _permissionDtoFixture = new();
|
||||
private readonly RolePermissionsDtoFixture _rolePermissionsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddRoleEndpointTests"/> class.
|
||||
@@ -44,7 +48,7 @@ public class AddRoleEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create();
|
||||
RolePermissionsDto expectedResponse = new(new RoleDto(Guid.NewGuid(), request.RoleName!), [new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]);
|
||||
RolePermissionsDto expectedResponse = _rolePermissionsDtoFixture.Create(role: _roleDtoFixture.Create(id: Guid.NewGuid(), roleName: request.RoleName!), permissions: [_permissionDtoFixture.Create(id: Guid.NewGuid(), permission: AuthorizationPermission.CanViewUsers)]);
|
||||
_mockApiHttpClient.PostAsync<RolePermissionsDto, AddRoleRequest>(Arg.Any<string>(), Arg.Any<AddRoleRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
|
||||
+5
-7
@@ -1,15 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DeleteTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -25,6 +24,7 @@ public class DeleteThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly DeleteThemeEndpoint _sut;
|
||||
private readonly DeleteThemeRequestFixture _deleteThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteThemeEndpointTests"/> class.
|
||||
@@ -43,14 +43,12 @@ public class DeleteThemeEndpointTests
|
||||
string themeId = "editorial-paper";
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new DeleteThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_deleteThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
using (System.Text.Json.JsonDocument jsonDocument = System.Text.Json.JsonDocument.Parse(body))
|
||||
{
|
||||
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +59,7 @@ public class DeleteThemeEndpointTests
|
||||
string expectedEndpoint = ApiRoutes.Themes.DELETE_THEME.Replace("{themeId}", themeId);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new DeleteThemeRequest(themeId), CancellationToken.None);
|
||||
await _sut.ExecuteAsync(_deleteThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).DeleteAsync(expectedEndpoint, Arg.Any<CancellationToken>());
|
||||
@@ -74,7 +72,7 @@ public class DeleteThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new DeleteThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_deleteThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+9
-8
@@ -2,16 +2,15 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.DownloadTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -26,6 +25,8 @@ public class DownloadThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly DownloadThemeEndpoint _sut;
|
||||
private readonly GetThemeArchiveRequestFixture _getThemeArchiveRequestFixture = new();
|
||||
private readonly BlobDataDtoFixture _blobDataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DownloadThemeEndpointTests"/> class.
|
||||
@@ -43,10 +44,10 @@ public class DownloadThemeEndpointTests
|
||||
// Arrange
|
||||
string themeId = "editorial-paper";
|
||||
_mockApiHttpClient.GetBlobAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new BlobDataDto { Data = [0x50, 0x4B, 0x03, 0x04], ContentType = "application/zip" });
|
||||
.Returns(_blobDataDtoFixture.Create(data: [0x50, 0x4B, 0x03, 0x04], contentType: "application/zip"));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeArchiveRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeArchiveRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
FileStreamHttpResult fileResult = Assert.IsType<FileStreamHttpResult>(result);
|
||||
@@ -61,10 +62,10 @@ public class DownloadThemeEndpointTests
|
||||
string themeId = "editorial-paper";
|
||||
string expectedEndpoint = ApiRoutes.Themes.GET_THEME_ARCHIVE.Replace("{themeId}", themeId);
|
||||
_mockApiHttpClient.GetBlobAsync(expectedEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new BlobDataDto { Data = [1, 2, 3], ContentType = "application/zip" });
|
||||
.Returns(_blobDataDtoFixture.Create(data: [1, 2, 3], contentType: "application/zip"));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new GetThemeArchiveRequest(themeId), CancellationToken.None);
|
||||
await _sut.ExecuteAsync(_getThemeArchiveRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).GetBlobAsync(expectedEndpoint, Arg.Any<CancellationToken>());
|
||||
@@ -77,7 +78,7 @@ public class DownloadThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeArchiveRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeArchiveRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+5
-5
@@ -2,15 +2,14 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.RestoreTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -26,6 +25,7 @@ public class RestoreThemeEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly RestoreThemeEndpoint _sut;
|
||||
private readonly RestoreThemeRequestFixture _restoreThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreThemeEndpointTests"/> class.
|
||||
@@ -44,7 +44,7 @@ public class RestoreThemeEndpointTests
|
||||
string themeId = "editorial-paper";
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new RestoreThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
@@ -62,7 +62,7 @@ public class RestoreThemeEndpointTests
|
||||
string expectedEndpoint = ApiRoutes.Themes.RESTORE_THEME.Replace("{themeId}", themeId);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new RestoreThemeRequest(themeId), CancellationToken.None);
|
||||
await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockApiHttpClient.Received(1).PostAsync<ThemeResponseDto, object>(expectedEndpoint, Arg.Any<object>(), Arg.Any<CancellationToken>());
|
||||
@@ -75,7 +75,7 @@ public class RestoreThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new RestoreThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_restoreThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+4
-4
@@ -2,16 +2,15 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -28,6 +27,7 @@ public class SetCurrentThemeEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly SetCurrentThemeEndpoint _sut;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointTests"/> class.
|
||||
@@ -48,7 +48,7 @@ public class SetCurrentThemeEndpointTests
|
||||
.Returns(_themeResponseDtoFixture.Create());
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetCurrentThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setCurrentThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
string body = await JsonResultTestHelper.GetResponseBodyAsync(result);
|
||||
|
||||
// Assert
|
||||
@@ -68,7 +68,7 @@ public class SetCurrentThemeEndpointTests
|
||||
public async Task ExecuteAsync_WhenThemeIdIsBlank_ShouldReturnProblemWithBadRequest(string? themeId)
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetCurrentThemeRequest(themeId), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setCurrentThemeRequestFixture.Create(themeId: themeId), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+3
-1
@@ -5,6 +5,7 @@ using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.FileSystemManagement.Directories.GetDirectories;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -27,6 +28,7 @@ public class GetDirectoriesEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly GetDirectoriesEndpoint _sut;
|
||||
private readonly GetDirectoriesRequestFixture _getDirectoriesRequestFixture = new();
|
||||
private readonly DirectoryDtoFixture _directoryDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class GetDirectoriesEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _getDirectoriesRequestFixture.Create(path: "/media", includeHiddenElements: true);
|
||||
DirectoryDto[] expectedDirectories = [new DirectoryDto { Path = "/media/books", Name = "books" }];
|
||||
DirectoryDto[] expectedDirectories = [_directoryDtoFixture.Create(path: "/media/books", name: "books")];
|
||||
_mockApiHttpClient.GetAsync<DirectoryDto[]>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedDirectories);
|
||||
|
||||
|
||||
+4
-2
@@ -5,6 +5,7 @@ using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.FileSystemManagement.Path.ValidatePath;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -27,6 +28,7 @@ public class ValidatePathEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly ValidatePathEndpoint _sut;
|
||||
private readonly ValidatePathRequestFixture _validatePathRequestFixture = new();
|
||||
private readonly PathValidDtoFixture _pathValidDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ValidatePathEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class ValidatePathEndpointTests
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(path: "/media/books");
|
||||
_mockApiHttpClient.GetAsync<PathValidDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathValidDto(true));
|
||||
.Returns(_pathValidDtoFixture.Create(isValid: true));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -63,7 +65,7 @@ public class ValidatePathEndpointTests
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(path: "C:/invalid|path");
|
||||
_mockApiHttpClient.GetAsync<PathValidDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathValidDto(false));
|
||||
.Returns(_pathValidDtoFixture.Create(isValid: false));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
+14
-13
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Enums.Common;
|
||||
using Lumina.Presentation.Web.Common.Requests.Libraries;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetLibraryItems;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Libraries;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -29,6 +30,8 @@ public class GetLibraryItemsEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly GetLibraryItemsEndpoint _sut;
|
||||
private readonly GetBooksLiteRequestFixture _getBooksLiteRequestFixture = new();
|
||||
private readonly PaginatedBookLiteDtoFixture _paginatedBookLiteDtoFixture = new();
|
||||
private readonly BookLiteDtoFixture _bookLiteDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibraryItemsEndpointTests"/> class.
|
||||
@@ -48,11 +51,11 @@ public class GetLibraryItemsEndpointTests
|
||||
perPage: 48,
|
||||
searchTerm: "the hobbit",
|
||||
filterAlphaKey: "H",
|
||||
ignoreThePrefixForAlphaPicker: true,
|
||||
shouldIgnoreThePrefixForAlphaPicker: true,
|
||||
sortBy: "title",
|
||||
sortOrder: SortOrder.Ascending);
|
||||
_mockApiHttpClient.GetAsync<PaginatedBookLiteDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PaginatedBookLiteDto());
|
||||
.Returns(_paginatedBookLiteDtoFixture.Create());
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -66,7 +69,7 @@ public class GetLibraryItemsEndpointTests
|
||||
endpoint.Contains("perPage=48") &&
|
||||
endpoint.Contains("searchTerm=the%20hobbit") &&
|
||||
endpoint.Contains("filterAlphaKey=H") &&
|
||||
endpoint.Contains("ignoreThePrefixForAlphaPicker=True") &&
|
||||
endpoint.Contains("shouldIgnoreThePrefixForAlphaPicker=True") &&
|
||||
endpoint.Contains("sortBy=title") &&
|
||||
endpoint.Contains("sortOrder=Ascending")),
|
||||
Arg.Any<CancellationToken>());
|
||||
@@ -78,7 +81,7 @@ public class GetLibraryItemsEndpointTests
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
_mockApiHttpClient.GetAsync<PaginatedBookLiteDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PaginatedBookLiteDto());
|
||||
.Returns(_paginatedBookLiteDtoFixture.Create());
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -87,7 +90,7 @@ public class GetLibraryItemsEndpointTests
|
||||
await _mockApiHttpClient.Received(1).GetAsync<PaginatedBookLiteDto>(
|
||||
Arg.Is<string>(endpoint =>
|
||||
endpoint.StartsWith(ApiRoutes.Books.GET_BOOKS_LITE, StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.EndsWith($"libraryId={request.LibraryId}&ignoreThePrefixForAlphaPicker=False", StringComparison.OrdinalIgnoreCase) &&
|
||||
endpoint.EndsWith($"libraryId={request.LibraryId}&shouldIgnoreThePrefixForAlphaPicker=False", StringComparison.OrdinalIgnoreCase) &&
|
||||
!endpoint.Contains("currentPage=") &&
|
||||
!endpoint.Contains("searchTerm=") &&
|
||||
!endpoint.Contains("sortBy=")),
|
||||
@@ -99,14 +102,12 @@ public class GetLibraryItemsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteRequest request = _getBooksLiteRequestFixture.Create();
|
||||
PaginatedBookLiteDto expectedResponse = new()
|
||||
{
|
||||
CurrentPage = 1,
|
||||
PerPage = 48,
|
||||
Count = 1,
|
||||
NumberOfPages = 1,
|
||||
Data = [new BookLiteDto { Id = Guid.NewGuid(), Title = "Test Book" }]
|
||||
};
|
||||
PaginatedBookLiteDto expectedResponse = _paginatedBookLiteDtoFixture.Create(
|
||||
data: [_bookLiteDtoFixture.Create(title: "Test Book")],
|
||||
currentPage: 1,
|
||||
perPage: 48,
|
||||
count: 1,
|
||||
numberOfPages: 1);
|
||||
_mockApiHttpClient.GetAsync<PaginatedBookLiteDto>(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
|
||||
+8
-6
@@ -5,19 +5,19 @@ using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Index;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -38,6 +38,8 @@ public class BooksIndexViewEndpointTests
|
||||
private readonly IStringLocalizer _mockStringLocalizer;
|
||||
private readonly BooksIndexViewEndpoint _sut;
|
||||
private readonly LibraryDtoFixture _libraryDtoFixture = new();
|
||||
private readonly GetBooksViewRequestFixture _getBooksViewRequestFixture = new();
|
||||
private readonly ThemePageRenderResultDtoFixture _themePageRenderResultDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BooksIndexViewEndpointTests"/> class.
|
||||
@@ -63,7 +65,7 @@ public class BooksIndexViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED).Returns("http://localhost/en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetBooksViewRequest(null), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getBooksViewRequestFixture.Create(libraryId: null), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -82,10 +84,10 @@ public class BooksIndexViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Books.GET_LIBRARY_ITEMS).Returns("http://localhost/en-us/library/written-content-library/books-library/books/api-get-library-items");
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Settings.GET_USER_SETTINGS).Returns("http://localhost/en-us/tools/settings/api-get-user-settings");
|
||||
_mockThemePageRenderer.RenderAsync(Arg.Any<ThemePageDto>(), Arg.Any<string?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new ThemePageRenderResultDto("<section>content</section>", "<script>script</script>")));
|
||||
.Returns(Result.From(_themePageRenderResultDtoFixture.Create(content: "<section>content</section>", script: "<script>script</script>")));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetBooksViewRequest(expectedLibrary.Id), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getBooksViewRequestFixture.Create(libraryId: expectedLibrary.Id), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RazorViewResult>(result);
|
||||
@@ -115,7 +117,7 @@ public class BooksIndexViewEndpointTests
|
||||
.Returns(Result<ThemePageRenderResultDto>.Failure(Error.Failure("Theme.Render", "The page could not be rendered.")));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetBooksViewRequest(expectedLibrary.Id), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getBooksViewRequestFixture.Create(libraryId: expectedLibrary.Id), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RazorViewResult>(result);
|
||||
|
||||
+7
-6
@@ -1,14 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Themes.ThemeAssets;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.FileSystemManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -24,6 +23,8 @@ public class ThemeAssetsEndpointTests
|
||||
{
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly ThemeAssetsEndpoint _sut;
|
||||
private readonly GetThemeAssetRequestFixture _getThemeAssetRequestFixture = new();
|
||||
private readonly BlobDataDtoFixture _blobDataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeAssetsEndpointTests"/> class.
|
||||
@@ -39,10 +40,10 @@ public class ThemeAssetsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
_mockApiHttpClient.GetBlobAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new BlobDataDto { Data = [1, 2, 3], ContentType = "text/css" });
|
||||
.Returns(_blobDataDtoFixture.Create(data: [1, 2, 3], contentType: "text/css"));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeAssetRequest(ThemeId: "editorial-paper", Path: "assets/style.css"), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeAssetRequestFixture.Create(themeId: "editorial-paper", path: "assets/style.css"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
FileContentHttpResult fileResult = Assert.IsType<FileContentHttpResult>(result);
|
||||
@@ -57,7 +58,7 @@ public class ThemeAssetsEndpointTests
|
||||
public async Task ExecuteAsync_WhenAssetPathMissing_ShouldReturnProblem()
|
||||
{
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new GetThemeAssetRequest(ThemeId: "editorial-paper", Path: null), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_getThemeAssetRequestFixture.Create(themeId: "editorial-paper", path: null), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
|
||||
+5
-4
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Requests.Tools;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Tools.Language.SetLanguage;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Tools;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -20,6 +20,7 @@ namespace Lumina.Presentation.Web.UnitTests.Core.Endpoints.Tools.Language.SetLan
|
||||
public class SetLanguageEndpointTests
|
||||
{
|
||||
private readonly SetLanguageEndpoint _sut;
|
||||
private readonly SetLanguageRequestFixture _setLanguageRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetLanguageEndpointTests"/> class.
|
||||
@@ -36,7 +37,7 @@ public class SetLanguageEndpointTests
|
||||
TestHttpContextFactory.ConfigureCulture(_sut.HttpContext, "en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetLanguageRequest("de-DE", null), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setLanguageRequestFixture.Create(newCulture: "de-DE"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -54,7 +55,7 @@ public class SetLanguageEndpointTests
|
||||
TestHttpContextFactory.ConfigureCulture(_sut.HttpContext, "en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetLanguageRequest("de-DE", "/en-us/tools/settings"), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setLanguageRequestFixture.Create(newCulture: "de-DE", returnUrl: "/en-us/tools/settings"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -69,7 +70,7 @@ public class SetLanguageEndpointTests
|
||||
_sut.HttpContext.Request.PathBase = "/lumina";
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new SetLanguageRequest("fr-FR", "/en-us/tools/settings"), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_setLanguageRequestFixture.Create(newCulture: "fr-FR", returnUrl: "/en-us/tools/settings"), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
|
||||
+6
-6
@@ -1,15 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Lumina.Presentation.Web.Common.Requests.UsersManagement.Authentication;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.UsersManagement.Authentication.Login;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement.Authentication;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -26,6 +25,7 @@ public class LoginViewEndpointTests
|
||||
{
|
||||
private readonly IUrlService _mockUrlService;
|
||||
private readonly LoginViewEndpoint _sut;
|
||||
private readonly LoginViewRequestFixture _loginViewRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LoginViewEndpointTests"/> class.
|
||||
@@ -45,7 +45,7 @@ public class LoginViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED).Returns("http://localhost/en-us");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new LoginViewRequest(), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_loginViewRequestFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -57,7 +57,7 @@ public class LoginViewEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuperAdminSetupPending_ShouldRedirectToRegisterView()
|
||||
{
|
||||
// Arrange
|
||||
Microsoft.AspNetCore.Http.ISession session = Substitute.For<Microsoft.AspNetCore.Http.ISession>();
|
||||
ISession session = Substitute.For<ISession>();
|
||||
byte[] pendingBytes = Encoding.UTF8.GetBytes("true");
|
||||
#pragma warning disable CS8601 // possible null reference assignment in the NSubstitute out-argument stub
|
||||
session.TryGetValue(HttpContextItemKeys.PENDING_SUPER_ADMIN_SETUP, out Arg.Any<byte[]>()).Returns(callInfo =>
|
||||
@@ -70,7 +70,7 @@ public class LoginViewEndpointTests
|
||||
_mockUrlService.GetAbsoluteUrl(WebRoutes.Authentication.REGISTER_VIEW).Returns("http://localhost/en-us/auth/register");
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new LoginViewRequest(), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_loginViewRequestFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
RedirectHttpResult redirectResult = Assert.IsType<RedirectHttpResult>(result);
|
||||
@@ -85,7 +85,7 @@ public class LoginViewEndpointTests
|
||||
TestHttpContextFactory.ConfigureSession(_sut.HttpContext, TestHttpContextFactory.CreateSession());
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new LoginViewRequest(), CancellationToken.None);
|
||||
IResult result = await _sut.ExecuteAsync(_loginViewRequestFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RazorViewResult>(result);
|
||||
|
||||
+3
-1
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.UsersManagement.Authentication.RecoverPassword;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NSubstitute;
|
||||
@@ -26,6 +27,7 @@ public class RecoverPasswordEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly RecoverPasswordEndpoint _sut;
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
private readonly RecoverPasswordResponseFixture _recoverPasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RecoverPasswordEndpointTests"/> class.
|
||||
@@ -41,7 +43,7 @@ public class RecoverPasswordEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
RecoverPasswordResponse expectedResponse = new(true);
|
||||
RecoverPasswordResponse expectedResponse = _recoverPasswordResponseFixture.Create(isPasswordReset: true);
|
||||
_mockApiHttpClient.PostAsync<RecoverPasswordResponse, RecoverPasswordRequest>(Arg.Any<string>(), Arg.Any<RecoverPasswordRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
|
||||
+4
-2
@@ -6,6 +6,7 @@ using Lumina.Presentation.Web.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.UsersManagement.Authentication.Register;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NSubstitute;
|
||||
@@ -26,6 +27,7 @@ public class RegisterEndpointTests
|
||||
private readonly IApiHttpClient _mockApiHttpClient;
|
||||
private readonly RegisterEndpoint _sut;
|
||||
private readonly RegisterRequestFixture _registerRequestFixture = new();
|
||||
private readonly RegisterResponseFixture _registerResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegisterEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RegisterEndpointTests
|
||||
// Arrange
|
||||
RegisterRequest request = _registerRequestFixture.Create(registrationType: "Admin");
|
||||
_mockApiHttpClient.PostAsync<RegisterResponse, RegisterRequest>(Arg.Any<string>(), Arg.Any<RegisterRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new RegisterResponse(request.Username, null));
|
||||
.Returns(_registerResponseFixture.Create(username: request.Username));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
@@ -63,7 +65,7 @@ public class RegisterEndpointTests
|
||||
// Arrange
|
||||
RegisterRequest request = _registerRequestFixture.Create(registrationType: "User");
|
||||
_mockApiHttpClient.PostAsync<RegisterResponse, RegisterRequest>(Arg.Any<string>(), Arg.Any<RegisterRequest>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new RegisterResponse(request.Username, null));
|
||||
.Returns(_registerResponseFixture.Create(username: request.Username));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, CancellationToken.None);
|
||||
|
||||
+28
-11
@@ -11,7 +11,6 @@ using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
@@ -46,6 +45,9 @@ public class ThemeLayoutRendererTests
|
||||
private readonly IView _mockAudioPlayerView;
|
||||
private readonly IView _mockScriptsView;
|
||||
private readonly IView _mockNavMenuView;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly ThemeTemplateResponseDtoFixture _themeTemplateResponseDtoFixture = new();
|
||||
private readonly ThemeLayoutPageDtoFixture _themeLayoutPageDtoFixture = new();
|
||||
private readonly ThemeLayoutRenderer _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -90,9 +92,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: TestHttpContextFactory.CreateAuthenticatedUser()));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}|{{assetBase}}|{{{appHead}}}|{{{nav}}}|{{{content}}}|{{{audioPlayer}}}|{{{appScripts}}}|{{{scripts}}}|{{mainStyle}}", navTemplate: "nav:{{siteName}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", "<page-script>");
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: "<page-script>");
|
||||
|
||||
// Act
|
||||
Result<string> result = await _sut.RenderAsync(page, "editorial", CancellationToken.None);
|
||||
@@ -107,9 +109,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: null));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}|{{assetBase}}|{{{appHead}}}|{{{nav}}}|{{{content}}}|{{{audioPlayer}}}|{{{appScripts}}}|{{{scripts}}}|{{mainStyle}}", navTemplate: "nav:{{siteName}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", "<page-script>");
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: "<page-script>");
|
||||
|
||||
// Act
|
||||
Result<string> result = await _sut.RenderAsync(page, "editorial", CancellationToken.None);
|
||||
@@ -124,9 +126,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: null));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}|{{{nav}}}", navTemplate: "{{#unclosed}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", string.Empty);
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: string.Empty);
|
||||
|
||||
// Act
|
||||
Result<string> result = await _sut.RenderAsync(page, "editorial", CancellationToken.None);
|
||||
@@ -142,9 +144,9 @@ public class ThemeLayoutRendererTests
|
||||
{
|
||||
// Arrange
|
||||
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: null));
|
||||
ThemeResponseDto theme = new ThemeResponseDtoFixture().Create(themeId: "editorial");
|
||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "editorial");
|
||||
SetupRenderDocuments(theme, layoutTemplate: "{{title}}", navTemplate: "nav:{{siteName}}");
|
||||
ThemeLayoutPageDto page = new("My Page", "<main>", string.Empty);
|
||||
ThemeLayoutPageDto page = _themeLayoutPageDtoFixture.Create(title: "My Page", content: "<main>", script: string.Empty);
|
||||
string layoutEndpoint = ApiRoutes.Themes.GET_THEME_TEMPLATE
|
||||
.Replace("{themeId}", "editorial")
|
||||
.Replace("{*pageKey}", "shared/layout");
|
||||
@@ -160,6 +162,12 @@ public class ThemeLayoutRendererTests
|
||||
await _mockApiHttpClient.Received(1).GetAsync<ThemeTemplateResponseDto>(navEndpoint, Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stubs the API responses that return the layout and navigation menu templates of the given theme.
|
||||
/// </summary>
|
||||
/// <param name="theme">The theme whose layout and navigation menu templates are stubbed.</param>
|
||||
/// <param name="layoutTemplate">The template returned for the layout document.</param>
|
||||
/// <param name="navTemplate">The template returned for the navigation menu document.</param>
|
||||
private void SetupRenderDocuments(ThemeResponseDto theme, string layoutTemplate, string navTemplate)
|
||||
{
|
||||
string layoutEndpoint = ApiRoutes.Themes.GET_THEME_TEMPLATE
|
||||
@@ -169,11 +177,16 @@ public class ThemeLayoutRendererTests
|
||||
.Replace("{themeId}", theme.ThemeId)
|
||||
.Replace("{*pageKey}", "shared/nav-menu");
|
||||
_mockApiHttpClient.GetAsync<ThemeTemplateResponseDto>(layoutEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new ThemeTemplateResponseDto(theme, layoutTemplate));
|
||||
.Returns(_themeTemplateResponseDtoFixture.Create(theme: theme, template: layoutTemplate));
|
||||
_mockApiHttpClient.GetAsync<ThemeTemplateResponseDto>(navEndpoint, Arg.Any<CancellationToken>())
|
||||
.Returns(new ThemeTemplateResponseDto(theme, navTemplate));
|
||||
.Returns(_themeTemplateResponseDtoFixture.Create(theme: theme, template: navTemplate));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a substitute view that renders the given markup.
|
||||
/// </summary>
|
||||
/// <param name="markup">The markup rendered by the view.</param>
|
||||
/// <returns>The created substitute view.</returns>
|
||||
private static IView CreateView(string markup)
|
||||
{
|
||||
IView view = Substitute.For<IView>();
|
||||
@@ -186,6 +199,10 @@ public class ThemeLayoutRendererTests
|
||||
return view;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a substitute string localizer that returns a string prefixed with "Localized-".
|
||||
/// </summary>
|
||||
/// <returns>The created substitute string localizer.</returns>
|
||||
private static IStringLocalizer CreateLocalizer()
|
||||
{
|
||||
IStringLocalizer localizer = Substitute.For<IStringLocalizer>();
|
||||
|
||||
Loaded 100 of 388 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user