mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 03:11:10 +00:00
Merge branch 'refactor/standardize-test-fixtures-and-docs' into feature/add-artwork-provider-and-metadata-aggregation
This commit is contained in:
commit
4ff184d8a5
388 files changed
+13829
-2814
No files matched your search
+23
-103
@@ -26,6 +26,8 @@ public class RoleRepositoryTests
|
||||
{
|
||||
private readonly LuminaDbContext _mockContext;
|
||||
private readonly RoleRepository _sut;
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RoleRepositoryTests"/> class.
|
||||
@@ -40,13 +42,7 @@ public class RoleRepositoryTests
|
||||
public async Task InsertAsync_WhenRoleDoesNotExist_ShouldAddRoleToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity role = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(role, CancellationToken.None);
|
||||
@@ -65,24 +61,12 @@ public class RoleRepositoryTests
|
||||
public async Task InsertAsync_WhenRoleWithSameIdExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RoleEntity newRole = new()
|
||||
{
|
||||
Id = existingRole.Id,
|
||||
RoleName = "SuperAdmin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity newRole = _roleEntityFixture.Create(id: existingRole.Id, roleName: "SuperAdmin");
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
@@ -97,24 +81,12 @@ public class RoleRepositoryTests
|
||||
public async Task InsertAsync_WhenRoleWithSameNameExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RoleEntity newRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity newRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(newRole, CancellationToken.None);
|
||||
@@ -131,20 +103,8 @@ public class RoleRepositoryTests
|
||||
// Arrange
|
||||
List<RoleEntity> roles =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "User",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
}
|
||||
_roleEntityFixture.Create(roleName: "Admin"),
|
||||
_roleEntityFixture.Create(roleName: "User")
|
||||
];
|
||||
|
||||
_mockContext.Roles.AddRange(roles);
|
||||
@@ -176,13 +136,7 @@ public class RoleRepositoryTests
|
||||
public async Task GetByNameAsync_WhenRoleExists_ShouldReturnRoleWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity role = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(role);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -211,8 +165,7 @@ public class RoleRepositoryTests
|
||||
public async Task GetByIdAsync_WhenRoleExists_ShouldReturnRoleWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RolePermissionEntity rolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity role = rolePermission.Role;
|
||||
|
||||
_mockContext.Roles.Add(role);
|
||||
@@ -248,26 +201,14 @@ public class RoleRepositoryTests
|
||||
public async Task UpdateAsync_WhenRoleExists_ShouldUpdateRoleAndReturnUpdated()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RoleEntity updatedRole = new()
|
||||
{
|
||||
Id = existingRole.Id,
|
||||
RoleName = "SuperAdmin",
|
||||
CreatedOnUtc = existingRole.CreatedOnUtc,
|
||||
CreatedBy = existingRole.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity updatedRole = _roleEntityFixture.Create(id: existingRole.Id, roleName: "SuperAdmin", createdBy: existingRole.CreatedBy, createdOnUtc: existingRole.CreatedOnUtc);
|
||||
updatedRole.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedRole.UpdatedBy = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
@@ -286,13 +227,7 @@ public class RoleRepositoryTests
|
||||
public async Task UpdateAsync_WhenRoleDoesNotExist_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity nonExistentRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity nonExistentRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(nonExistentRole, CancellationToken.None);
|
||||
@@ -306,25 +241,17 @@ public class RoleRepositoryTests
|
||||
public async Task UpdateAsync_WhenRoleHasPermissions_ShouldUpdatePermissionsAndReturnUpdated()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RolePermissionEntity rolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity existingRole = rolePermission.Role;
|
||||
existingRole.RolePermissions = [rolePermission];
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RolePermissionEntity newRolePermission = rolePermissionFixture.Create();
|
||||
RoleEntity updatedRole = new()
|
||||
{
|
||||
Id = existingRole.Id,
|
||||
RoleName = existingRole.RoleName,
|
||||
RolePermissions = [newRolePermission],
|
||||
CreatedOnUtc = existingRole.CreatedOnUtc,
|
||||
CreatedBy = existingRole.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = Guid.NewGuid()
|
||||
};
|
||||
RolePermissionEntity newRolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity updatedRole = _roleEntityFixture.Create(id: existingRole.Id, roleName: existingRole.RoleName, rolePermissions: [newRolePermission], includeRolePermissions: true, createdBy: existingRole.CreatedBy, createdOnUtc: existingRole.CreatedOnUtc);
|
||||
updatedRole.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedRole.UpdatedBy = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedRole, CancellationToken.None);
|
||||
@@ -344,13 +271,7 @@ public class RoleRepositoryTests
|
||||
public async Task DeleteByIdAsync_WhenRoleExists_ShouldDeleteRoleAndReturnDeleted()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity existingRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "Admin",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity existingRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -386,8 +307,7 @@ public class RoleRepositoryTests
|
||||
public async Task DeleteByIdAsync_WhenRoleHasPermissions_ShouldDeleteRoleWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RolePermissionEntity rolePermission = _rolePermissionEntityFixture.Create();
|
||||
RoleEntity existingRole = rolePermission.Role;
|
||||
existingRole.RolePermissions = [rolePermission];
|
||||
|
||||
|
||||
+1
-7
@@ -125,13 +125,7 @@ public class DirectoryScanFingerprintRepositoryTests : IDisposable
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
DateTime newLastWriteTimeUtc = DateTime.UtcNow.AddDays(1);
|
||||
DirectoryScanFingerprintEntity updatedFingerprint = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
LibraryId = libraryId,
|
||||
Path = "/dir1",
|
||||
LastWriteTimeUtc = newLastWriteTimeUtc
|
||||
};
|
||||
DirectoryScanFingerprintEntity updatedFingerprint = _directoryScanFingerprintEntityFixture.Create(libraryId: libraryId, path: "/dir1", lastWriteTimeUtc: newLastWriteTimeUtc);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpsertRangeAsync([updatedFingerprint], CancellationToken.None);
|
||||
|
||||
+6
-12
@@ -163,18 +163,12 @@ public class LibraryRepositoryTests
|
||||
_mockContext.Libraries.Add(library);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
LibraryEntity updatedLibrary = new()
|
||||
{
|
||||
Id = library.Id,
|
||||
UserId = library.UserId,
|
||||
Title = "Updated Title",
|
||||
LibraryType = library.LibraryType,
|
||||
ContentLocations = [new LibraryContentLocationEntity { Path = "/new/path" }],
|
||||
CreatedOnUtc = library.CreatedOnUtc,
|
||||
CreatedBy = library.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = library.UserId
|
||||
};
|
||||
LibraryEntity updatedLibrary = _libraryEntityFixture.Create(
|
||||
id: library.Id,
|
||||
userId: library.UserId,
|
||||
title: "Updated Title",
|
||||
libraryType: library.LibraryType,
|
||||
contentLocations: ["/new/path"]);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedLibrary, CancellationToken.None);
|
||||
|
||||
+3
-13
@@ -149,19 +149,9 @@ public class LibraryScanRepositoryTests
|
||||
_mockContext.LibraryScans.Add(libraryScan);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
LibraryScanEntity updatedScan = new()
|
||||
{
|
||||
Id = libraryScan.Id,
|
||||
LibraryId = libraryScan.LibraryId,
|
||||
UserId = libraryScan.UserId,
|
||||
Status = LibraryScanJobStatus.Completed,
|
||||
Library = libraryScan.Library,
|
||||
User = libraryScan.User,
|
||||
CreatedOnUtc = libraryScan.CreatedOnUtc,
|
||||
CreatedBy = libraryScan.CreatedBy,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = libraryScan.UserId
|
||||
};
|
||||
LibraryScanEntity updatedScan = _libraryScanEntityFixture.Create(id: libraryScan.Id, libraryId: libraryScan.LibraryId, userId: libraryScan.UserId, status: LibraryScanJobStatus.Completed, libraryEntity: libraryScan.Library, createdOnUtc: libraryScan.CreatedOnUtc);
|
||||
updatedScan.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedScan.UpdatedBy = libraryScan.UserId;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedScan, CancellationToken.None);
|
||||
|
||||
+4
-2
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
|
||||
using Lumina.DataAccess.Core.Repositories.Libraries;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -39,6 +40,7 @@ public class LibraryScanStagingResultsRepositoryTests : IDisposable
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly LibraryScanEntityFixture _libraryScanEntityFixture = new();
|
||||
private readonly HashedFileSystemFileDtoFixture _hashedFileSystemFileDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanStagingResultsRepositoryTests"/> class.
|
||||
@@ -235,8 +237,8 @@ public class LibraryScanStagingResultsRepositoryTests : IDisposable
|
||||
|
||||
List<HashedFileSystemFileDto> hashedFiles =
|
||||
[
|
||||
new HashedFileSystemFileDto { Path = "/books/a.epub", Size = 10, Ticks = 100, CurrentHash = 999, OldHash = 0 },
|
||||
new HashedFileSystemFileDto { Path = "/books/b.epub", Size = 20, Ticks = 200, CurrentHash = 888, OldHash = 0 }
|
||||
_hashedFileSystemFileDtoFixture.Create(path: "/books/a.epub", size: 10, ticks: 100, currentHash: 999, oldHash: 0),
|
||||
_hashedFileSystemFileDtoFixture.Create(path: "/books/b.epub", size: 20, ticks: 200, currentHash: 888, oldHash: 0)
|
||||
];
|
||||
|
||||
// Act
|
||||
|
||||
+62
-174
@@ -30,6 +30,9 @@ public class UserRepositoryTests
|
||||
private readonly UserRepository _sut;
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly UserRoleEntityFixture _userRoleEntityFixture = new();
|
||||
private readonly UserPermissionEntityFixture _userPermissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserRepositoryTests"/> class.
|
||||
@@ -143,20 +146,11 @@ public class UserRepositoryTests
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
// Create updated user with same Id but different properties
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username, // Keep username as it's used for lookup
|
||||
Password = "NewPassword123",
|
||||
TempPassword = "TempPass456",
|
||||
TotpSecret = "NewSecret",
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedBy = existingUser.Id,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: "NewPassword123");
|
||||
updatedUser.TempPassword = "TempPass456";
|
||||
updatedUser.TotpSecret = "NewSecret";
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -235,30 +229,13 @@ public class UserRepositoryTests
|
||||
_mockContext.Permissions.Add(newPermission);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = "NewPassword",
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = existingUser.Id,
|
||||
User = existingUser,
|
||||
PermissionId = newPermission.Id,
|
||||
Permission = newPermission,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = existingUser.Id
|
||||
}
|
||||
],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow
|
||||
};
|
||||
UserPermissionEntity newUserPermission = _userPermissionEntityFixture.Create(existingUser, newPermission);
|
||||
newUserPermission.CreatedOnUtc = DateTime.UtcNow;
|
||||
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: "NewPassword", userPermissions: [newUserPermission], includeUserPermissions: true);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -280,50 +257,24 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenUserHasExistingPermissions_ShouldRemoveOldPermissionsAndAddNew()
|
||||
{
|
||||
// Arrange
|
||||
UserEntityFixture userFixture = new();
|
||||
PermissionEntityFixture permissionFixture = new();
|
||||
UserPermissionEntityFixture userPermissionFixture = new();
|
||||
UserEntity existingUser = _userEntityFixture.Create();
|
||||
PermissionEntity oldPermission = _permissionEntityFixture.Create();
|
||||
PermissionEntity newPermission = _permissionEntityFixture.Create();
|
||||
|
||||
UserEntity existingUser = userFixture.Create();
|
||||
PermissionEntity oldPermission = permissionFixture.Create();
|
||||
PermissionEntity newPermission = permissionFixture.Create();
|
||||
|
||||
UserEntity userWithPermissions = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = existingUser.Libraries,
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
userPermissionFixture.Create(existingUser, oldPermission)
|
||||
],
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
UpdatedOnUtc = existingUser.UpdatedOnUtc,
|
||||
UpdatedBy = existingUser.UpdatedBy
|
||||
};
|
||||
UserEntity userWithPermissions = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userPermissions: [_userPermissionEntityFixture.Create(existingUser, oldPermission)], includeUserPermissions: true);
|
||||
userWithPermissions.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
userWithPermissions.CreatedBy = existingUser.CreatedBy;
|
||||
userWithPermissions.UpdatedOnUtc = existingUser.UpdatedOnUtc;
|
||||
userWithPermissions.UpdatedBy = existingUser.UpdatedBy;
|
||||
|
||||
_mockContext.Users.Add(userWithPermissions);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = existingUser.Libraries,
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
userPermissionFixture.Create(existingUser, newPermission)
|
||||
],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = existingUser.Id
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userPermissions: [_userPermissionEntityFixture.Create(existingUser, newPermission)], includeUserPermissions: true);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedUser.UpdatedBy = existingUser.Id;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -349,84 +300,40 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenUserRoleChanges_ShouldRemoveOldRoleAndAddNew()
|
||||
{
|
||||
// Arrange
|
||||
RoleEntity oldRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "OldRole",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity oldRole = _roleEntityFixture.Create(roleName: "OldRole");
|
||||
oldRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
oldRole.CreatedBy = Guid.NewGuid();
|
||||
|
||||
RoleEntity newRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleName = "NewRole",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
RoleEntity newRole = _roleEntityFixture.Create(roleName: "NewRole");
|
||||
newRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
newRole.CreatedBy = Guid.NewGuid();
|
||||
|
||||
UserEntity existingUser = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "TestUser",
|
||||
Password = "TestPass",
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
UserEntity existingUser = _userEntityFixture.Create(username: "TestUser", password: "TestPass");
|
||||
existingUser.CreatedOnUtc = DateTime.UtcNow;
|
||||
existingUser.CreatedBy = Guid.NewGuid();
|
||||
|
||||
UserRoleEntity oldUserRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = existingUser.Id,
|
||||
User = existingUser,
|
||||
RoleId = oldRole.Id,
|
||||
Role = oldRole,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
UserRoleEntity oldUserRole = _userRoleEntityFixture.Create(userId: existingUser.Id, user: existingUser, roleId: oldRole.Id, role: oldRole);
|
||||
oldUserRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
oldUserRole.CreatedBy = Guid.NewGuid();
|
||||
|
||||
existingUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = [],
|
||||
UserRole = oldUserRole,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
CreatedBy = existingUser.CreatedBy
|
||||
};
|
||||
DateTime originalCreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
Guid originalCreatedBy = existingUser.CreatedBy;
|
||||
existingUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userRole: oldUserRole, includeUserRole: true);
|
||||
existingUser.CreatedOnUtc = originalCreatedOnUtc;
|
||||
existingUser.CreatedBy = originalCreatedBy;
|
||||
|
||||
_mockContext.Users.Add(existingUser);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserRoleEntity newUserRole = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = existingUser.Id,
|
||||
User = existingUser,
|
||||
RoleId = newRole.Id,
|
||||
Role = newRole,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = existingUser.Id
|
||||
};
|
||||
UserRoleEntity newUserRole = _userRoleEntityFixture.Create(userId: existingUser.Id, user: existingUser, roleId: newRole.Id, role: newRole);
|
||||
newUserRole.CreatedOnUtc = DateTime.UtcNow;
|
||||
newUserRole.CreatedBy = existingUser.Id;
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = [],
|
||||
UserRole = newUserRole,
|
||||
UserPermissions = [],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = existingUser.Id
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password, userRole: newUserRole, includeUserRole: true);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedUser.UpdatedBy = existingUser.Id;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
@@ -454,39 +361,20 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenRemovingUserRole_ShouldRemoveRoleAndNotAddNew()
|
||||
{
|
||||
// Arrange
|
||||
UserEntityFixture userFixture = new();
|
||||
UserRoleEntityFixture userRoleFixture = new();
|
||||
UserRoleEntity oldUserRole = _userRoleEntityFixture.Create();
|
||||
|
||||
UserRoleEntity oldUserRole = userRoleFixture.Create();
|
||||
|
||||
UserEntity existingUser = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "TestUser",
|
||||
Password = "TestPass",
|
||||
Libraries = [],
|
||||
UserRole = oldUserRole,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid()
|
||||
};
|
||||
UserEntity existingUser = _userEntityFixture.Create(username: "TestUser", password: "TestPass", userRole: oldUserRole, includeUserRole: true);
|
||||
existingUser.CreatedOnUtc = DateTime.UtcNow;
|
||||
existingUser.CreatedBy = Guid.NewGuid();
|
||||
|
||||
_mockContext.Users.Add(existingUser);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
UserEntity updatedUser = new()
|
||||
{
|
||||
Id = existingUser.Id,
|
||||
Username = existingUser.Username,
|
||||
Password = existingUser.Password,
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
UpdatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = existingUser.Id
|
||||
};
|
||||
UserEntity updatedUser = _userEntityFixture.Create(id: existingUser.Id, username: existingUser.Username, password: existingUser.Password);
|
||||
updatedUser.CreatedBy = existingUser.CreatedBy;
|
||||
updatedUser.CreatedOnUtc = existingUser.CreatedOnUtc;
|
||||
updatedUser.UpdatedOnUtc = DateTime.UtcNow;
|
||||
updatedUser.UpdatedBy = existingUser.Id;
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedUser, CancellationToken.None);
|
||||
|
||||
+3
-3
@@ -119,7 +119,7 @@ public class UserSettingsRepositoryTests
|
||||
Assert.Equal(settings.UserId, result.Value.UserId);
|
||||
Assert.Equal(settings.IsPaginationEnabled, result.Value.IsPaginationEnabled);
|
||||
Assert.Equal(settings.ItemsPerPage, result.Value.ItemsPerPage);
|
||||
Assert.Equal(settings.IgnoreThePrefixForAlphaPicker, result.Value.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.Equal(settings.ShouldIgnoreThePrefixForAlphaPicker, result.Value.ShouldIgnoreThePrefixForAlphaPicker);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -146,7 +146,7 @@ public class UserSettingsRepositoryTests
|
||||
userId: existingSettings.UserId,
|
||||
isPaginationEnabled: false,
|
||||
itemsPerPage: 12,
|
||||
ignoreThePrefixForAlphaPicker: true);
|
||||
shouldIgnoreThePrefixForAlphaPicker: true);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(updatedSettings, CancellationToken.None);
|
||||
@@ -160,7 +160,7 @@ public class UserSettingsRepositoryTests
|
||||
Assert.Equal(existingSettings.UserId, modifiedSettings.UserId);
|
||||
Assert.False(modifiedSettings.IsPaginationEnabled);
|
||||
Assert.Equal(12, modifiedSettings.ItemsPerPage);
|
||||
Assert.True(modifiedSettings.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.True(modifiedSettings.ShouldIgnoreThePrefixForAlphaPicker);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -6,6 +6,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.DataAccess.Core.Seed;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -31,6 +32,9 @@ public class DataSeedServiceTests
|
||||
private readonly IPermissionRepository _mockPermissionRepository;
|
||||
private readonly DataSeedService _sut;
|
||||
private readonly DateTime _fixedUtcNow;
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DataSeedServiceTests"/> class.
|
||||
@@ -226,12 +230,12 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
List<PermissionEntity> permissions =
|
||||
[
|
||||
new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanViewUsers },
|
||||
new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanDeleteUsers },
|
||||
new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanRegisterUsers }
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers),
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers),
|
||||
_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanRegisterUsers)
|
||||
];
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -291,7 +295,7 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
Error expectedError = Error.Failure("Permissions.NotFound", "Failed to retrieve permissions");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -318,8 +322,8 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
List<PermissionEntity> permissions = [new() { Id = Guid.NewGuid(), PermissionName = AuthorizationPermission.CanViewUsers }];
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
List<PermissionEntity> permissions = [_permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)];
|
||||
Error expectedError = Error.Failure("RolePermission.InsertFailed", "Failed to insert role permission");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
@@ -373,9 +377,8 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
UserEntityFixture userFixture = new();
|
||||
UserEntity adminUser = userFixture.Create();
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
UserEntity adminUser = _userEntityFixture.Create();
|
||||
// Use the adminUser.Id instead of the randomly generated userId
|
||||
userId = adminUser.Id;
|
||||
|
||||
@@ -437,7 +440,7 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
IUserRepository mockUserRepository = Substitute.For<IUserRepository>();
|
||||
@@ -463,8 +466,8 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
UserEntity adminUser = new UserEntityFixture().Create();
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
UserEntity adminUser = _userEntityFixture.Create();
|
||||
|
||||
Error expectedError = Error.Failure("UserRole.InsertFailed", "Failed to insert user role");
|
||||
|
||||
@@ -519,7 +522,7 @@ public class DataSeedServiceTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
Error expectedError = Error.Failure("User.NotFound", "Failed to retrieve user");
|
||||
|
||||
IRoleRepository mockRoleRepository = Substitute.For<IRoleRepository>();
|
||||
|
||||
Reference in new issue
Block a user