mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Centralizes audit column ownership in the auditing interceptor
Removes explicit audit assignments from mappings, handlers, repositories, seeding, and background jobs, leaving the auditing interceptor as the only writer of the audit columns for ordinary saves. Adds a one-time initialization save so setup can attribute the original admin account and seeded rows to the SYSTEM audit identity, while ordinary anonymous writes remain unattributed with Guid.Empty.
This commit is contained in:
1 parent
b56fabf5df
commit
7253f1507c
98 files changed
+731
-516
No files matched your search
+86
-51
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Scheduling;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
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.DTO.Filtering;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
@@ -49,6 +49,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
private readonly IDomainEventsQueue _mockDomainEventsQueue;
|
||||
private readonly IValidator<SetupApplicationCommand> _mockValidator;
|
||||
private readonly SetupApplicationCommandHandler _sut;
|
||||
private readonly DateTime _fixedUtcNow;
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly ScheduledJobEntityFixture _scheduledJobEntityFixture = new();
|
||||
private readonly SetupApplicationCommandFixture _setupApplicationCommandFixture = new();
|
||||
@@ -61,7 +62,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
public SetupApplicationCommandHandlerTests()
|
||||
{
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockUnitOfWork.SaveChangesAsInitializationAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
_mockHashService = Substitute.For<IPasswordHashService>();
|
||||
_mockCryptographyService = Substitute.For<ICryptographyService>();
|
||||
_mockTotpTokenGenerator = Substitute.For<ITotpTokenGenerator>();
|
||||
@@ -70,6 +71,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
_mockScheduledJobRepository = Substitute.For<IScheduledJobRepository>();
|
||||
_mockDateTimeProvider = Substitute.For<IDateTimeProvider>();
|
||||
_mockDataSeedService = Substitute.For<IDataSeedService>();
|
||||
_fixedUtcNow = new DateTime(2026, 1, 15, 10, 30, 0, DateTimeKind.Utc);
|
||||
_mockDomainEventsQueue = Substitute.For<IDomainEventsQueue>();
|
||||
_mockValidator = Substitute.For<IValidator<SetupApplicationCommand>>();
|
||||
_mockValidator.Validate(Arg.Any<SetupApplicationCommand>())
|
||||
@@ -77,7 +79,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
|
||||
_mockUnitOfWork.UserRepository.Returns(_mockUserRepository);
|
||||
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
|
||||
_mockDateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
|
||||
_mockDateTimeProvider.UtcNow.Returns(_fixedUtcNow);
|
||||
_mockDataSeedService.SetDefaultScheduledJobsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockScheduledJobRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
@@ -101,18 +103,20 @@ public class SetupApplicationCommandHandlerTests
|
||||
// Arrange
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create() with { Use2fa = false };
|
||||
string hashedPassword = Uri.EscapeDataString("hashedPassword");
|
||||
UserEntity? insertedUser = null;
|
||||
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 0, count: 0, numberOfPages: 1)));
|
||||
_mockHashService.HashString(command.Password!)
|
||||
.Returns(hashedPassword);
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created)
|
||||
.AndDoes(info => insertedUser = info.Arg<UserEntity>());
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
@@ -125,10 +129,41 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(command.Username, result.Value.Username);
|
||||
Assert.Null(result.Value.TotpSecret);
|
||||
Assert.NotNull(insertedUser);
|
||||
Assert.Equal(AuditIdentities.s_systemUserId, insertedUser!.CreatedBy);
|
||||
Assert.Equal(_fixedUtcNow, insertedUser.CreatedOnUtc);
|
||||
Assert.Null(insertedUser.UpdatedBy);
|
||||
Assert.Null(insertedUser.UpdatedOnUtc);
|
||||
|
||||
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>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsInitializationAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAsync_WhenSaveChangesFails_ShouldReturnErrorAndNotSeedDefaults()
|
||||
{
|
||||
// Arrange
|
||||
SetupApplicationCommand command = _setupApplicationCommandFixture.Create() with { Use2fa = false };
|
||||
Error expectedError = Error.Failure("Persistence.SaveFailed", "The changes could not be saved.");
|
||||
_mockUserRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 0, count: 0, numberOfPages: 1)));
|
||||
_mockHashService.HashString(command.Password!)
|
||||
.Returns("hashedPassword");
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockUnitOfWork.SaveChangesAsInitializationAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
Result<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(expectedError, result.FirstError);
|
||||
await _mockDataSeedService.DidNotReceive().SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -153,11 +188,11 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(encryptedSecret);
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
@@ -173,7 +208,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
|
||||
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>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsInitializationAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -195,7 +230,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
|
||||
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>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsInitializationAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -217,7 +252,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
|
||||
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>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsInitializationAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -241,7 +276,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
|
||||
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>());
|
||||
await _mockUnitOfWork.DidNotReceive().SaveChangesAsInitializationAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -255,7 +290,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(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>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -265,8 +300,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -280,9 +315,9 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(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>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -292,9 +327,9 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -308,11 +343,11 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(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>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
@@ -322,9 +357,9 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
@@ -339,11 +374,11 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(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>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(error);
|
||||
@@ -355,9 +390,9 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(error, result.FirstError);
|
||||
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.DidNotReceive().SetDefaultScheduledJobsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -373,11 +408,11 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(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>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
@@ -405,11 +440,11 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(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>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
@@ -422,9 +457,9 @@ public class SetupApplicationCommandHandlerTests
|
||||
Assert.NotNull(result.Value);
|
||||
Assert.Equal(command.Username, result.Value.Username);
|
||||
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockDataSeedService.Received(1).SetDefaultScheduledJobsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -442,11 +477,11 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.From(_paginatedResultDtoFixture.Create(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>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
@@ -492,11 +527,11 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns("hashedPassword");
|
||||
_mockUserRepository.InsertAsync(Arg.Any<UserEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationPermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetDefaultAuthorizationRolesAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
_mockDataSeedService.SetAdminRolePermissionsAsync(Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
_mockDataSeedService.SetAdminRoleToAdministratorAccount(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.Created);
|
||||
|
||||
-1
@@ -529,7 +529,6 @@ public class ReportConsumptionProgressCommandHandlerTests
|
||||
await _mockMediaResumePointRepository.Received(1).UpsertForUserAsync(
|
||||
Arg.Is<MediaResumePointEntity>(resumePoint =>
|
||||
resumePoint.Id == existingResumePoint.Id &&
|
||||
resumePoint.CreatedOnUtc == existingResumePoint.CreatedOnUtc &&
|
||||
resumePoint.LastPositionTimeOffsetMilliseconds == 600_000 &&
|
||||
resumePoint.LastProgressFraction == 0.4),
|
||||
_userId,
|
||||
|
||||
-1
@@ -145,7 +145,6 @@ public class UpdateBookCoverCommandHandlerTests
|
||||
Assert.Single(existingBook.Artwork);
|
||||
Assert.Equal(result.Value.CoverPath, existingCover.FileName);
|
||||
Assert.Equal(ArtworkStatus.Enriched, existingCover.Status);
|
||||
Assert.Equal(_userId, existingCover.UpdatedBy);
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@ public class DeleteThemeCommandHandlerTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockThemeRepository.Received(1).UpdateAsync(
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && entity.IsDeleted && entity.IsCurrent == null && entity.UpdatedBy == _userId),
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && entity.IsDeleted && entity.IsCurrent == null),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockThemeRepository.DidNotReceive().DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
|
||||
+2
-7
@@ -202,9 +202,7 @@ public class InstallThemeCommandHandlerTests
|
||||
theme.Version == manifest.Version &&
|
||||
theme.PreviewPath == manifest.Preview &&
|
||||
theme.InstallSource == ThemeInstallSource.Uploaded &&
|
||||
theme.IsDeleted == false &&
|
||||
theme.CreatedBy == _userId &&
|
||||
theme.UpdatedBy == _userId),
|
||||
theme.IsDeleted == false),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockThemeRepository.DidNotReceive().UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
@@ -268,10 +266,7 @@ public class InstallThemeCommandHandlerTests
|
||||
theme.Name == manifest.Name &&
|
||||
theme.InstallSource == existingTheme.InstallSource &&
|
||||
theme.IsCurrent == existingTheme.IsCurrent &&
|
||||
theme.IsDeleted == false &&
|
||||
theme.CreatedOnUtc == existingTheme.CreatedOnUtc &&
|
||||
theme.CreatedBy == existingTheme.CreatedBy &&
|
||||
theme.UpdatedBy == _userId),
|
||||
theme.IsDeleted == false),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockThemeRepository.DidNotReceive().InsertAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
|
||||
+1
-1
@@ -235,7 +235,7 @@ public class RestoreThemeCommandHandlerTests
|
||||
Assert.False(result.IsFailure);
|
||||
await _mockThemeService.Received(1).RestoreBundledThemeAsync(theme.ThemeId, Arg.Any<CancellationToken>());
|
||||
await _mockThemeRepository.Received(1).UpdateAsync(
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && !entity.IsDeleted && entity.IsCurrent == null && entity.UpdatedBy == _userId),
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && !entity.IsDeleted && entity.IsCurrent == null),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
+2
-2
@@ -238,7 +238,7 @@ public class SetCurrentThemeCommandHandlerTests
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == currentTheme.Id && entity.IsCurrent == null),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockThemeRepository.Received(1).UpdateAsync(
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && entity.IsCurrent == true && entity.UpdatedBy == _userId),
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && entity.IsCurrent == true),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
@@ -290,7 +290,7 @@ public class SetCurrentThemeCommandHandlerTests
|
||||
Assert.Equal(theme.Id, result.Value.Id);
|
||||
Assert.True(result.Value.IsCurrent);
|
||||
await _mockThemeRepository.Received(1).UpdateAsync(
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && entity.IsCurrent == true && entity.UpdatedBy == _userId),
|
||||
Arg.Is<ThemeEntity>(entity => entity.Id == theme.Id && entity.IsCurrent == true),
|
||||
Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
-5
@@ -5,7 +5,6 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
@@ -33,7 +32,6 @@ public class RegisterUserCommandHandlerTests
|
||||
private readonly ITotpTokenGenerator _mockTotpTokenGenerator;
|
||||
private readonly IQRCodeGenerator _mockQRCodeGenerator;
|
||||
private readonly IUserRepository _mockUserRepository;
|
||||
private readonly IDateTimeProvider _mockDateTimeProvider;
|
||||
private readonly RegisterUserCommandHandler _sut;
|
||||
private readonly RegisterUserCommandFixture _registerUserCommandFixture = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
@@ -50,10 +48,8 @@ public class RegisterUserCommandHandlerTests
|
||||
_mockTotpTokenGenerator = Substitute.For<ITotpTokenGenerator>();
|
||||
_mockQRCodeGenerator = Substitute.For<IQRCodeGenerator>();
|
||||
_mockUserRepository = Substitute.For<IUserRepository>();
|
||||
_mockDateTimeProvider = Substitute.For<IDateTimeProvider>();
|
||||
|
||||
_mockUnitOfWork.UserRepository.Returns(_mockUserRepository);
|
||||
_mockDateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
|
||||
|
||||
IValidator<RegisterUserCommand> mockValidator = Substitute.For<IValidator<RegisterUserCommand>>();
|
||||
mockValidator.Validate(Arg.Any<RegisterUserCommand>())
|
||||
@@ -64,7 +60,6 @@ public class RegisterUserCommandHandlerTests
|
||||
_mockCryptographyService,
|
||||
_mockTotpTokenGenerator,
|
||||
_mockQRCodeGenerator,
|
||||
_mockDateTimeProvider,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user