mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 02:11:10 +00:00
Returns the unit of work save changes result
This commit is contained in:
1 parent
f3e465255e
commit
64ef3a1e22
141 files changed
+1388
-1151
No files matched your search
+15
-12
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -46,6 +48,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockPermissionRepository = Substitute.For<IPermissionRepository>();
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_userId = Guid.NewGuid();
|
||||
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
@@ -62,7 +65,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetPermissionsQuery query = _getPermissionsQueryFixture.Create();
|
||||
IEnumerable<PermissionEntity> permissions =
|
||||
List<PermissionEntity> permissions =
|
||||
[
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers),
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers)
|
||||
@@ -70,8 +73,8 @@ public class GetPermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(permissions));
|
||||
_mockPermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PermissionEntity> { Data = permissions, CurrentPage = 1, PerPage = permissions.Count, Count = permissions.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -80,7 +83,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(2, result.Value.Count());
|
||||
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -99,7 +102,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -116,7 +119,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -128,7 +131,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockPermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -138,7 +141,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -146,7 +149,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetPermissionsQuery query = _getPermissionsQueryFixture.Create();
|
||||
IEnumerable<PermissionEntity> permissions =
|
||||
List<PermissionEntity> permissions =
|
||||
[
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)
|
||||
];
|
||||
@@ -154,8 +157,8 @@ public class GetPermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(permissions));
|
||||
_mockPermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PermissionEntity> { Data = permissions, CurrentPage = 1, PerPage = permissions.Count, Count = permissions.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, cancellationToken);
|
||||
@@ -164,6 +167,6 @@ public class GetPermissionsQueryHandlerTests
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Single(result.Value);
|
||||
await _mockAuthorizationService.Received(1).IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPermissionRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+1
@@ -49,6 +49,7 @@ public class AddRoleCommandHandlerTests
|
||||
mockValidator.Validate(Arg.Any<AddRoleCommand>())
|
||||
.Returns([]);
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
|
||||
+7
-6
@@ -43,6 +43,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
mockValidator.Validate(Arg.Any<DeleteRoleCommand>())
|
||||
.Returns([]);
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -89,7 +90,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -100,7 +101,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
@@ -121,7 +122,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(adminRole);
|
||||
|
||||
// Act
|
||||
@@ -142,7 +143,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -164,7 +165,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(role);
|
||||
_mockRoleRepository.DeleteByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
@@ -187,7 +188,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(role);
|
||||
_mockRoleRepository.DeleteByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
|
||||
+4
-3
@@ -49,6 +49,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
mockValidator.Validate(Arg.Any<UpdateRoleCommand>())
|
||||
.Returns([]);
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -130,7 +131,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns(true);
|
||||
_mockRoleRepository.UpdateAsync(Arg.Any<RoleEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -151,7 +152,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns(true);
|
||||
_mockRoleRepository.UpdateAsync(Arg.Any<RoleEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
@@ -178,7 +179,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns(true);
|
||||
_mockRoleRepository.UpdateAsync(Arg.Any<RoleEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(role);
|
||||
|
||||
// Act
|
||||
|
||||
+6
-5
@@ -47,6 +47,7 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
mockValidator.Validate(Arg.Any<GetRolePermissionsQuery>())
|
||||
.Returns([]);
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -76,7 +77,7 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -93,7 +94,7 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,7 +106,7 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(query.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(query.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -124,7 +125,7 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(query.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(query.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
@@ -153,7 +154,7 @@ public class GetRolePermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetByIdAsync(query.RoleId, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(query.RoleId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(role);
|
||||
|
||||
// Act
|
||||
|
||||
+9
-6
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -41,6 +43,7 @@ public class GetRolesQueryHandlerTests
|
||||
public GetRolesQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -69,7 +72,7 @@ public class GetRolesQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockRoleRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -86,7 +89,7 @@ public class GetRolesQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockRoleRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -98,7 +101,7 @@ public class GetRolesQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -114,7 +117,7 @@ public class GetRolesQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetRolesQuery query = _getRolesQueryFixture.Create();
|
||||
IEnumerable<RoleEntity> roles =
|
||||
List<RoleEntity> roles =
|
||||
[
|
||||
_roleEntityFixture.Create(roleName: "Admin"),
|
||||
_roleEntityFixture.Create(roleName: "User")
|
||||
@@ -122,8 +125,8 @@ public class GetRolesQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockRoleRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(roles));
|
||||
_mockRoleRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<RoleEntity> { Data = roles, CurrentPage = 1, PerPage = roles.Count, Count = roles.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
+46
-37
@@ -5,6 +5,8 @@ using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.Seed;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
@@ -22,7 +24,6 @@ using Lumina.Domain.SharedKernel.Common.Enums.Scheduling;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -57,6 +58,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
public SetupApplicationCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockHashService = Substitute.For<IPasswordHashService>();
|
||||
_mockCryptographyService = Substitute.For<ICryptographyService>();
|
||||
_mockTotpTokenGenerator = Substitute.For<ITotpTokenGenerator>();
|
||||
@@ -75,8 +77,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
_mockDateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
|
||||
_mockDataSeedService.SetDefaultScheduledJobsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<ScheduledJobEntity>()));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new SetupApplicationCommandHandler(
|
||||
_mockUnitOfWork,
|
||||
@@ -97,8 +99,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create() with { Use2fa = false };
|
||||
string hashedPassword = Uri.EscapeDataString("hashedPassword");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockHashService.HashString(command.Password!)
|
||||
.Returns(hashedPassword);
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
@@ -121,7 +123,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.Equal(command.Username, result.Value.Username);
|
||||
Assert.Null(result.Value.TotpSecret);
|
||||
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -136,8 +138,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
string qrCodeUri = "data:image/png;base64,test";
|
||||
string encryptedSecret = "encryptedSecret";
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockHashService.HashString(command.Password!)
|
||||
.Returns(hashedPassword);
|
||||
_mockTotpTokenGenerator.GenerateSecret()
|
||||
@@ -166,7 +168,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.Equal(command.Username, result.Value.Username);
|
||||
Assert.Equal(qrCodeUri, result.Value.TotpSecret);
|
||||
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -178,8 +180,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
UserEntity existingUser = _userEntityFixture.Create();
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new[] { existingUser });
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [existingUser], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
@@ -188,7 +190,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.AdminAccountAlreadyCreated, result.FirstError);
|
||||
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -200,7 +202,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to retrieve users");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -210,7 +212,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -222,8 +224,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to insert user");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
@@ -234,7 +236,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -246,8 +248,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to set default permissions");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -271,8 +273,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to set default roles");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -299,8 +301,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to set admin role permissions");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -330,8 +332,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to set admin role to administrator account");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -364,8 +366,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to seed default scheduled jobs");
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -396,8 +398,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
// Arrange
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -433,8 +435,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
ScheduledJobEntity activeScheduledJob2 = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active);
|
||||
ScheduledJobEntity addedScheduledJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added);
|
||||
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
@@ -445,8 +447,15 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(new[] { activeScheduledJob1, activeScheduledJob2, addedScheduledJob });
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity>
|
||||
{
|
||||
Data = [activeScheduledJob1, activeScheduledJob2, addedScheduledJob],
|
||||
CurrentPage = 1,
|
||||
PerPage = 3,
|
||||
Count = 3,
|
||||
NumberOfPages = 1
|
||||
}));
|
||||
|
||||
// Act
|
||||
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
@@ -472,7 +481,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(validationError, result.FirstError);
|
||||
await _mockUserRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -481,8 +490,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create();
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockHashService.HashString(command.Password!)
|
||||
.Returns("hashedPassword");
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
@@ -496,7 +505,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
Error expectedError = Error.Failure("ScheduledJobs.NotFound", "Failed to read the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
|
||||
+11
-9
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
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;
|
||||
@@ -10,7 +12,6 @@ using Lumina.Domain.Common.Primitives;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -35,6 +36,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
public CheckInitializationQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
|
||||
_mockUnitOfWork.UserRepository.Returns(_mockUserRepository);
|
||||
@@ -47,30 +49,30 @@ public class CheckInitializationQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
List<UserEntity> users = _userEntityFixture.CreateMany();
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(users.AsEnumerable()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = users, CurrentPage = 1, PerPage = users.Count, Count = users.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.HandleAsync(_checkInitializationQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsInitialized);
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenNoUsersExist_ShouldReturnNotInitialized()
|
||||
{
|
||||
// Arrange
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<UserEntity>()));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.HandleAsync(_checkInitializationQueryFixture.Create(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -78,7 +80,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
Error error = Error.Failure("Database.Error", "Failed to retrieve users");
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -86,6 +88,6 @@ public class CheckInitializationQueryHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
await _mockUserRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -54,6 +54,7 @@ public class AddLibraryCommandHandlerTests
|
||||
public AddLibraryCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -84,7 +85,7 @@ public class AddLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
AddLibraryCommand command = _addLibraryCommandFixture.Create();
|
||||
LibraryEntity persistedLibrary = _libraryEntityFixture.Create(userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(persistedLibrary));
|
||||
|
||||
// Act
|
||||
@@ -123,7 +124,7 @@ public class AddLibraryCommandHandlerTests
|
||||
AddLibraryCommand command = _addLibraryCommandFixture.Create();
|
||||
command = command with { CoverImage = null };
|
||||
LibraryEntity persistedLibrary = _libraryEntityFixture.Create(userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(persistedLibrary));
|
||||
|
||||
// Act
|
||||
@@ -261,7 +262,7 @@ public class AddLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddLibraryCommand command = _addLibraryCommandFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ public class CancelLibrariesScanCommandHandlerTests
|
||||
public CancelLibrariesScanCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+9
-8
@@ -49,6 +49,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
public CancelLibraryScanCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -74,7 +75,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
// Arrange
|
||||
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
|
||||
LibraryScanEntity runningScan = _libraryScanEntityFixture.Create(id: command.ScanId, libraryId: command.LibraryId, userId: _userId);
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(runningScan));
|
||||
|
||||
// Act
|
||||
@@ -93,7 +94,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryScanEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -111,7 +112,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get library scan"));
|
||||
|
||||
// Act
|
||||
@@ -129,7 +130,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
// Arrange
|
||||
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
|
||||
LibraryScanEntity runningScan = _libraryScanEntityFixture.Create(id: command.ScanId, libraryId: command.LibraryId, userId: _userId);
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(runningScan));
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(false);
|
||||
@@ -157,7 +158,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockLibraryScanRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryScanRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -167,7 +168,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
// Arrange
|
||||
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
|
||||
LibraryScanEntity completedScan = _libraryScanEntityFixture.Create(id: command.ScanId, libraryId: command.LibraryId, userId: _userId, status: LibraryScanJobStatus.Completed);
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(completedScan));
|
||||
|
||||
// Act
|
||||
@@ -186,7 +187,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
// Arrange
|
||||
CancelLibraryScanCommand command = _cancelLibraryScanCommandFixture.Create();
|
||||
LibraryScanEntity runningScan = _libraryScanEntityFixture.Create(id: command.ScanId, libraryId: command.LibraryId, userId: _userId);
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(runningScan));
|
||||
_mockLibraryScanRepository.UpdateAsync(Arg.Any<LibraryScanEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to update library scan"));
|
||||
@@ -212,7 +213,7 @@ public class CancelLibraryScanCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.LibraryScanning.LibraryScanIdCannotBeEmpty, result.FirstError);
|
||||
await _mockLibraryScanRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryScanRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockLibraryScanRepository.DidNotReceive().UpdateAsync(Arg.Any<LibraryScanEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
+10
-9
@@ -50,6 +50,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
public DeleteLibraryCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -78,7 +79,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -99,7 +100,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockProviderConfigurationStore.RemoveProviderConfigurationsForLibraryAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to remove provider configurations"));
|
||||
@@ -118,7 +119,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -136,7 +137,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get library"));
|
||||
|
||||
// Act
|
||||
@@ -154,7 +155,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(false);
|
||||
@@ -182,7 +183,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -192,7 +193,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId, contentLocations: [""]);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -211,7 +212,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
DeleteLibraryCommand command = _deleteLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockLibraryRepository.DeleteByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to delete library"));
|
||||
@@ -237,7 +238,7 @@ public class DeleteLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Library.LibraryIdCannotBeEmpty, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ public class ScanLibrariesCommandHandlerTests
|
||||
public ScanLibrariesCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
|
||||
+13
-12
@@ -52,6 +52,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
public ScanLibraryCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
@@ -81,7 +82,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -100,7 +101,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -118,7 +119,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get library"));
|
||||
|
||||
// Act
|
||||
@@ -136,7 +137,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(false);
|
||||
@@ -164,7 +165,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -174,7 +175,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId, isEnabled: false);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -193,7 +194,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId, isLocked: true);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -212,7 +213,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId, contentLocations: [""]);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -231,7 +232,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockLibraryScanRepository.GetPastMonthScansByLibraryIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get past month scans"));
|
||||
@@ -251,7 +252,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
LibraryScanEntity runningScan = _libraryScanEntityFixture.Create(libraryId: command.Id, userId: _userId, status: LibraryScanJobStatus.Running);
|
||||
_mockLibraryScanRepository.GetPastMonthScansByLibraryIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
@@ -273,7 +274,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
ScanLibraryCommand command = _scanLibraryCommandFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: command.Id, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockLibraryScanRepository.InsertAsync(Arg.Any<LibraryScanEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to insert library scan"));
|
||||
@@ -299,7 +300,7 @@ public class ScanLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Library.LibraryIdCannotBeEmpty, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockLibraryScanRepository.DidNotReceive().InsertAsync(Arg.Any<LibraryScanEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
+22
-21
@@ -56,6 +56,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
public UpdateLibraryCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -89,7 +90,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
LibraryType commandLibraryType = Enum.Parse<LibraryType>(command.LibraryType);
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.LibraryType = commandLibraryType == LibraryType.Book ? LibraryType.EBook : LibraryType.Book;
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
|
||||
// Act
|
||||
@@ -112,7 +113,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.LibraryType = Enum.Parse<LibraryType>(command.LibraryType);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
|
||||
// Act
|
||||
@@ -131,7 +132,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
LibraryType commandLibraryType = Enum.Parse<LibraryType>(command.LibraryType);
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.LibraryType = commandLibraryType == LibraryType.Book ? LibraryType.EBook : LibraryType.Book;
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
_mockProviderConfigurationStore.ReconcileProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to reconcile provider configurations"));
|
||||
@@ -151,7 +152,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
command = command with { CoverImage = null };
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
|
||||
// Act
|
||||
@@ -171,7 +172,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
command = command with { CoverImage = "C:/Users/user/cover.jpg" };
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.CoverImage = null;
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
_mockEnvironmentContext.FileTypeService.GetImageTypeAsync(Arg.Any<FileSystemPathId>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(ImageType.None));
|
||||
@@ -182,7 +183,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Library.CoverFileMustBeAnImage, result.FirstError);
|
||||
await _mockLibraryRepository.Received(1).GetByIdAsync(command.Id, Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.Received(1).GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -194,7 +195,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
command = command with { CoverImage = "C:/Users/user/cover.jpg" };
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.CoverImage = null;
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
_mockEnvironmentContext.FileTypeService.GetImageTypeAsync(Arg.Any<FileSystemPathId>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to determine image type"));
|
||||
@@ -204,7 +205,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockLibraryRepository.Received(1).GetByIdAsync(command.Id, Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.Received(1).GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -216,7 +217,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
command = command with { CoverImage = " " };
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.CoverImage = null;
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
|
||||
// Act
|
||||
@@ -225,7 +226,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.FileSystemManagement.InvalidPath, result.FirstError);
|
||||
await _mockLibraryRepository.Received(1).GetByIdAsync(command.Id, Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.Received(1).GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -236,7 +237,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
existingLibrary.CoverImage = command.CoverImage;
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
|
||||
// Act
|
||||
@@ -246,7 +247,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockEnvironmentContext.FileTypeService.DidNotReceive()
|
||||
.GetImageTypeAsync(Arg.Any<FileSystemPathId>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.Received(2).GetByIdAsync(command.Id, Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.Received(2).GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -255,7 +256,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -273,7 +274,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get library"));
|
||||
|
||||
// Act
|
||||
@@ -291,7 +292,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
_mockAuthorizationService.HasPermissionAsync(_userId, Arg.Any<AuthorizationPermission>(), Arg.Any<CancellationToken>())
|
||||
.Returns(false);
|
||||
@@ -321,7 +322,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -331,7 +332,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
command = command with { ContentLocations = [""] };
|
||||
|
||||
@@ -351,7 +352,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(command.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary));
|
||||
_mockLibraryRepository.UpdateAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to update library"));
|
||||
@@ -370,7 +371,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary), Error.Failure(description: "Failed to retrieve updated library"));
|
||||
|
||||
// Act
|
||||
@@ -386,7 +387,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Arrange
|
||||
UpdateLibraryCommand command = _updateLibraryCommandFixture.Create();
|
||||
LibraryEntity existingLibrary = _libraryEntityFixture.Create(id: command.Id, userId: command.OwnerId);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(existingLibrary), Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -411,7 +412,7 @@ public class UpdateLibraryCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Library.LibraryIdCannotBeEmpty, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().UpdateAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,7 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
@@ -68,15 +68,15 @@ public class LibraryMediaItemDeletedDomainEventHandlerTests
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: libraryId.Value, title: "My Library");
|
||||
_mockBookRepository.GetByPathAsync(libraryId.Value, book.Path, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<BookEntity?>(book));
|
||||
_mockLibraryRepository.GetByIdAsync(libraryId.Value, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
_mockBookRepository.DeleteAsync(book.Id, Arg.Any<CancellationToken>())
|
||||
_mockBookRepository.DeleteByIdAsync(book.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Deleted));
|
||||
_mockBookArtworkService.DeleteBookArtwork(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
|
||||
.Returns(Result.Deleted);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
LibraryMediaItemDeletedDomainEvent domainEvent = _libraryMediaItemDeletedDomainEventFixture.Create(libraryId: libraryId, path: book.Path);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class LibraryMediaItemDeletedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
_mockBookArtworkService.Received(1).DeleteBookArtwork(libraryId.Value, book.Id, "My Library", "Frank Herbert", book.Title);
|
||||
await _mockBookRepository.Received(1).DeleteAsync(book.Id, Arg.Any<CancellationToken>());
|
||||
await _mockBookRepository.Received(1).DeleteByIdAsync(book.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class LibraryMediaItemDeletedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
_mockBookArtworkService.DidNotReceive().DeleteBookArtwork(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>());
|
||||
await _mockBookRepository.DidNotReceive().DeleteAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockBookRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -117,15 +117,15 @@ public class LibraryMediaItemDeletedDomainEventHandlerTests
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: libraryId.Value, title: "My Library");
|
||||
_mockBookRepository.GetByPathAsync(libraryId.Value, book.Path, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<BookEntity?>(book));
|
||||
_mockLibraryRepository.GetByIdAsync(libraryId.Value, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
_mockBookArtworkService.DeleteBookArtwork(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
|
||||
.Returns(Error.Failure("Artwork.DeleteFailed", "Failed to delete the stored artwork"));
|
||||
_mockBookRepository.DeleteAsync(book.Id, Arg.Any<CancellationToken>())
|
||||
_mockBookRepository.DeleteByIdAsync(book.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Deleted));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
LibraryMediaItemDeletedDomainEvent domainEvent = _libraryMediaItemDeletedDomainEventFixture.Create(libraryId: libraryId, path: book.Path);
|
||||
|
||||
@@ -134,7 +134,7 @@ public class LibraryMediaItemDeletedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
// a failing artwork deletion must not prevent the book from being removed, so the deletion is only logged
|
||||
await _mockBookRepository.Received(1).DeleteAsync(book.Id, Arg.Any<CancellationToken>());
|
||||
await _mockBookRepository.Received(1).DeleteByIdAsync(book.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class LibraryMediaItemDeletedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.Equal(error, exception.EventualConsistencyError);
|
||||
await _mockBookRepository.DidNotReceive().DeleteAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockBookRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -167,14 +167,14 @@ public class LibraryMediaItemDeletedDomainEventHandlerTests
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: libraryId.Value, title: "My Library");
|
||||
_mockBookRepository.GetByPathAsync(libraryId.Value, book.Path, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<BookEntity?>(book));
|
||||
_mockLibraryRepository.GetByIdAsync(libraryId.Value, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
_mockBookArtworkService.DeleteBookArtwork(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
|
||||
.Returns(Result.Deleted);
|
||||
Error error = Error.Failure("Database.Error", "Failed to delete the book");
|
||||
_mockBookRepository.DeleteAsync(book.Id, Arg.Any<CancellationToken>())
|
||||
_mockBookRepository.DeleteByIdAsync(book.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
LibraryMediaItemDeletedDomainEvent domainEvent = _libraryMediaItemDeletedDomainEventFixture.Create(libraryId: libraryId, path: book.Path);
|
||||
|
||||
+3
-2
@@ -55,6 +55,7 @@ public class LibrarySavedDomainEventHandlerTests
|
||||
public LibrarySavedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockEnvironmentContext = Substitute.For<IEnvironmentContext>();
|
||||
@@ -106,7 +107,7 @@ public class LibrarySavedDomainEventHandlerTests
|
||||
await _sut.HandleAsync(domainEvent, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(domainEvent.Library.CoverImage);
|
||||
Assert.True(domainEvent.Library.CoverImage.HasValue);
|
||||
await _mockLibraryRepository.Received(1).UpdateAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -177,7 +178,7 @@ public class LibrarySavedDomainEventHandlerTests
|
||||
await _sut.HandleAsync(domainEvent, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("/Media/Libraries/guid/cover.png", domainEvent.Library.CoverImage);
|
||||
Assert.Equal("/Media/Libraries/guid/cover.png", domainEvent.Library.CoverImage.Value);
|
||||
_mockFileProviderService.DidNotReceive().CopyFile(Arg.Any<FileSystemPathId>(), Arg.Any<FileSystemPathId>(), Arg.Any<bool>());
|
||||
await _mockLibraryRepository.Received(1).UpdateAsync(Arg.Any<LibraryEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
+6
-5
@@ -46,6 +46,7 @@ public class LibraryScanCancelledDomainEventHandlerTests
|
||||
public LibraryScanCancelledDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockLibraryScanStagingResultsRepository = Substitute.For<ILibraryScanStagingResultsRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
@@ -70,7 +71,7 @@ public class LibraryScanCancelledDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: domainEvent.ScanId.Value,
|
||||
libraryId: domainEvent.LibraryId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
|
||||
// Act
|
||||
@@ -89,7 +90,7 @@ public class LibraryScanCancelledDomainEventHandlerTests
|
||||
// Arrange
|
||||
LibraryScanCancelledDomainEvent domainEvent = _libraryScanCancelledDomainEventFixture.Create();
|
||||
Error error = Error.Failure(description: "Failed to get library scan");
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -106,7 +107,7 @@ public class LibraryScanCancelledDomainEventHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
LibraryScanCancelledDomainEvent domainEvent = _libraryScanCancelledDomainEventFixture.Create();
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryScanEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -126,7 +127,7 @@ public class LibraryScanCancelledDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: domainEvent.ScanId.Value,
|
||||
libraryId: domainEvent.LibraryId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
Error error = Error.Failure(description: "Failed to cancel scan");
|
||||
_mockMediaLibraryScanningService.CancelScan(Arg.Any<LibraryScan>()).Returns(error);
|
||||
@@ -149,7 +150,7 @@ public class LibraryScanCancelledDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: domainEvent.ScanId.Value,
|
||||
libraryId: domainEvent.LibraryId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
Error error = Error.Failure(description: "Failed to clear staging results");
|
||||
_mockLibraryScanStagingResultsRepository.ClearForScanAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
|
||||
+7
-6
@@ -47,6 +47,7 @@ public class LibraryScanFailedDomainEventHandlerTests
|
||||
public LibraryScanFailedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockLibraryScanStagingResultsRepository = Substitute.For<ILibraryScanStagingResultsRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
@@ -73,7 +74,7 @@ public class LibraryScanFailedDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: compositeId.ScanId.Value,
|
||||
userId: compositeId.UserId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
|
||||
// Act
|
||||
@@ -98,7 +99,7 @@ public class LibraryScanFailedDomainEventHandlerTests
|
||||
id: compositeId.ScanId.Value,
|
||||
userId: compositeId.UserId.Value,
|
||||
status: LibraryScanJobStatus.Failed);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
|
||||
// Act
|
||||
@@ -119,7 +120,7 @@ public class LibraryScanFailedDomainEventHandlerTests
|
||||
// Arrange
|
||||
LibraryScanFailedDomainEvent domainEvent = _libraryScanFailedDomainEventFixture.Create();
|
||||
Error error = Error.Failure(description: "Failed to get library scan");
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -136,7 +137,7 @@ public class LibraryScanFailedDomainEventHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
LibraryScanFailedDomainEvent domainEvent = _libraryScanFailedDomainEventFixture.Create();
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryScanEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -157,7 +158,7 @@ public class LibraryScanFailedDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: compositeId.ScanId.Value,
|
||||
userId: compositeId.UserId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
Error error = Error.Failure(description: "Failed to update library scan");
|
||||
_mockLibraryScanRepository.UpdateAsync(Arg.Any<LibraryScanEntity>(), Arg.Any<CancellationToken>())
|
||||
@@ -181,7 +182,7 @@ public class LibraryScanFailedDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: compositeId.ScanId.Value,
|
||||
userId: compositeId.UserId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
Error error = Error.Failure(description: "Failed to clear staging results");
|
||||
_mockLibraryScanStagingResultsRepository.ClearForScanAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
|
||||
+6
-5
@@ -46,6 +46,7 @@ public class LibraryScanFinishedDomainEventHandlerTests
|
||||
public LibraryScanFinishedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
_mockMediaLibrariesScanProgressTracker = Substitute.For<IMediaLibrariesScanProgressTracker>();
|
||||
@@ -68,7 +69,7 @@ public class LibraryScanFinishedDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: compositeId.ScanId.Value,
|
||||
userId: compositeId.UserId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
_mockMediaLibrariesScanProgressTracker.UpdateScanProgress(Arg.Any<LibraryId>(), compositeId).Returns(Result.Updated);
|
||||
|
||||
@@ -89,7 +90,7 @@ public class LibraryScanFinishedDomainEventHandlerTests
|
||||
// Arrange
|
||||
LibraryScanFinishedDomainEvent domainEvent = _libraryScanFinishedDomainEventFixture.Create();
|
||||
Error error = Error.Failure(description: "Failed to get library scan");
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -106,7 +107,7 @@ public class LibraryScanFinishedDomainEventHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
LibraryScanFinishedDomainEvent domainEvent = _libraryScanFinishedDomainEventFixture.Create();
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryScanEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -128,7 +129,7 @@ public class LibraryScanFinishedDomainEventHandlerTests
|
||||
id: compositeId.ScanId.Value,
|
||||
userId: compositeId.UserId.Value,
|
||||
status: LibraryScanJobStatus.Pending);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
|
||||
// Act
|
||||
@@ -150,7 +151,7 @@ public class LibraryScanFinishedDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: compositeId.ScanId.Value,
|
||||
userId: compositeId.UserId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
Error error = Error.Failure(description: "Failed to update library scan");
|
||||
_mockLibraryScanRepository.UpdateAsync(Arg.Any<LibraryScanEntity>(), Arg.Any<CancellationToken>())
|
||||
|
||||
+5
-4
@@ -43,6 +43,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
public LibraryScanQueuedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
_mockMediaLibraryScanningService = Substitute.For<IMediaLibraryScanningService>();
|
||||
@@ -63,7 +64,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: domainEvent.ScanId.Value,
|
||||
libraryId: domainEvent.LibraryId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryScanEntity?>(scan));
|
||||
|
||||
// Act
|
||||
@@ -82,7 +83,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
// Arrange
|
||||
LibraryScanQueuedDomainEvent domainEvent = _libraryScanQueuedDomainEventFixture.Create();
|
||||
Error error = Error.Failure(description: "Failed to get library scan");
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -99,7 +100,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
LibraryScanQueuedDomainEvent domainEvent = _libraryScanQueuedDomainEventFixture.Create();
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryScanEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -119,7 +120,7 @@ public class LibraryScanQueuedDomainEventHandlerTests
|
||||
LibraryScanEntity scan = _libraryScanEntityFixture.Create(
|
||||
id: domainEvent.ScanId.Value,
|
||||
libraryId: domainEvent.LibraryId.Value);
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, Arg.Any<CancellationToken>())
|
||||
_mockLibraryScanRepository.GetByIdAsync(scan.Id, cancellationToken: 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<CancellationToken>())
|
||||
|
||||
+1
@@ -34,6 +34,7 @@ public class LibraryScanStartedDomainEventHandlerTests
|
||||
public LibraryScanStartedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
_mockLibraryScanRepository.UpdateAsync(Arg.Any<LibraryScanEntity>(), Arg.Any<CancellationToken>())
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ public class GetEnabledLibrariesQueryHandlerTests
|
||||
public GetEnabledLibrariesQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+7
-4
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -41,6 +43,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
public GetLibrariesQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -63,7 +66,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
_libraryEntityFixture.Create(userId: _userId),
|
||||
_libraryEntityFixture.Create(userId: Guid.NewGuid())
|
||||
];
|
||||
_mockLibraryRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryEntity>>(libraries));
|
||||
_mockLibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<LibraryEntity> { Data = libraries, CurrentPage = 1, PerPage = libraries.Count, Count = libraries.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<LibraryResponse[]> result = await _sut.HandleAsync(_getLibrariesQueryFixture.Create(), CancellationToken.None);
|
||||
@@ -85,7 +88,7 @@ public class GetLibrariesQueryHandlerTests
|
||||
_libraryEntityFixture.Create(userId: _userId),
|
||||
_libraryEntityFixture.Create(userId: otherUserId)
|
||||
];
|
||||
_mockLibraryRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<LibraryEntity>>(libraries));
|
||||
_mockLibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<LibraryEntity> { Data = libraries, CurrentPage = 1, PerPage = libraries.Count, Count = libraries.Count, NumberOfPages = 1 }));
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>()).Returns(false);
|
||||
|
||||
// Act
|
||||
@@ -109,14 +112,14 @@ public class GetLibrariesQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenGetAllFails_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
_mockLibraryRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get libraries"));
|
||||
|
||||
// Act
|
||||
|
||||
+6
-5
@@ -47,6 +47,7 @@ public class GetLibraryQueryHandlerTests
|
||||
{
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
@@ -57,7 +58,7 @@ public class GetLibraryQueryHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From((LibraryEntity?)_libraryEntityFixture.Create(userId: _userId, title: "Test Library", libraryType: LibraryType.EBook, contentLocations: [])));
|
||||
_mockValidator.Validate(Arg.Any<GetLibraryQuery>()).Returns([]);
|
||||
|
||||
@@ -110,7 +111,7 @@ public class GetLibraryQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync<ILibraryOwnershipPolicy>(Arg.Any<Guid>(), Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -118,7 +119,7 @@ public class GetLibraryQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryQuery query = _getLibraryQueryFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -134,7 +135,7 @@ public class GetLibraryQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryQuery query = _getLibraryQueryFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Errors.Library.LibraryNotFound);
|
||||
|
||||
// Act
|
||||
@@ -159,6 +160,6 @@ public class GetLibraryQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Library.LibraryIdCannotBeEmpty, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync<ILibraryOwnershipPolicy>(Arg.Any<Guid>(), Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -53,6 +53,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
public GetLibraryScanProgressQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -82,7 +83,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
// Arrange
|
||||
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: query.LibraryId, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -100,7 +101,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -117,7 +118,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get library"));
|
||||
|
||||
// Act
|
||||
@@ -134,7 +135,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
// Arrange
|
||||
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: query.LibraryId, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockAuthorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(false);
|
||||
@@ -161,7 +162,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -170,7 +171,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
// Arrange
|
||||
GetLibraryScanProgressQuery query = _getLibraryScanProgressQueryFixture.Create();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(id: query.LibraryId, userId: _userId);
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(query.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
_mockMediaLibrariesScanProgressTracker.GetScanProgress(Arg.Any<MediaLibraryScanCompositeId>())
|
||||
.Returns(Error.Failure(description: "Failed to get scan progress"));
|
||||
@@ -195,7 +196,7 @@ public class GetLibraryScanProgressQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Library.LibraryIdCannotBeEmpty, result.FirstError);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
_mockMediaLibrariesScanProgressTracker.DidNotReceive().GetScanProgress(Arg.Any<MediaLibraryScanCompositeId>());
|
||||
}
|
||||
}
|
||||
+1
@@ -50,6 +50,7 @@ public class GetRunningLibraryScansQueryHandlerTests
|
||||
public GetRunningLibraryScansQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLibraryScanRepository = Substitute.For<ILibraryScanRepository>();
|
||||
_mockUnitOfWork.LibraryScanRepository.Returns(_mockLibraryScanRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ public class ReorderLibraryArtworkProvidersCommandHandlerTests
|
||||
public ReorderLibraryArtworkProvidersCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockConfigurationRepository = Substitute.For<IArtworkProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.ArtworkProviderConfigurationRepository.Returns(_mockConfigurationRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ public class ReorderLibraryMetadataProvidersCommandHandlerTests
|
||||
public ReorderLibraryMetadataProvidersCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.LibraryMetadataProviderConfigurationRepository.Returns(_mockConfigurationRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ public class SetLibraryArtworkProviderEnabledCommandHandlerTests
|
||||
public SetLibraryArtworkProviderEnabledCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockConfigurationRepository = Substitute.For<IArtworkProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.ArtworkProviderConfigurationRepository.Returns(_mockConfigurationRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ public class SetLibraryMetadataProviderEnabledCommandHandlerTests
|
||||
public SetLibraryMetadataProviderEnabledCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.LibraryMetadataProviderConfigurationRepository.Returns(_mockConfigurationRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+1
@@ -34,6 +34,7 @@ public class UpdatePluginSettingsCommandHandlerTests
|
||||
public UpdatePluginSettingsCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
|
||||
_mockValidator = Substitute.For<IValidator<UpdatePluginSettingsCommand>>();
|
||||
|
||||
+12
-8
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
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;
|
||||
@@ -47,6 +49,7 @@ public class GetLibraryArtworkProvidersQueryHandlerTests
|
||||
public GetLibraryArtworkProvidersQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockArtworkProviderConfigurationRepository = Substitute.For<IArtworkProviderConfigurationRepository>();
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.ArtworkProviderConfigurationRepository.Returns(_mockArtworkProviderConfigurationRepository);
|
||||
@@ -100,7 +103,8 @@ public class GetLibraryArtworkProvidersQueryHandlerTests
|
||||
_pluginEntityFixture.Create(firstPluginId),
|
||||
_pluginEntityFixture.Create(secondPluginId)
|
||||
];
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = plugins, CurrentPage = 1, PerPage = plugins.Count, Count = plugins.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<LibraryArtworkProviderResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -127,8 +131,8 @@ public class GetLibraryArtworkProvidersQueryHandlerTests
|
||||
];
|
||||
_mockArtworkProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>(configurations));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<PluginEntity>>([_pluginEntityFixture.Create()]));
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [_pluginEntityFixture.Create()], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<LibraryArtworkProviderResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -147,8 +151,8 @@ public class GetLibraryArtworkProvidersQueryHandlerTests
|
||||
GetLibraryArtworkProvidersQuery query = _getLibraryArtworkProvidersQueryFixture.Create();
|
||||
_mockArtworkProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<PluginEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<LibraryArtworkProviderResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -172,7 +176,7 @@ public class GetLibraryArtworkProvidersQueryHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -182,7 +186,7 @@ public class GetLibraryArtworkProvidersQueryHandlerTests
|
||||
GetLibraryArtworkProvidersQuery query = _getLibraryArtworkProvidersQueryFixture.Create();
|
||||
_mockArtworkProviderConfigurationRepository.GetByLibraryIdAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get plugins"));
|
||||
|
||||
// Act
|
||||
@@ -209,7 +213,7 @@ public class GetLibraryArtworkProvidersQueryHandlerTests
|
||||
await _mockAuthorizationService.Received(1).EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
_userId, Arg.Is<LibraryOwnershipPolicyContext>(context => context.LibraryId == query.LibraryId), Arg.Any<CancellationToken>());
|
||||
await _mockArtworkProviderConfigurationRepository.DidNotReceive().GetByLibraryIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+12
-8
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
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;
|
||||
@@ -48,6 +50,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
public GetLibraryMetadataProvidersQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -100,7 +103,8 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
_pluginEntityFixture.Create(firstPluginId),
|
||||
_pluginEntityFixture.Create(secondPluginId)
|
||||
];
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = plugins, CurrentPage = 1, PerPage = plugins.Count, Count = plugins.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<LibraryMetadataProviderResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -127,8 +131,8 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
];
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>(configurations));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<PluginEntity>>([_pluginEntityFixture.Create()]));
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [_pluginEntityFixture.Create()], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<LibraryMetadataProviderResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -147,8 +151,8 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
GetLibraryMetadataProvidersQuery query = _getLibraryMetadataProvidersQueryFixture.Create();
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<PluginEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<LibraryMetadataProviderResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -172,7 +176,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -182,7 +186,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
GetLibraryMetadataProvidersQuery query = _getLibraryMetadataProvidersQueryFixture.Create();
|
||||
_mockProviderConfigurationStore.GetConfigurationsAsync(query.LibraryId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get plugins"));
|
||||
|
||||
// Act
|
||||
@@ -209,7 +213,7 @@ public class GetLibraryMetadataProvidersQueryHandlerTests
|
||||
await _mockAuthorizationService.Received(1).EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
_userId, Arg.Is<LibraryOwnershipPolicyContext>(context => context.LibraryId == query.LibraryId), Arg.Any<CancellationToken>());
|
||||
await _mockProviderConfigurationStore.DidNotReceive().GetConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+6
-5
@@ -45,6 +45,7 @@ public class GetPluginSettingsQueryHandlerTests
|
||||
public GetPluginSettingsQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
|
||||
_mockPluginManager = Substitute.For<IPluginManager>();
|
||||
@@ -67,7 +68,7 @@ public class GetPluginSettingsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Plugins.PluginIdCannotBeEmpty, result.FirstError);
|
||||
await _mockPluginRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockPluginRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -76,7 +77,7 @@ public class GetPluginSettingsQueryHandlerTests
|
||||
// Arrange
|
||||
GetPluginSettingsQuery query = _getPluginSettingsQueryFixture.Create();
|
||||
PluginEntity plugin = _pluginEntityFixture.Create(query.PluginId);
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(plugin));
|
||||
|
||||
IPlugin loadedPlugin = Substitute.For<IPlugin>();
|
||||
@@ -107,7 +108,7 @@ public class GetPluginSettingsQueryHandlerTests
|
||||
// Arrange
|
||||
GetPluginSettingsQuery query = _getPluginSettingsQueryFixture.Create();
|
||||
PluginEntity plugin = _pluginEntityFixture.Create(query.PluginId);
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(plugin));
|
||||
_mockPluginManager.GetPlugin(query.PluginId).Returns((IPlugin?)null);
|
||||
|
||||
@@ -125,7 +126,7 @@ public class GetPluginSettingsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetPluginSettingsQuery query = _getPluginSettingsQueryFixture.Create();
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<PluginEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -143,7 +144,7 @@ public class GetPluginSettingsQueryHandlerTests
|
||||
// Arrange
|
||||
GetPluginSettingsQuery query = _getPluginSettingsQueryFixture.Create();
|
||||
Error error = Error.Failure(description: "Failed to get plugin");
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(query.PluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
|
||||
+6
-2
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Fixtures.Core.Plugins.Queries.GetPlugins;
|
||||
@@ -34,6 +36,7 @@ public class GetPluginsQueryHandlerTests
|
||||
public GetPluginsQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
|
||||
_sut = new GetPluginsQueryHandler(_mockUnitOfWork);
|
||||
@@ -44,7 +47,8 @@ public class GetPluginsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
List<PluginEntity> plugins = [_pluginEntityFixture.Create(), _pluginEntityFixture.Create()];
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = plugins, CurrentPage = 1, PerPage = plugins.Count, Count = plugins.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(_getPluginsQueryFixture.Create(), CancellationToken.None);
|
||||
@@ -60,7 +64,7 @@ public class GetPluginsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenRepositoryReturnsError_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure(description: "Failed to get plugins"));
|
||||
|
||||
// Act
|
||||
|
||||
+1
@@ -49,6 +49,7 @@ public class AddScheduledJobCommandHandlerTests
|
||||
public AddScheduledJobCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
|
||||
+9
-8
@@ -48,6 +48,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
public FireScheduledJobCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
@@ -72,7 +73,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
|
||||
// Act
|
||||
@@ -98,7 +99,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Scheduling.ScheduledJobNotFound, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
_mockDomainEventsQueue.DidNotReceive().Enqueue(Arg.Any<IDomainEvent>());
|
||||
}
|
||||
|
||||
@@ -115,7 +116,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -131,7 +132,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -140,7 +141,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
// Arrange
|
||||
FireScheduledJobCommand command = _fireScheduledJobCommandFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled job");
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
Result<ScheduledJobResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
@@ -156,7 +157,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
FireScheduledJobCommand command = _fireScheduledJobCommandFixture.Create();
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -179,7 +180,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
scheduleType: ScheduleType.DailyAtHourAndMinute,
|
||||
hour: 99,
|
||||
minute: 0);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
|
||||
// Act
|
||||
@@ -199,7 +200,7 @@ public class FireScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Running);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
|
||||
// Act
|
||||
|
||||
+10
-9
@@ -51,6 +51,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
public RemoveScheduledJobCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
@@ -78,7 +79,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobExecutionRepository.DeleteByScheduledJobIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
@@ -113,7 +114,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Scheduling.ScheduledJobNotFound, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -130,7 +131,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -146,7 +147,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -154,7 +155,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
RemoveScheduledJobCommand command = _removeScheduledJobCommandFixture.Create();
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -175,7 +176,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
Error error = Error.Failure("Database.Error", "Failed to delete the executions");
|
||||
_mockScheduledJobExecutionRepository.DeleteByScheduledJobIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
@@ -200,7 +201,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobExecutionRepository.DeleteByScheduledJobIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
@@ -223,7 +224,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
// Arrange
|
||||
RemoveScheduledJobCommand command = _removeScheduledJobCommandFixture.Create();
|
||||
Error repositoryError = DomainErrors.Scheduling.ScheduledJobNotFound;
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(repositoryError);
|
||||
|
||||
// Act
|
||||
@@ -247,7 +248,7 @@ public class RemoveScheduledJobCommandHandlerTests
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
intervalMinutes: 0,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(invalidScheduledJob));
|
||||
|
||||
// Act
|
||||
|
||||
+10
-9
@@ -48,6 +48,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
public StartScheduledJobCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
@@ -72,7 +73,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Added);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
|
||||
@@ -102,7 +103,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Scheduling.ScheduledJobNotFound, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -119,7 +120,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -135,7 +136,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -143,7 +144,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
StartScheduledJobCommand command = _startScheduledJobCommandFixture.Create();
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -164,7 +165,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
|
||||
// Act
|
||||
@@ -186,7 +187,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Added);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(DomainErrors.Scheduling.ScheduledJobNotFound);
|
||||
@@ -207,7 +208,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
// Arrange
|
||||
StartScheduledJobCommand command = _startScheduledJobCommandFixture.Create();
|
||||
Error repositoryError = DomainErrors.Scheduling.ScheduledJobNotFound;
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(repositoryError);
|
||||
|
||||
// Act
|
||||
@@ -230,7 +231,7 @@ public class StartScheduledJobCommandHandlerTests
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
intervalMinutes: 0,
|
||||
status: ScheduledJobStatus.Added);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(invalidScheduledJob));
|
||||
|
||||
// Act
|
||||
|
||||
+11
-10
@@ -50,6 +50,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
public StopScheduledJobCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
@@ -75,7 +76,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
|
||||
@@ -105,7 +106,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Running,
|
||||
lastStartedOnUtc: DateTime.UtcNow.AddMinutes(-10));
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
|
||||
@@ -132,7 +133,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Scheduling.ScheduledJobNotFound, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobScheduler.DidNotReceive().StopCycleAsync(Arg.Any<Lumina.Domain.Core.BoundedContexts.SchedulingBoundedContext.ScheduledJobAggregate.ValueObjects.ScheduledJobId>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -149,7 +150,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -165,7 +166,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -173,7 +174,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
StopScheduledJobCommand command = _stopScheduledJobCommandFixture.Create();
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -194,7 +195,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Added);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
|
||||
// Act
|
||||
@@ -216,7 +217,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
id: command.ScheduledJobId,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(DomainErrors.Scheduling.ScheduledJobNotFound);
|
||||
@@ -237,7 +238,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
// Arrange
|
||||
StopScheduledJobCommand command = _stopScheduledJobCommandFixture.Create();
|
||||
Error repositoryError = DomainErrors.Scheduling.ScheduledJobNotFound;
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(repositoryError);
|
||||
|
||||
// Act
|
||||
@@ -260,7 +261,7 @@ public class StopScheduledJobCommandHandlerTests
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
intervalMinutes: 0,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(command.ScheduledJobId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(invalidScheduledJob));
|
||||
|
||||
// Act
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ public class UpdateSchedulerDisplayPreferencesCommandHandlerTests
|
||||
public UpdateSchedulerDisplayPreferencesCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockSchedulerDisplayPreferencesRepository = Substitute.For<ISchedulerDisplayPreferencesRepository>();
|
||||
|
||||
+6
-3
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Scheduling.Events;
|
||||
using Lumina.Application.Core.Scheduling.Notifications;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
|
||||
@@ -40,11 +42,12 @@ public class ScheduledJobAddedDomainEventHandlerTests
|
||||
public ScheduledJobAddedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobNotifier = Substitute.For<IScheduledJobNotifier>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
|
||||
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new ScheduledJobAddedDomainEventHandler(_mockScheduledJobNotifier, _mockUnitOfWork);
|
||||
}
|
||||
@@ -56,7 +59,7 @@ public class ScheduledJobAddedDomainEventHandlerTests
|
||||
ScheduledJobAddedDomainEvent domainEvent = _scheduledJobAddedDomainEventFixture.Create();
|
||||
ScheduledJobEntity scheduledJob1 = _scheduledJobEntityFixture.Create(name: "Job 1");
|
||||
ScheduledJobEntity scheduledJob2 = _scheduledJobEntityFixture.Create(name: "Job 2");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([scheduledJob1, scheduledJob2]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [scheduledJob1, scheduledJob2], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
await _sut.HandleAsync(domainEvent, CancellationToken.None);
|
||||
@@ -73,7 +76,7 @@ public class ScheduledJobAddedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobAddedDomainEvent domainEvent = _scheduledJobAddedDomainEventFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
|
||||
+5
-2
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Scheduling;
|
||||
using Lumina.Application.Core.Scheduling.Events;
|
||||
using Lumina.Application.Core.Scheduling.Notifications;
|
||||
@@ -39,12 +41,13 @@ public class ScheduledJobCycleStartedDomainEventHandlerTests
|
||||
public ScheduledJobCycleStartedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobNotifier = Substitute.For<IScheduledJobNotifier>();
|
||||
_mockScheduledJobScheduler = Substitute.For<IScheduledJobScheduler>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
|
||||
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new ScheduledJobCycleStartedDomainEventHandler(_mockScheduledJobNotifier, _mockScheduledJobScheduler, _mockUnitOfWork);
|
||||
}
|
||||
@@ -69,7 +72,7 @@ public class ScheduledJobCycleStartedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobCycleStartedDomainEvent domainEvent = _scheduledJobCycleStartedDomainEventFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
|
||||
+6
-3
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Scheduling.Events;
|
||||
using Lumina.Application.Core.Scheduling.Notifications;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
|
||||
@@ -39,11 +41,12 @@ public class ScheduledJobCycleStoppedDomainEventHandlerTests
|
||||
public ScheduledJobCycleStoppedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobNotifier = Substitute.For<IScheduledJobNotifier>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
|
||||
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new ScheduledJobCycleStoppedDomainEventHandler(_mockScheduledJobNotifier, _mockUnitOfWork);
|
||||
}
|
||||
@@ -54,7 +57,7 @@ public class ScheduledJobCycleStoppedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobCycleStoppedDomainEvent domainEvent = _scheduledJobCycleStoppedDomainEventFixture.Create();
|
||||
ScheduledJobEntity stoppedJob = _scheduledJobEntityFixture.Create(name: "Stopped job", status: Lumina.Domain.SharedKernel.Common.Enums.Scheduling.ScheduledJobStatus.Added);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([stoppedJob]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [stoppedJob], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
await _sut.HandleAsync(domainEvent, CancellationToken.None);
|
||||
@@ -71,7 +74,7 @@ public class ScheduledJobCycleStoppedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobCycleStoppedDomainEvent domainEvent = _scheduledJobCycleStoppedDomainEventFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
|
||||
+17
-14
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Scheduling.Events;
|
||||
using Lumina.Application.Core.Scheduling.Notifications;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
|
||||
@@ -43,6 +45,7 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
public ScheduledJobExecutionCompletedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobNotifier = Substitute.For<IScheduledJobNotifier>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
|
||||
@@ -51,7 +54,7 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
_mockUnitOfWork.ScheduledJobExecutionRepository.Returns(_mockScheduledJobExecutionRepository);
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockScheduledJobExecutionRepository.UpdateAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new ScheduledJobExecutionCompletedDomainEventHandler(_mockScheduledJobNotifier, _mockUnitOfWork);
|
||||
}
|
||||
@@ -68,14 +71,14 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
id: domainEvent.ScheduledJobId.Value,
|
||||
status: ScheduledJobStatus.Running,
|
||||
lastStartedOnUtc: completedOnUtc.AddMinutes(-5));
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
ScheduledJobExecutionEntity execution = _scheduledJobExecutionEntityFixture.Create(
|
||||
id: domainEvent.RunId,
|
||||
scheduledJobId: scheduledJob.Id,
|
||||
isCycleRun: isCycleRun,
|
||||
completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobExecutionEntity?>(execution));
|
||||
|
||||
// Act
|
||||
@@ -100,7 +103,7 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
ScheduledJobExecutionCompletedDomainEvent domainEvent = _scheduledJobExecutionCompletedDomainEventFixture.Create(isCycleRun: true);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -109,7 +112,7 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.Equal(Errors.Scheduling.ScheduledJobNotFound, exception.EventualConsistencyError);
|
||||
await _mockScheduledJobExecutionRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobExecutionRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -118,7 +121,7 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobExecutionCompletedDomainEvent domainEvent = _scheduledJobExecutionCompletedDomainEventFixture.Create(isCycleRun: true);
|
||||
ScheduledJobEntity scheduledJob = _scheduledJobEntityFixture.Create(id: domainEvent.ScheduledJobId.Value, status: ScheduledJobStatus.Running);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
Error error = Error.Failure("Database.Error", "Failed to update the scheduled job");
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(error);
|
||||
@@ -129,7 +132,7 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
|
||||
// Assert
|
||||
Assert.Equal(error, exception.EventualConsistencyError);
|
||||
await _mockScheduledJobExecutionRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobExecutionRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -138,9 +141,9 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobExecutionCompletedDomainEvent domainEvent = _scheduledJobExecutionCompletedDomainEventFixture.Create(isCycleRun: true);
|
||||
ScheduledJobEntity scheduledJob = _scheduledJobEntityFixture.Create(id: domainEvent.ScheduledJobId.Value, status: ScheduledJobStatus.Running);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobExecutionEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -158,10 +161,10 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobExecutionCompletedDomainEvent domainEvent = _scheduledJobExecutionCompletedDomainEventFixture.Create(isCycleRun: true);
|
||||
ScheduledJobEntity scheduledJob = _scheduledJobEntityFixture.Create(id: domainEvent.ScheduledJobId.Value, status: ScheduledJobStatus.Running);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
ScheduledJobExecutionEntity execution = _scheduledJobExecutionEntityFixture.Create(id: domainEvent.RunId);
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobExecutionEntity?>(execution));
|
||||
Error error = Error.Failure("Database.Error", "Failed to update the execution");
|
||||
_mockScheduledJobExecutionRepository.UpdateAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>()).Returns(error);
|
||||
@@ -181,13 +184,13 @@ public class ScheduledJobExecutionCompletedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobExecutionCompletedDomainEvent domainEvent = _scheduledJobExecutionCompletedDomainEventFixture.Create(isCycleRun: true);
|
||||
ScheduledJobEntity scheduledJob = _scheduledJobEntityFixture.Create(id: domainEvent.ScheduledJobId.Value, status: ScheduledJobStatus.Running);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
ScheduledJobExecutionEntity execution = _scheduledJobExecutionEntityFixture.Create(id: domainEvent.RunId);
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobExecutionRepository.GetByIdAsync(domainEvent.RunId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobExecutionEntity?>(execution));
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
|
||||
+11
-8
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Scheduling.Events;
|
||||
using Lumina.Application.Core.Scheduling.Notifications;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
|
||||
@@ -44,6 +46,7 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
public ScheduledJobExecutionStartedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobNotifier = Substitute.For<IScheduledJobNotifier>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
|
||||
@@ -52,7 +55,7 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
_mockUnitOfWork.ScheduledJobExecutionRepository.Returns(_mockScheduledJobExecutionRepository);
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockScheduledJobExecutionRepository.InsertAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new ScheduledJobExecutionStartedDomainEventHandler(_mockScheduledJobNotifier, _mockUnitOfWork);
|
||||
}
|
||||
@@ -68,7 +71,7 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
taskType: domainEvent.TaskType,
|
||||
scheduleType: ScheduleType.WithIntervalInMinutes,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
|
||||
// Act
|
||||
@@ -100,7 +103,7 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobExecutionStartedDomainEvent domainEvent = _scheduledJobExecutionStartedDomainEventFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled job");
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
@@ -116,7 +119,7 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
ScheduledJobExecutionStartedDomainEvent domainEvent = _scheduledJobExecutionStartedDomainEventFixture.Create();
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -135,7 +138,7 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
ScheduledJobEntity scheduledJob = _scheduledJobEntityFixture.Create(
|
||||
id: domainEvent.ScheduledJobId.Value,
|
||||
status: ScheduledJobStatus.Active);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
Error error = Error.Failure("Database.Error", "Failed to update the scheduled job");
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(error);
|
||||
@@ -155,7 +158,7 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobExecutionStartedDomainEvent domainEvent = _scheduledJobExecutionStartedDomainEventFixture.Create();
|
||||
ScheduledJobEntity scheduledJob = _scheduledJobEntityFixture.Create(id: domainEvent.ScheduledJobId.Value);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
Error error = Error.Failure("Database.Error", "Failed to insert the execution");
|
||||
_mockScheduledJobExecutionRepository.InsertAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>()).Returns(error);
|
||||
@@ -175,10 +178,10 @@ public class ScheduledJobExecutionStartedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobExecutionStartedDomainEvent domainEvent = _scheduledJobExecutionStartedDomainEventFixture.Create();
|
||||
ScheduledJobEntity scheduledJob = _scheduledJobEntityFixture.Create(id: domainEvent.ScheduledJobId.Value);
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(domainEvent.ScheduledJobId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobEntity?>(scheduledJob));
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
|
||||
+5
-2
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Scheduling.Events;
|
||||
using Lumina.Application.Core.Scheduling.Notifications;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
|
||||
@@ -40,6 +42,7 @@ public class ScheduledJobExecutionStoppedDomainEventHandlerTests
|
||||
public ScheduledJobExecutionStoppedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobNotifier = Substitute.For<IScheduledJobNotifier>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
|
||||
@@ -47,7 +50,7 @@ public class ScheduledJobExecutionStoppedDomainEventHandlerTests
|
||||
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
|
||||
_mockUnitOfWork.ScheduledJobExecutionRepository.Returns(_mockScheduledJobExecutionRepository);
|
||||
_mockScheduledJobExecutionRepository.UpdateAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new ScheduledJobExecutionStoppedDomainEventHandler(_mockScheduledJobNotifier, _mockUnitOfWork);
|
||||
}
|
||||
@@ -140,7 +143,7 @@ public class ScheduledJobExecutionStoppedDomainEventHandlerTests
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(domainEvent.ScheduledJobId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobExecutionEntity?>(null));
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
|
||||
+6
-3
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Scheduling.Events;
|
||||
using Lumina.Application.Core.Scheduling.Notifications;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
|
||||
@@ -39,11 +41,12 @@ public class ScheduledJobRemovedDomainEventHandlerTests
|
||||
public ScheduledJobRemovedDomainEventHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobNotifier = Substitute.For<IScheduledJobNotifier>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
|
||||
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
_sut = new ScheduledJobRemovedDomainEventHandler(_mockScheduledJobNotifier, _mockUnitOfWork);
|
||||
}
|
||||
@@ -54,7 +57,7 @@ public class ScheduledJobRemovedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobRemovedDomainEvent domainEvent = _scheduledJobRemovedDomainEventFixture.Create();
|
||||
ScheduledJobEntity remainingJob = _scheduledJobEntityFixture.Create(name: "Remaining job");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From<IEnumerable<ScheduledJobEntity>>([remainingJob]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [remainingJob], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
await _sut.HandleAsync(domainEvent, CancellationToken.None);
|
||||
@@ -71,7 +74,7 @@ public class ScheduledJobRemovedDomainEventHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobRemovedDomainEvent domainEvent = _scheduledJobRemovedDomainEventFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
EventualConsistencyException exception = await Assert.ThrowsAsync<EventualConsistencyException>(
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ public class GetScheduledJobHistoryQueryHandlerTests
|
||||
public GetScheduledJobHistoryQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
|
||||
|
||||
+10
-7
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
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.Core.Scheduling.Queries.GetScheduledJobs;
|
||||
@@ -40,6 +42,7 @@ public class GetScheduledJobsQueryHandlerTests
|
||||
public GetScheduledJobsQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
@@ -57,8 +60,8 @@ public class GetScheduledJobsQueryHandlerTests
|
||||
// Arrange
|
||||
ScheduledJobEntity scheduledJob1 = _scheduledJobEntityFixture.Create(name: "Job 1");
|
||||
ScheduledJobEntity scheduledJob2 = _scheduledJobEntityFixture.Create(name: "Job 2");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ScheduledJobEntity>>([scheduledJob1, scheduledJob2]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [scheduledJob1, scheduledJob2], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<ScheduledJobResponse>> result = await _sut.HandleAsync(new GetScheduledJobsQuery(), CancellationToken.None);
|
||||
@@ -74,8 +77,8 @@ public class GetScheduledJobsQueryHandlerTests
|
||||
public async Task HandleAsync_WhenNoScheduledJobsExist_ShouldReturnEmptyCollection()
|
||||
{
|
||||
// Arrange
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ScheduledJobEntity>>([]));
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ScheduledJobEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<ScheduledJobResponse>> result = await _sut.HandleAsync(new GetScheduledJobsQuery(), CancellationToken.None);
|
||||
@@ -97,7 +100,7 @@ public class GetScheduledJobsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -112,7 +115,7 @@ public class GetScheduledJobsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockScheduledJobRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -120,7 +123,7 @@ public class GetScheduledJobsQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
Error error = Error.Failure("Database.Error", "Failed to get the scheduled jobs");
|
||||
_mockScheduledJobRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<ScheduledJobResponse>> result = await _sut.HandleAsync(new GetScheduledJobsQuery(), CancellationToken.None);
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ public class GetSchedulerDisplayPreferencesQueryHandlerTests
|
||||
public GetSchedulerDisplayPreferencesQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockSchedulerDisplayPreferencesRepository = Substitute.For<ISchedulerDisplayPreferencesRepository>();
|
||||
|
||||
+20
-17
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
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.Themes;
|
||||
@@ -47,6 +49,7 @@ public class DeleteThemeCommandHandlerTests
|
||||
public DeleteThemeCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeService = Substitute.For<IThemeService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
@@ -185,7 +188,7 @@ public class DeleteThemeCommandHandlerTests
|
||||
Error error = Error.Failure("Database.Error", "Failed to get all themes");
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -206,8 +209,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
ThemeEntity userTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false);
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, userTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, userTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
@@ -228,8 +231,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
ThemeEntity theme = _themeEntityFixture.Create(themeId: command.ThemeId, installSource: ThemeInstallSource.Uploaded, isCurrent: true, includeIsCurrent: true, isDeleted: false);
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
@@ -251,8 +254,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
ThemeEntity otherBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, otherBundledTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, otherBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
|
||||
@@ -278,8 +281,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
ThemeEntity bundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, bundledTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, bundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeRepository.DeleteByIdAsync(theme.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
|
||||
@@ -304,8 +307,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
Error error = Error.Failure("Database.Error", "Failed to delete theme");
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, bundledTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, bundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeRepository.DeleteByIdAsync(theme.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
@@ -329,8 +332,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
_mockThemeService.DefaultThemeId.Returns(replacementTheme.ThemeId);
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, replacementTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, replacementTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
|
||||
@@ -360,8 +363,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
_mockThemeService.DefaultThemeId.Returns("no-such-default");
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, betaTheme, alphaTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, betaTheme, alphaTheme], CurrentPage = 1, PerPage = 3, Count = 3, NumberOfPages = 1 }));
|
||||
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Updated);
|
||||
|
||||
@@ -388,8 +391,8 @@ public class DeleteThemeCommandHandlerTests
|
||||
Error error = Error.Failure("Theme.DeleteFailed", "Failed to delete theme files");
|
||||
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ThemeEntity?>(theme));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, bundledTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, bundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeRepository.DeleteByIdAsync(theme.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
_mockThemeService.DeleteAsync(theme.ThemeId, Arg.Any<CancellationToken>())
|
||||
|
||||
+1
@@ -51,6 +51,7 @@ public class InstallThemeCommandHandlerTests
|
||||
public InstallThemeCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeService = Substitute.For<IThemeService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+1
@@ -45,6 +45,7 @@ public class RestoreThemeCommandHandlerTests
|
||||
public RestoreThemeCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeService = Substitute.For<IThemeService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ public class SetCurrentThemeCommandHandlerTests
|
||||
public SetCurrentThemeCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockValidator = Substitute.For<IValidator<SetCurrentThemeCommand>>();
|
||||
|
||||
+1
@@ -35,6 +35,7 @@ public class GetCurrentThemeQueryHandlerTests
|
||||
public GetCurrentThemeQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
|
||||
_sut = new GetCurrentThemeQueryHandler(_mockUnitOfWork);
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ public class GetThemeArchiveQueryHandlerTests
|
||||
public GetThemeArchiveQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeService = Substitute.For<IThemeService>();
|
||||
_mockValidator = Substitute.For<IValidator<GetThemeArchiveQuery>>();
|
||||
_mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ public class GetThemeAssetQueryHandlerTests
|
||||
public GetThemeAssetQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeService = Substitute.For<IThemeService>();
|
||||
_mockValidator = Substitute.For<IValidator<GetThemeAssetQuery>>();
|
||||
_mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ public class GetThemeTemplateQueryHandlerTests
|
||||
public GetThemeTemplateQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeService = Substitute.For<IThemeService>();
|
||||
_mockValidator = Substitute.For<IValidator<GetThemeTemplateQuery>>();
|
||||
_mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
|
||||
+8
-5
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.Themes.Management.Queries.GetThemes;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemes;
|
||||
@@ -35,6 +37,7 @@ public class GetThemesQueryHandlerTests
|
||||
public GetThemesQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
|
||||
_sut = new GetThemesQueryHandler(_mockUnitOfWork);
|
||||
@@ -49,8 +52,8 @@ public class GetThemesQueryHandlerTests
|
||||
ThemeEntity bundledLowerTheme = _themeEntityFixture.Create(themeId: "bundled-lower", name: "apple", installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity bundledUpperTheme = _themeEntityFixture.Create(themeId: "bundled-upper", name: "Banana", installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity deletedTheme = _themeEntityFixture.Create(themeId: "deleted-theme", name: "Deleted", installSource: ThemeInstallSource.Uploaded, isDeleted: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([uploadedTheme, bundledLowerTheme, bundledUpperTheme, deletedTheme]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [uploadedTheme, bundledLowerTheme, bundledUpperTheme, deletedTheme], CurrentPage = 1, PerPage = 4, Count = 4, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<ThemeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -73,8 +76,8 @@ public class GetThemesQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetThemesQuery query = _getThemesQueryFixture.Create();
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<ThemeEntity>>([]));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IReadOnlyList<ThemeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
@@ -90,7 +93,7 @@ public class GetThemesQueryHandlerTests
|
||||
// Arrange
|
||||
GetThemesQuery query = _getThemesQueryFixture.Create();
|
||||
Error error = Error.Failure("Database.Error", "Failed to get all themes");
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
|
||||
+1
@@ -36,6 +36,7 @@ public class ChangePasswordCommandHandlerTests
|
||||
public ChangePasswordCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockHashService = Substitute.For<IPasswordHashService>();
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
|
||||
|
||||
+1
@@ -39,6 +39,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
public RecoverPasswordCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockHashService = Substitute.For<IPasswordHashService>();
|
||||
_mockTotpTokenGenerator = Substitute.For<ITotpTokenGenerator>();
|
||||
_mockCryptographyService = Substitute.For<ICryptographyService>();
|
||||
|
||||
+1
@@ -44,6 +44,7 @@ public class RegisterUserCommandHandlerTests
|
||||
public RegisterUserCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockHashService = Substitute.For<IPasswordHashService>();
|
||||
_mockCryptographyService = Substitute.For<ICryptographyService>();
|
||||
_mockTotpTokenGenerator = Substitute.For<ITotpTokenGenerator>();
|
||||
|
||||
+9
-6
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
@@ -42,6 +44,7 @@ public class GetUsersQueryHandlerTests
|
||||
public GetUsersQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
@@ -70,7 +73,7 @@ public class GetUsersQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockUserRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -87,7 +90,7 @@ public class GetUsersQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -99,7 +102,7 @@ public class GetUsersQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -115,13 +118,13 @@ public class GetUsersQueryHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
GetUsersQuery query = _getUsersQueryFixture.Create();
|
||||
IEnumerable<UserEntity> users = _userEntityFixture.CreateMany(2);
|
||||
List<UserEntity> users = _userEntityFixture.CreateMany(2);
|
||||
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(users));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = users, CurrentPage = 1, PerPage = users.Count, Count = users.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ public class LoginUserQueryHandlerTests
|
||||
public LoginUserQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockHashService = Substitute.For<IPasswordHashService>();
|
||||
_mockJwtTokenGenerator = Substitute.For<IJwtTokenGenerator>();
|
||||
_mockTotpTokenGenerator = Substitute.For<ITotpTokenGenerator>();
|
||||
|
||||
+21
-18
@@ -4,6 +4,8 @@ using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
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.Validation;
|
||||
@@ -54,6 +56,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
public UpdateUserRoleAndPermissionsCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
@@ -107,7 +110,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(ApplicationErrors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -117,7 +120,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
UpdateUserRoleAndPermissionsCommand command = _updateUserRoleAndPermissionsCommandFixture.Create();
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
@@ -137,9 +140,9 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
@@ -167,16 +170,16 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
includeUserRole: true);
|
||||
|
||||
RoleEntity newRole = _roleEntityFixture.Create(roleName: "User");
|
||||
IEnumerable<UserEntity> users = [user];
|
||||
List<UserEntity> users = [user];
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(newRole);
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(users));
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<UserEntity> { Data = users, CurrentPage = 1, PerPage = users.Count, Count = users.Count, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
@@ -199,9 +202,9 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(role);
|
||||
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(permissions));
|
||||
@@ -237,9 +240,9 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(role);
|
||||
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(permissions));
|
||||
@@ -276,11 +279,11 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(_roleEntityFixture.Create(roleName: "User"));
|
||||
_mockUserRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -301,9 +304,9 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(command.UserId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockRoleRepository.GetByIdAsync(command.RoleId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(_roleEntityFixture.Create(roleName: "User"));
|
||||
_mockPermissionRepository.GetByIdsAsync(command.Permissions, Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
+6
-5
@@ -47,6 +47,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
public GetUserPermissionsQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
@@ -79,7 +80,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -96,7 +97,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -108,7 +109,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -127,7 +128,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
@@ -157,7 +158,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
|
||||
// Act
|
||||
|
||||
+7
-6
@@ -44,6 +44,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
public GetUserRoleQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
@@ -76,7 +77,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -93,7 +94,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Authorization.NotAuthorized, result.FirstError);
|
||||
await _mockAuthorizationService.DidNotReceive().IsInRoleAsync(Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,7 +106,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -124,7 +125,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
@@ -144,7 +145,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
|
||||
// Act
|
||||
@@ -171,7 +172,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(query.UserId!.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(user);
|
||||
|
||||
// Act
|
||||
|
||||
+1
@@ -40,6 +40,7 @@ public class UpdateUserSettingsCommandHandlerTests
|
||||
public UpdateUserSettingsCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockUserSettingsRepository = Substitute.For<IUserSettingsRepository>();
|
||||
|
||||
|
||||
+1
@@ -38,6 +38,7 @@ public class GetUserSettingsQueryHandlerTests
|
||||
public GetUserSettingsQueryHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockUserSettingsRepository = Substitute.For<IUserSettingsRepository>();
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
@@ -47,6 +49,7 @@ public class DataSeedServiceTests
|
||||
public DataSeedServiceTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockDateTimeProvider = Substitute.For<IDateTimeProvider>();
|
||||
_mockPermissionRepository = Substitute.For<IPermissionRepository>();
|
||||
_fixedUtcNow = DateTime.UtcNow;
|
||||
@@ -252,7 +255,15 @@ public class DataSeedServiceTests
|
||||
_mockUnitOfWork.RolePermissionRepository.Returns(mockRolePermissionRepository);
|
||||
|
||||
mockRoleRepository.GetByNameAsync("Admin", Arg.Any<CancellationToken>()).Returns(adminRole);
|
||||
mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(permissions);
|
||||
mockPermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(new PaginatedResultDto<PermissionEntity>
|
||||
{
|
||||
Data = permissions,
|
||||
CurrentPage = 1,
|
||||
PerPage = permissions.Count,
|
||||
Count = permissions.Count,
|
||||
NumberOfPages = 1
|
||||
});
|
||||
mockRolePermissionRepository.InsertAsync(Arg.Any<RolePermissionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
@@ -310,7 +321,7 @@ public class DataSeedServiceTests
|
||||
_mockUnitOfWork.PermissionRepository.Returns(mockPermissionRepository);
|
||||
|
||||
mockRoleRepository.GetByNameAsync("Admin", Arg.Any<CancellationToken>()).Returns(adminRole);
|
||||
mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
mockPermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.SetAdminRolePermissionsAsync(userId, CancellationToken.None);
|
||||
@@ -340,7 +351,15 @@ public class DataSeedServiceTests
|
||||
_mockUnitOfWork.RolePermissionRepository.Returns(mockRolePermissionRepository);
|
||||
|
||||
mockRoleRepository.GetByNameAsync("Admin", Arg.Any<CancellationToken>()).Returns(adminRole);
|
||||
mockPermissionRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(permissions);
|
||||
mockPermissionRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(new PaginatedResultDto<PermissionEntity>
|
||||
{
|
||||
Data = permissions,
|
||||
CurrentPage = 1,
|
||||
PerPage = permissions.Count,
|
||||
Count = permissions.Count,
|
||||
NumberOfPages = 1
|
||||
});
|
||||
mockRolePermissionRepository.InsertAsync(Arg.Any<RolePermissionEntity>(), Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -396,7 +415,7 @@ public class DataSeedServiceTests
|
||||
_mockUnitOfWork.UserRoleRepository.Returns(mockUserRoleRepository);
|
||||
|
||||
mockRoleRepository.GetByNameAsync("Admin", Arg.Any<CancellationToken>()).Returns(adminRole);
|
||||
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns(adminUser);
|
||||
mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>()).Returns(adminUser);
|
||||
mockUserRoleRepository.InsertAsync(Arg.Any<UserRoleEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
@@ -454,7 +473,7 @@ public class DataSeedServiceTests
|
||||
_mockUnitOfWork.UserRepository.Returns(mockUserRepository);
|
||||
|
||||
mockRoleRepository.GetByNameAsync("Admin", Arg.Any<CancellationToken>()).Returns(adminRole);
|
||||
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns((UserEntity?)null);
|
||||
mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>()).Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
@@ -485,7 +504,7 @@ public class DataSeedServiceTests
|
||||
_mockUnitOfWork.UserRoleRepository.Returns(mockUserRoleRepository);
|
||||
|
||||
mockRoleRepository.GetByNameAsync("Admin", Arg.Any<CancellationToken>()).Returns(adminRole);
|
||||
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns(adminUser);
|
||||
mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>()).Returns(adminUser);
|
||||
mockUserRoleRepository.InsertAsync(Arg.Any<UserRoleEntity>(), Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -537,7 +556,7 @@ public class DataSeedServiceTests
|
||||
_mockUnitOfWork.UserRepository.Returns(mockUserRepository);
|
||||
|
||||
mockRoleRepository.GetByNameAsync("Admin", Arg.Any<CancellationToken>()).Returns(adminRole);
|
||||
mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>()).Returns(expectedError);
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.SetAdminRoleToAdministratorAccount(userId, CancellationToken.None);
|
||||
@@ -580,7 +599,7 @@ public class DataSeedServiceTests
|
||||
|
||||
await mockScheduledJobRepository.Received(5).InsertAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
await mockScheduledJobRepository.DidNotReceive().GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await mockScheduledJobRepository.DidNotReceive().GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -8,6 +8,7 @@ using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.DataAccess.Common.DependencyInjection;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
@@ -96,9 +97,11 @@ public class UnitOfWorkTests
|
||||
CancellationToken cancellationToken = new();
|
||||
|
||||
// Act
|
||||
await unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
Result<Success> result = await unitOfWork.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
await dbContext.Received(1).SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
|
||||
+37
-36
@@ -40,6 +40,7 @@ public class AuthorizationServiceTests
|
||||
public AuthorizationServiceTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
_mockAuthorizationPolicyFactory = Substitute.For<IAuthorizationPolicyFactory>();
|
||||
|
||||
@@ -53,7 +54,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -61,7 +62,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -70,7 +71,7 @@ public class AuthorizationServiceTests
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
Error error = Error.Failure("Database.Error", "Failed to retrieve user");
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -78,7 +79,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -88,7 +89,7 @@ public class AuthorizationServiceTests
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
|
||||
directPermissions: [AuthorizationPermission.CanViewUsers]);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -96,7 +97,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -111,7 +112,7 @@ public class AuthorizationServiceTests
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
|
||||
rolePermissions: rolePermissions);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -119,7 +120,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -128,7 +129,7 @@ public class AuthorizationServiceTests
|
||||
// Arrange
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions();
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -136,7 +137,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -146,7 +147,7 @@ public class AuthorizationServiceTests
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
|
||||
directPermissions: [AuthorizationPermission.CanDeleteUsers]);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -154,7 +155,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -170,7 +171,7 @@ public class AuthorizationServiceTests
|
||||
directPermissions: [AuthorizationPermission.CanViewUsers],
|
||||
rolePermissions: rolePermissions);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -178,7 +179,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -186,7 +187,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -194,7 +195,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -203,7 +204,7 @@ public class AuthorizationServiceTests
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
Error error = Error.Failure("Database.Error", "Failed to retrieve user");
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -211,7 +212,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -226,7 +227,7 @@ public class AuthorizationServiceTests
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
|
||||
rolePermissions: rolePermissions);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -234,7 +235,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -249,7 +250,7 @@ public class AuthorizationServiceTests
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
|
||||
rolePermissions: rolePermissions);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -257,7 +258,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -266,7 +267,7 @@ public class AuthorizationServiceTests
|
||||
// Arrange
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions();
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -274,7 +275,7 @@ public class AuthorizationServiceTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -409,7 +410,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -418,7 +419,7 @@ public class AuthorizationServiceTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Users.UserDoesNotExist, result.FirstError);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -427,7 +428,7 @@ public class AuthorizationServiceTests
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
Error error = Error.Failure("Database.Error", "Failed to retrieve user");
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -436,7 +437,7 @@ public class AuthorizationServiceTests
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -444,7 +445,7 @@ public class AuthorizationServiceTests
|
||||
{
|
||||
// Arrange
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions();
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -455,7 +456,7 @@ public class AuthorizationServiceTests
|
||||
Assert.Equal(user.Id, result.Value.UserId);
|
||||
Assert.Null(result.Value.Role);
|
||||
Assert.Empty(result.Value.Permissions);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -469,7 +470,7 @@ public class AuthorizationServiceTests
|
||||
AuthorizationPermission.CanDeleteUsers
|
||||
]);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -481,7 +482,7 @@ public class AuthorizationServiceTests
|
||||
Assert.Null(result.Value.Role);
|
||||
Assert.Equal([AuthorizationPermission.CanViewUsers, AuthorizationPermission.CanDeleteUsers],
|
||||
result.Value.Permissions);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -499,7 +500,7 @@ public class AuthorizationServiceTests
|
||||
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
|
||||
rolePermissions: rolePermissions);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -511,7 +512,7 @@ public class AuthorizationServiceTests
|
||||
Assert.Equal("Admin", result.Value.Role);
|
||||
Assert.Equal([AuthorizationPermission.CanViewUsers, AuthorizationPermission.CanDeleteUsers],
|
||||
result.Value.Permissions);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -530,7 +531,7 @@ public class AuthorizationServiceTests
|
||||
directPermissions: [AuthorizationPermission.CanRegisterUsers],
|
||||
rolePermissions: rolePermissions);
|
||||
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -549,6 +550,6 @@ public class AuthorizationServiceTests
|
||||
},
|
||||
result.Value.Permissions
|
||||
);
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+17
-16
@@ -40,6 +40,7 @@ public class LibraryOwnershipPolicyTests
|
||||
public LibraryOwnershipPolicyTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
_mockUnitOfWork.UserRepository.Returns(_mockUserRepository);
|
||||
@@ -59,8 +60,8 @@ public class LibraryOwnershipPolicyTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -69,7 +70,7 @@ public class LibraryOwnershipPolicyTests
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -77,7 +78,7 @@ public class LibraryOwnershipPolicyTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -86,7 +87,7 @@ public class LibraryOwnershipPolicyTests
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to retrieve user"));
|
||||
|
||||
// Act
|
||||
@@ -94,7 +95,7 @@ public class LibraryOwnershipPolicyTests
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -107,7 +108,7 @@ public class LibraryOwnershipPolicyTests
|
||||
{ "Admin", [] }
|
||||
});
|
||||
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
|
||||
_mockUserRepository.GetByIdAsync(adminUser.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(adminUser.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(adminUser));
|
||||
|
||||
// Act
|
||||
@@ -115,7 +116,7 @@ public class LibraryOwnershipPolicyTests
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -125,9 +126,9 @@ public class LibraryOwnershipPolicyTests
|
||||
Guid userId = Guid.NewGuid();
|
||||
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
|
||||
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(regularUser));
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<LibraryEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
@@ -144,9 +145,9 @@ public class LibraryOwnershipPolicyTests
|
||||
Guid userId = Guid.NewGuid();
|
||||
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
|
||||
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(regularUser));
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to retrieve library"));
|
||||
|
||||
// Act
|
||||
@@ -164,9 +165,9 @@ public class LibraryOwnershipPolicyTests
|
||||
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(userId: userId);
|
||||
LibraryOwnershipPolicyContext context = new(library.Id);
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(regularUser));
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
@@ -184,9 +185,9 @@ public class LibraryOwnershipPolicyTests
|
||||
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
|
||||
LibraryEntity library = _libraryEntityFixture.Create(userId: Guid.NewGuid());
|
||||
LibraryOwnershipPolicyContext context = new(library.Id);
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(regularUser));
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-4
@@ -32,6 +32,7 @@ public class Over18PolicyTests
|
||||
public Over18PolicyTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
_mockUnitOfWork.UserRepository.Returns(_mockUserRepository);
|
||||
|
||||
@@ -43,7 +44,7 @@ public class Over18PolicyTests
|
||||
{
|
||||
// Arrange
|
||||
UserEntity user = _userEntityFixture.Create();
|
||||
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
@@ -58,7 +59,7 @@ public class Over18PolicyTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -73,7 +74,7 @@ public class Over18PolicyTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to retrieve user"));
|
||||
|
||||
// Act
|
||||
@@ -88,7 +89,7 @@ public class Over18PolicyTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
|
||||
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result<UserEntity?>.Success(null));
|
||||
|
||||
// Act
|
||||
|
||||
+30
-30
@@ -2,7 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
@@ -139,7 +139,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
"Test Title",
|
||||
Arg.Any<ArtworkDto>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkType.Cover, coverArtwork.ArtworkType);
|
||||
Assert.Equal(0, coverArtwork.Ordinal);
|
||||
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
|
||||
@@ -168,7 +168,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
|
||||
// the book already has a stored cover with the same content hash as the resolved artwork
|
||||
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
SetupSingleBookPage(book, artworkPluginId);
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
@@ -179,7 +179,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
// Assert
|
||||
// the identical artwork is not copied again, so the artwork storage service is not called and the stored file name is kept
|
||||
await mockBookArtworkService.DidNotReceive().SaveBookArtworkAsync(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<ArtworkDto>(), Arg.Any<CancellationToken>());
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
|
||||
Assert.Equal("existing\\cover.jpeg", coverArtwork.FileName);
|
||||
Assert.Equal("Artwork Provider", coverArtwork.Provider);
|
||||
@@ -212,7 +212,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
// Assert
|
||||
await mockBookArtworkService.DidNotReceive().SaveBookArtworkAsync(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<ArtworkDto>(), Arg.Any<CancellationToken>());
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkType.Cover, coverArtwork.ArtworkType);
|
||||
Assert.Equal(0, coverArtwork.Ordinal);
|
||||
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
|
||||
@@ -226,7 +226,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
// Arrange
|
||||
_mockArtworkConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -330,7 +330,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
_mockServiceScopeFactory.CreateAsyncScope().Returns(asyncServiceScope);
|
||||
|
||||
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: false)));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
|
||||
|
||||
@@ -346,7 +346,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -354,7 +354,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
// Assert
|
||||
// the provider that requires access to the web is skipped when the library does not permit web downloads
|
||||
await webProvider.DidNotReceive().GetArtworkAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>());
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
|
||||
Assert.Equal("Local Provider", coverArtwork.Provider);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
@@ -377,7 +377,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([_artworkConfigurationEntityFixture.Create(_libraryId.Value, artworkPluginId, 1)]));
|
||||
_mockBookRepository.GetBooksNeedingArtworkCountAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to count the books that need artwork"));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -405,7 +405,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
.Returns(Result.From(1));
|
||||
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to get the books that need artwork"));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -429,7 +429,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
|
||||
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
|
||||
_mockArtworkConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
@@ -440,7 +440,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to get the author display names"));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -465,7 +465,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
|
||||
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
SetupSingleBookPage(book, artworkPluginId);
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
@@ -474,7 +474,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
|
||||
Assert.Equal("existing\\cover.jpeg", coverArtwork.FileName);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
@@ -507,7 +507,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
|
||||
Assert.Null(coverArtwork.FileName);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
@@ -532,7 +532,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
|
||||
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
SetupSingleBookPage(book, artworkPluginId);
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
@@ -541,7 +541,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
|
||||
Assert.Equal("existing\\cover.jpeg", coverArtwork.FileName);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
@@ -577,7 +577,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
// Assert
|
||||
// for remote artwork, the content hash is computed on the stored copy, so it is only known after the artwork is stored
|
||||
await mockBookArtworkService.Received(1).SaveBookArtworkAsync(_libraryId.Value, book.Id, "My Library", "Frank Herbert", Arg.Any<string>(), Arg.Any<ArtworkDto>(), Arg.Any<CancellationToken>());
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
|
||||
Assert.Equal("\\media\\books\\Library\\Author\\Title\\cover.jpeg", coverArtwork.FileName);
|
||||
Assert.Equal(999ul, coverArtwork.ContentHash);
|
||||
@@ -605,7 +605,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
|
||||
// the book has no known ISBNs of its own, so the artwork lookup is built without an ISBN
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub", title: "Test Title", includeMetadata: false);
|
||||
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
|
||||
SetupSingleBookPage(book, artworkPluginId);
|
||||
// the author of the book is not known, so its artwork directory falls back to an empty author name
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
@@ -623,7 +623,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
"Test Title",
|
||||
Arg.Any<ArtworkDto>(),
|
||||
Arg.Any<CancellationToken>());
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
|
||||
Assert.Equal("\\media\\books\\Library\\Author\\Title\\cover.jpeg", coverArtwork.FileName);
|
||||
Assert.Equal(222ul, coverArtwork.ContentHash);
|
||||
@@ -669,7 +669,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
|
||||
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
|
||||
|
||||
@@ -682,7 +682,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
.Returns(Result.From(1));
|
||||
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
|
||||
@@ -691,7 +691,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
// Assert
|
||||
// a failing artwork provider must not prevent the artwork of the other provider from being used
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
|
||||
Assert.Equal("Second Provider", coverArtwork.Provider);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
@@ -735,7 +735,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
|
||||
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
|
||||
|
||||
@@ -748,7 +748,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
.Returns(Result.From(1));
|
||||
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
|
||||
|
||||
@@ -757,7 +757,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
|
||||
// Assert
|
||||
// a provider that returns remote artwork must require web access, so its artwork is skipped and the next provider is used
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
|
||||
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
|
||||
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
|
||||
Assert.Equal("Second Provider", coverArtwork.Provider);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
@@ -769,7 +769,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
// Arrange
|
||||
_mockArtworkConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
IMediaLibraryScanJob mockChildJob = Substitute.For<IMediaLibraryScanJob>();
|
||||
mockChildJob.ExecuteAsync(Arg.Any<Guid>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
|
||||
@@ -815,7 +815,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
private void SetupSingleBookPage(BookEntity book, Guid artworkPluginId)
|
||||
{
|
||||
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
|
||||
|
||||
@@ -827,6 +827,6 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
|
||||
.Returns(Result.From(1));
|
||||
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
}
|
||||
}
|
||||
+1
@@ -55,6 +55,7 @@ public class MediaLibraryScanDiffJobTests
|
||||
_mockServiceScope.ServiceProvider.Returns(_mockServiceProvider);
|
||||
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockStagingResultsRepository = Substitute.For<ILibraryScanStagingResultsRepository>();
|
||||
_mockUnitOfWork.LibraryScanStagingResultsRepository.Returns(_mockStagingResultsRepository);
|
||||
_mockServiceProvider.GetService(typeof(IUnitOfWork)).Returns(_mockUnitOfWork);
|
||||
|
||||
+1
@@ -62,6 +62,7 @@ public class MediaLibraryScanHashJobTests
|
||||
_mockServiceScope.ServiceProvider.Returns(_mockServiceProvider);
|
||||
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockStagingResultsRepository = Substitute.For<ILibraryScanStagingResultsRepository>();
|
||||
_mockUnitOfWork.LibraryScanStagingResultsRepository.Returns(_mockStagingResultsRepository);
|
||||
_mockServiceProvider.GetService(typeof(IUnitOfWork)).Returns(_mockUnitOfWork);
|
||||
|
||||
+29
-31
@@ -4,7 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaContributors;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -127,7 +127,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
.Returns(Result.From(0));
|
||||
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -144,7 +144,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
// Arrange
|
||||
_mockConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -339,8 +339,8 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
|
||||
firstProvider.Name.Returns("First Provider");
|
||||
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
|
||||
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", roleName: "Author", roleCategory: MediaContributorRoleCategory.Author);
|
||||
MediaContributorDto translator = _mediaContributorDtoFixture.Create(displayName: "Jane Translator", roleName: "Translator", roleCategory: MediaContributorRoleCategory.Translator);
|
||||
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", role: MediaContributorRole.Author);
|
||||
MediaContributorDto translator = _mediaContributorDtoFixture.Create(displayName: "Jane Translator", role: MediaContributorRole.Translator);
|
||||
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [author, translator]));
|
||||
|
||||
@@ -362,15 +362,13 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
await _mockMediaContributorRepository.Received(1).FindOrCreateByDisplayNameAsync("Frank Herbert", Arg.Any<string?>(), Arg.Any<CancellationToken>());
|
||||
await _mockMediaContributorRepository.Received(1).FindOrCreateByDisplayNameAsync("Jane Translator", Arg.Any<string?>(), Arg.Any<CancellationToken>());
|
||||
|
||||
// the participation rows are replaced on the entity, carrying the role and the category of each contributor
|
||||
Assert.Equal(2, book.BookContributors.Count);
|
||||
BookContributorEntity linkedAuthor = Assert.Single(book.BookContributors, contributor => contributor.MediaContributorId == authorEntity.Id);
|
||||
Assert.Equal("Author", linkedAuthor.RoleName);
|
||||
Assert.Equal(MediaContributorRoleCategory.Author, linkedAuthor.RoleCategory);
|
||||
// the participation rows are replaced on the entity, carrying the canonical role of each contributor
|
||||
Assert.Equal(2, book.Contributors.Count);
|
||||
BookContributorEntity linkedAuthor = Assert.Single(book.Contributors, contributor => contributor.MediaContributorId == authorEntity.Id);
|
||||
Assert.Equal(MediaContributorRole.Author, linkedAuthor.Role);
|
||||
Assert.Equal(book.Id, linkedAuthor.BookId);
|
||||
BookContributorEntity linkedTranslator = Assert.Single(book.BookContributors, contributor => contributor.MediaContributorId == translatorEntity.Id);
|
||||
Assert.Equal("Translator", linkedTranslator.RoleName);
|
||||
Assert.Equal(MediaContributorRoleCategory.Translator, linkedTranslator.RoleCategory);
|
||||
BookContributorEntity linkedTranslator = Assert.Single(book.Contributors, contributor => contributor.MediaContributorId == translatorEntity.Id);
|
||||
Assert.Equal(MediaContributorRole.Translator, linkedTranslator.Role);
|
||||
Assert.Equal(MetadataStatus.Enriched, book.MetadataStatus);
|
||||
}
|
||||
|
||||
@@ -382,7 +380,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
|
||||
firstProvider.Name.Returns("First Provider");
|
||||
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
|
||||
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", roleName: "Author", roleCategory: MediaContributorRoleCategory.Author);
|
||||
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", role: MediaContributorRole.Author);
|
||||
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [author]));
|
||||
|
||||
@@ -396,7 +394,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
.Returns(Result.From(2));
|
||||
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([firstBook, secondBook]), Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
MediaContributorEntity authorEntity = _mediaContributorEntityFixture.Create(displayName: "Frank Herbert");
|
||||
_mockMediaContributorRepository.FindOrCreateByDisplayNameAsync("Frank Herbert", Arg.Any<string?>(), Arg.Any<CancellationToken>())
|
||||
@@ -408,10 +406,10 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
// Assert
|
||||
// the contributor cache of the page guarantees a single contributor per person, so the repository is queried only once
|
||||
await _mockMediaContributorRepository.Received(1).FindOrCreateByDisplayNameAsync("Frank Herbert", Arg.Any<string?>(), Arg.Any<CancellationToken>());
|
||||
Assert.Single(firstBook.BookContributors);
|
||||
Assert.Single(secondBook.BookContributors);
|
||||
Assert.Equal(authorEntity.Id, firstBook.BookContributors[0].MediaContributorId);
|
||||
Assert.Equal(authorEntity.Id, secondBook.BookContributors[0].MediaContributorId);
|
||||
Assert.Single(firstBook.Contributors);
|
||||
Assert.Single(secondBook.Contributors);
|
||||
Assert.Equal(authorEntity.Id, firstBook.Contributors[0].MediaContributorId);
|
||||
Assert.Equal(authorEntity.Id, secondBook.Contributors[0].MediaContributorId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -435,7 +433,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
|
||||
SetupRealServiceProviderForProviders(localPluginId, localProvider, webPluginId, webProvider, shouldAggregateMetadataWhenMissing: false);
|
||||
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(title: "My Library", canDownloadMetadataFromWeb: false)));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
|
||||
|
||||
@@ -473,7 +471,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
|
||||
SetupRealServiceProviderForProviders(localPluginId, localProvider, webPluginId, webProvider, shouldAggregateMetadataWhenMissing: false);
|
||||
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(title: "My Library", canDownloadMetadataFromWeb: true)));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
|
||||
|
||||
@@ -503,7 +501,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([_configurationEntityFixture.Create(_libraryId.Value, firstPluginId, 1)]));
|
||||
_mockBookRepository.GetBooksNeedingMetadataCountAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to count the books to enrich"));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -528,7 +526,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
.Returns(Result.From(1));
|
||||
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to get the books to enrich"));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -607,7 +605,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
|
||||
firstProvider.Name.Returns("First Provider");
|
||||
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
|
||||
MediaContributorDto namelessContributor = _mediaContributorDtoFixture.Create(roleName: "Author", roleCategory: MediaContributorRoleCategory.Author) with { Name = null };
|
||||
MediaContributorDto namelessContributor = _mediaContributorDtoFixture.Create(role: MediaContributorRole.Author) with { Name = null };
|
||||
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [namelessContributor]));
|
||||
|
||||
@@ -621,7 +619,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
// Assert
|
||||
// a contributor without a display name cannot be linked to the book, so no contributor is queried or created
|
||||
await _mockMediaContributorRepository.DidNotReceive().FindOrCreateByDisplayNameAsync(Arg.Any<string>(), Arg.Any<string?>(), Arg.Any<CancellationToken>());
|
||||
Assert.Empty(book.BookContributors);
|
||||
Assert.Empty(book.Contributors);
|
||||
Assert.Equal(MetadataStatus.Enriched, book.MetadataStatus);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
}
|
||||
@@ -650,9 +648,9 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
BookContributorEntity linkedContributor = Assert.Single(book.BookContributors);
|
||||
Assert.Equal("Contributor", linkedContributor.RoleName);
|
||||
Assert.Equal(MediaContributorRoleCategory.Other, linkedContributor.RoleCategory);
|
||||
// a contributor without a role is linked with the default canonical role
|
||||
BookContributorEntity linkedContributor = Assert.Single(book.Contributors);
|
||||
Assert.Equal(MediaContributorRole.Author, linkedContributor.Role);
|
||||
Assert.Equal(MetadataStatus.Enriched, book.MetadataStatus);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
|
||||
}
|
||||
@@ -665,7 +663,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
|
||||
firstProvider.Name.Returns("First Provider");
|
||||
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
|
||||
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", roleName: "Author", roleCategory: MediaContributorRoleCategory.Author);
|
||||
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", role: MediaContributorRole.Author);
|
||||
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [author]));
|
||||
|
||||
@@ -689,7 +687,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
// Arrange
|
||||
_mockConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
IMediaLibraryScanJob mockChildJob = Substitute.For<IMediaLibraryScanJob>();
|
||||
mockChildJob.ExecuteAsync(Arg.Any<Guid>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
|
||||
@@ -747,6 +745,6 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
|
||||
.Returns(Result.From(1));
|
||||
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -2,7 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
@@ -219,7 +219,7 @@ public class MediaLibraryScanProviderConfigurationInvalidationJobTests
|
||||
public async Task ExecuteAsync_WhenGettingTheLibraryFails_ShouldMarkJobAsFailedAndPublishFailureEvent()
|
||||
{
|
||||
// Arrange
|
||||
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to get the media library"));
|
||||
SetupConfigurations();
|
||||
|
||||
@@ -254,7 +254,7 @@ public class MediaLibraryScanProviderConfigurationInvalidationJobTests
|
||||
public async Task ExecuteAsync_WhenLibraryDoesNotExist_ShouldMarkJobAsFailedAndPublishFailureEvent()
|
||||
{
|
||||
// Arrange
|
||||
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -413,10 +413,10 @@ public class MediaLibraryScanProviderConfigurationInvalidationJobTests
|
||||
/// <param name="artworkConfigurations">The artwork provider configurations of the media library.</param>
|
||||
private void SetupLibraryAndConfigurations(LibraryEntity library, List<LibraryMetadataProviderConfigurationEntity>? metadataConfigurations = null, List<LibraryArtworkProviderConfigurationEntity>? artworkConfigurations = null)
|
||||
{
|
||||
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<LibraryEntity?>(library));
|
||||
SetupConfigurations(metadataConfigurations, artworkConfigurations);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Domain.Common.Events;
|
||||
@@ -106,7 +106,7 @@ public class MediaLibraryScanResultsSaveJobTests
|
||||
.Returns(Result.From<BookEntity?>(null));
|
||||
_mockBookRepository.InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Created));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -133,7 +133,7 @@ public class MediaLibraryScanResultsSaveJobTests
|
||||
.Returns(Result.From(Result.Updated));
|
||||
_mockSnapshotRepository.GetPathsAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<string>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -158,7 +158,7 @@ public class MediaLibraryScanResultsSaveJobTests
|
||||
.Returns(Result.From<IReadOnlyList<string>>(["existing.pdf"]));
|
||||
_mockBookRepository.GetByPathAsync(_libraryId.Value, "existing.pdf", Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<BookEntity?>(_bookEntityFixture.Create(path: "existing.pdf")));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
@@ -356,7 +356,7 @@ public class MediaLibraryScanResultsSaveJobTests
|
||||
.Returns(Result.From(Result.Updated));
|
||||
_mockSnapshotRepository.GetPathsAsync(_libraryId.Value, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<string>>([]));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
IMediaLibraryScanJob mockChild = Substitute.For<IMediaLibraryScanJob>();
|
||||
mockChild.ExecuteAsync(Arg.Any<Guid>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
|
||||
@@ -389,7 +389,7 @@ public class MediaLibraryScanResultsSaveJobTests
|
||||
.Returns(Result.From<BookEntity?>(null));
|
||||
_mockBookRepository.InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Created));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
@@ -45,6 +45,7 @@ public class MediaLibraryProviderConfigurationStoreTests
|
||||
public MediaLibraryProviderConfigurationStoreTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockMetadataConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockArtworkConfigurationRepository = Substitute.For<IArtworkProviderConfigurationRepository>();
|
||||
_mockBookReaderConfigurationRepository = Substitute.For<ILibraryBookReaderConfigurationRepository>();
|
||||
|
||||
+9
-6
@@ -4,6 +4,8 @@ using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
@@ -62,6 +64,7 @@ public class PluginDetectionSyncJobTests
|
||||
_mockServiceScope.ServiceProvider.Returns(_mockServiceProvider);
|
||||
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
|
||||
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
|
||||
@@ -187,8 +190,8 @@ public class PluginDetectionSyncJobTests
|
||||
.Returns(Result.From(Result.Updated));
|
||||
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.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [loadedPluginRow, stalePluginRow], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockPluginRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
PluginDetectionSyncJob sut = CreateSut();
|
||||
@@ -213,8 +216,8 @@ public class PluginDetectionSyncJobTests
|
||||
_mockPluginRepository.UpsertAsync(Arg.Any<PluginEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Updated));
|
||||
LibraryEntity bookLibrary = _libraryEntityFixture.Create(libraryType: LibraryType.Book);
|
||||
_mockLibraryRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From((IEnumerable<LibraryEntity>)[bookLibrary]));
|
||||
_mockLibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<LibraryEntity> { Data = [bookLibrary], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockProviderConfigurationStore.EnsureProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Success);
|
||||
PluginDetectionSyncJob sut = CreateSut();
|
||||
@@ -240,8 +243,8 @@ public class PluginDetectionSyncJobTests
|
||||
assemblyName: "MyPlugin",
|
||||
errorMessage: "Failed to load plugin assembly 'MyPlugin.dll': unexpected error");
|
||||
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.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [staleLoadedRow], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockPluginRepository.DeleteByIdAsync(previouslyLoadedPlugin.Id, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Deleted);
|
||||
PluginDetectionSyncJob sut = CreateSut([loadError]);
|
||||
|
||||
+5
-4
@@ -35,6 +35,7 @@ public class PluginSettingsStoreTests
|
||||
public PluginSettingsStoreTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockLogger = Substitute.For<ILogger<PluginSettingsStore>>();
|
||||
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
|
||||
@@ -49,7 +50,7 @@ public class PluginSettingsStoreTests
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
Dictionary<string, string> expectedSettings = new() { ["ApiKey"] = "test-key", ["Enabled"] = "true" };
|
||||
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, settingsJson: JsonSerializer.Serialize(expectedSettings));
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(pluginEntity));
|
||||
|
||||
// Act
|
||||
@@ -66,7 +67,7 @@ public class PluginSettingsStoreTests
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, includeSettingsJson: false);
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(pluginEntity));
|
||||
|
||||
// Act
|
||||
@@ -81,7 +82,7 @@ public class PluginSettingsStoreTests
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<PluginEntity?>(null));
|
||||
|
||||
// Act
|
||||
@@ -96,7 +97,7 @@ public class PluginSettingsStoreTests
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
|
||||
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Database.Error", "Failed to retrieve the plugin"));
|
||||
|
||||
// Act
|
||||
|
||||
+45
-43
@@ -4,6 +4,8 @@ using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Themes;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
|
||||
@@ -73,7 +75,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
|
||||
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
|
||||
_mockUnitOfWork.ScheduledJobExecutionRepository.Returns(_mockScheduledJobExecutionRepository);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockScheduledJobExecutionRepository.UpdateAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
|
||||
@@ -132,7 +134,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
{
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
|
||||
// Act
|
||||
@@ -152,7 +154,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
|
||||
|
||||
// Act
|
||||
@@ -169,7 +171,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
|
||||
using CancellationTokenSource cycleCancellationTokenSource = new();
|
||||
_runtimeRegistry.TryStartCycle(scheduledJobId, cycleCancellationTokenSource);
|
||||
@@ -190,7 +192,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
_mockDomainEventPublisher.When(publisher => publisher.PublishAsync(Arg.Is<ScheduledJobExecutionStartedDomainEvent>(_ => true), Arg.Any<CancellationToken>()))
|
||||
@@ -213,7 +215,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
|
||||
@@ -233,7 +235,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: false, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
|
||||
@@ -252,7 +254,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
|
||||
// Act
|
||||
ScheduledJobStatus result = await InvokeAsync<ScheduledJobStatus>("ReconcileInterruptedRunAsync", scheduledJobId, CancellationToken.None);
|
||||
@@ -269,7 +271,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.OnceAtStartup);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.OnceAtStartup));
|
||||
|
||||
// Act
|
||||
@@ -288,7 +290,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.OnceAtStartup);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { activeJob });
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.OnceAtStartup));
|
||||
|
||||
// Act
|
||||
@@ -340,7 +342,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
IThemeService mockThemeService = Substitute.For<IThemeService>();
|
||||
mockThemeService.GetBundledThemeArchivePaths().Returns([]);
|
||||
IThemeRepository mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
|
||||
mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUnitOfWork.ThemeRepository.Returns(mockThemeRepository);
|
||||
_services[typeof(IThemeService)] = mockThemeService;
|
||||
|
||||
@@ -349,7 +351,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
|
||||
// Assert
|
||||
mockThemeService.Received(1).GetBundledThemeArchivePaths();
|
||||
await mockThemeRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await mockThemeRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -391,7 +393,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
IThemeService mockThemeService = Substitute.For<IThemeService>();
|
||||
mockThemeService.GetBundledThemeArchivePaths().Returns([]);
|
||||
IThemeRepository mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
|
||||
mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockUnitOfWork.ThemeRepository.Returns(mockThemeRepository);
|
||||
_services[typeof(IThemeService)] = mockThemeService;
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
@@ -412,7 +414,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
Error error = Error.Failure("ScheduledJobs.NotFound", "Failed to read the scheduled job");
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
await InvokeAsync("RunCycleWorkerAsync", scheduledJobId, false, CancellationToken.None);
|
||||
@@ -428,7 +430,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
cancellationTokenSource.Cancel();
|
||||
|
||||
@@ -445,7 +447,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create();
|
||||
Error error = Error.Failure("ScheduledJobs.NotFound", "Failed to read the scheduled job");
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(error);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
|
||||
|
||||
// Act
|
||||
await InvokeAsync("ExecuteScheduledJobRunAsync", scheduledJobId, false, CancellationToken.None);
|
||||
@@ -462,7 +464,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// An interval schedule whose interval is not positive cannot be converted to its domain object.
|
||||
ScheduledJobEntity invalidJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 0);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(invalidJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(invalidJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(invalidJob);
|
||||
|
||||
// Act
|
||||
await InvokeAsync("ExecuteScheduledJobRunAsync", scheduledJobId, false, CancellationToken.None);
|
||||
@@ -478,7 +480,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
_mockDomainEventPublisher.When(publisher => publisher.PublishAsync(Arg.Any<ScheduledJobExecutionStartedDomainEvent>(), Arg.Any<CancellationToken>()))
|
||||
.Do(_ => cancellationTokenSource.Cancel());
|
||||
@@ -496,7 +498,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
|
||||
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Task.Failed", "The task of the scheduled job failed."));
|
||||
@@ -515,7 +517,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
|
||||
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<Success>>(new InvalidOperationException("The task threw.")));
|
||||
@@ -533,7 +535,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<Success>>(new OperationCanceledException()));
|
||||
|
||||
@@ -550,7 +552,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
_mockTaskExecutor.When(executor => executor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>()))
|
||||
.Do(_ => cancellationTokenSource.Cancel());
|
||||
@@ -570,7 +572,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
|
||||
Assert.True(_runtimeRegistry.TryAcquireRunSlot(scheduledJobId));
|
||||
|
||||
// Act
|
||||
@@ -589,7 +591,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
|
||||
_mockDomainEventPublisher.When(publisher => publisher.PublishAsync(Arg.Any<ScheduledJobExecutionStartedDomainEvent>(), Arg.Any<CancellationToken>()))
|
||||
.Do(_ => throw new OperationCanceledException());
|
||||
|
||||
@@ -659,7 +661,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
@@ -681,7 +683,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
{
|
||||
// Arrange
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create();
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("ScheduledJobs.NotFound", "Failed to read the scheduled job"));
|
||||
|
||||
// Act
|
||||
@@ -697,7 +699,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("ScheduledJobExecutions.NotFound", "Failed to read the open execution"));
|
||||
|
||||
@@ -736,7 +738,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<ScheduledJobExecutionEntity?>(null));
|
||||
|
||||
@@ -755,7 +757,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>())
|
||||
@@ -775,7 +777,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
_mockScheduledJobExecutionRepository.UpdateAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>())
|
||||
@@ -795,10 +797,10 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException(new InvalidOperationException("Save failed")));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException<Result<Success>>(new InvalidOperationException("Save failed")));
|
||||
|
||||
// Act
|
||||
ScheduledJobStatus result = await InvokeAsync<ScheduledJobStatus>("ReconcileInterruptedRunAsync", scheduledJobId, CancellationToken.None);
|
||||
@@ -813,10 +815,10 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException(new OperationCanceledException()));
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException<Result<Success>>(new OperationCanceledException()));
|
||||
|
||||
// Act
|
||||
ScheduledJobStatus result = await InvokeAsync<ScheduledJobStatus>("ReconcileInterruptedRunAsync", scheduledJobId, CancellationToken.None);
|
||||
@@ -846,7 +848,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { runningJob });
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: false, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
|
||||
@@ -868,7 +870,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
|
||||
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { runningJob });
|
||||
// The first read reconciles the interrupted run while the job is still running; the reads made by the resumed cycle observe the reconciled active status.
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob, activeJob, activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob, activeJob, activeJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.OnceAtStartup));
|
||||
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
|
||||
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
|
||||
@@ -888,7 +890,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { activeJob });
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
|
||||
// Act
|
||||
await InvokeAsync("ResumeActiveCyclesAsync", CancellationToken.None);
|
||||
@@ -907,7 +909,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
RegisterDateTimeProvider();
|
||||
IScheduledJobCycleTicker mockCycleTicker = Substitute.For<IScheduledJobCycleTicker>();
|
||||
@@ -931,7 +933,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity dailyJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.DailyAtHourAndMinute, hour: 10, minute: 30);
|
||||
ScheduledJobEntity runningDailyJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.DailyAtHourAndMinute, hour: 10, minute: 30);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(dailyJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(dailyJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(dailyJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningDailyJob);
|
||||
RegisterDateTimeProvider();
|
||||
IScheduledJobCycleTicker mockCycleTicker = Substitute.For<IScheduledJobCycleTicker>();
|
||||
@@ -955,7 +957,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
|
||||
RegisterDateTimeProvider();
|
||||
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
|
||||
@@ -981,7 +983,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
RegisterDateTimeProvider();
|
||||
using CancellationTokenSource cancellationTokenSource = new();
|
||||
cancellationTokenSource.Cancel();
|
||||
@@ -1000,7 +1002,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// Arrange
|
||||
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
|
||||
RegisterDateTimeProvider();
|
||||
IScheduledJobCycleTicker mockCycleTicker = Substitute.For<IScheduledJobCycleTicker>();
|
||||
mockCycleTicker.WaitForNextTickAsync(Arg.Any<CancellationToken>())
|
||||
@@ -1038,7 +1040,7 @@ public class ScheduledJobSchedulerJobTests
|
||||
// An interval schedule whose interval is not positive cannot be converted to its domain object.
|
||||
ScheduledJobEntity invalidJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 0);
|
||||
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(invalidJob.Id);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(invalidJob);
|
||||
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(invalidJob);
|
||||
|
||||
// Act
|
||||
Schedule? result = await InvokeAsync<Schedule?>("GetScheduleAsync", scheduledJobId, CancellationToken.None);
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ public class CleanScheduledJobExecutionHistoryTaskExecutorTests
|
||||
{
|
||||
_mockDateTimeProvider = Substitute.For<IDateTimeProvider>();
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
|
||||
_mockDateTimeProvider.UtcNow.Returns(_fixedUtcNow);
|
||||
_mockUnitOfWork.ScheduledJobExecutionRepository.Returns(_mockScheduledJobExecutionRepository);
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class MediaLibraryScanTaskExecutorTests
|
||||
_mockLibraryRepository.GetAllEnabledAndUnlockedAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IEnumerable<LibraryEntity>>([]));
|
||||
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockDomainEventPublisher = Substitute.For<IDomainEventPublisher>();
|
||||
_sut = new MediaLibraryScanTaskExecutor(_mockDomainEventPublisher, Substitute.For<ILogger<MediaLibraryScanTaskExecutor>>(), _mockUnitOfWork);
|
||||
}
|
||||
|
||||
+11
-9
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Lumina.Application.Common.Infrastructure.Themes;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -42,7 +44,7 @@ public class RepairThemesTaskExecutorTests
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
ILogger<RepairThemesTaskExecutor> logger = Substitute.For<ILogger<RepairThemesTaskExecutor>>();
|
||||
_sut = new RepairThemesTaskExecutor(_mockThemeService, logger, _mockUnitOfWork);
|
||||
}
|
||||
@@ -53,14 +55,14 @@ public class RepairThemesTaskExecutorTests
|
||||
// Arrange
|
||||
ScheduledJob scheduledJob = _scheduledJobFixture.Create(taskType: ScheduledTaskType.RepairThemes);
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([]);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.ExecutePayloadAsync(scheduledJob, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockThemeRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockThemeRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -72,14 +74,14 @@ public class RepairThemesTaskExecutorTests
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["missing.zip"]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Theme.Manifest", "Failed to read the theme manifest"));
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.ExecutePayloadAsync(scheduledJob, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockThemeRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
|
||||
await _mockThemeRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -88,8 +90,8 @@ public class RepairThemesTaskExecutorTests
|
||||
{
|
||||
// Arrange
|
||||
ScheduledJob scheduledJob = _scheduledJobFixture.Create(taskType: ScheduledTaskType.RepairThemes);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<IEnumerable<ThemeEntity>>>(new InvalidOperationException("The database is unavailable.")));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<PaginatedResultDto<ThemeEntity>>>(new InvalidOperationException("The database is unavailable.")));
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.ExecutePayloadAsync(scheduledJob, CancellationToken.None);
|
||||
@@ -104,8 +106,8 @@ public class RepairThemesTaskExecutorTests
|
||||
{
|
||||
// Arrange
|
||||
ScheduledJob scheduledJob = _scheduledJobFixture.Create(taskType: ScheduledTaskType.RepairThemes);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<IEnumerable<ThemeEntity>>>(new OperationCanceledException()));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<PaginatedResultDto<ThemeEntity>>>(new OperationCanceledException()));
|
||||
|
||||
// Act
|
||||
async Task Act()
|
||||
|
||||
+18
-16
@@ -2,6 +2,8 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Lumina.Application.Common.Infrastructure.Themes;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
|
||||
@@ -46,12 +48,12 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockThemeRepository = Substitute.For<IThemeRepository>();
|
||||
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockLogger = Substitute.For<ILogger>();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([]);
|
||||
_mockThemeService.HasThemePack(Arg.Any<string>()).Returns(true);
|
||||
_mockThemeService.DefaultThemeId.Returns("lumina-default");
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
|
||||
_mockThemeRepository.InsertAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockThemeRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(Result.Deleted);
|
||||
@@ -63,7 +65,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
public async Task SynchronizeAsync_WhenTheInstalledThemesCannotBeRead_ShouldLogAndReturn()
|
||||
{
|
||||
// Arrange
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Themes.NotFound", "Failed to read the installed themes"));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
|
||||
@@ -97,7 +99,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
ThemeEntity installedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { installedTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [installedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync("bundled.zip", Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
|
||||
@@ -115,7 +117,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
ThemeEntity deletedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { deletedTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [deletedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync("bundled.zip", Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
|
||||
@@ -133,7 +135,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
ThemeEntity damagedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { damagedTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [damagedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
// The first pack check happens before the repair and reports the files as missing; the later checks report the files as present.
|
||||
@@ -155,7 +157,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
ThemeEntity damagedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { damagedTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [damagedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
_mockThemeService.HasThemePack(damagedTheme.ThemeId).Returns(false, true);
|
||||
@@ -254,7 +256,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity healthyTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { healthyTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [healthyTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
|
||||
// Act
|
||||
await ThemeSynchronizer.SynchronizeAsync(_mockThemeService, _mockUnitOfWork, _mockLogger, CancellationToken.None);
|
||||
@@ -269,7 +271,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(brokenTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenTheme.ThemeId, Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
@@ -287,7 +289,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity lastBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { lastBundledTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [lastBundledTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(lastBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(lastBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
|
||||
@@ -306,7 +308,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenBundledTheme, healthyBundledTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenBundledTheme, healthyBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
|
||||
@@ -326,7 +328,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenBundledTheme, healthyBundledTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenBundledTheme, healthyBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
|
||||
@@ -346,7 +348,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenUserTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenUserTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenUserTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(brokenUserTheme.ThemeId).Returns(false);
|
||||
|
||||
// Act
|
||||
@@ -361,7 +363,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenUserTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenUserTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenUserTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(brokenUserTheme.ThemeId).Returns(false);
|
||||
_mockThemeRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Themes.DeleteFailed", "Failed to delete the theme"));
|
||||
@@ -380,7 +382,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeEntity throwingBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { throwingBundledTheme, healthyBundledTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [throwingBundledTheme, healthyBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(Arg.Any<string>()).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(throwingBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<Success>>(new InvalidOperationException("Unexpected failure")));
|
||||
@@ -401,7 +403,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenBundledTheme });
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenBundledTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
|
||||
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<Success>>(new OperationCanceledException()));
|
||||
|
||||
Reference in new issue
Block a user