mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Moves repository entities to Application layer for joint access
This commit is contained in:
1 parent
baf9854355
commit
7321fb89e2
120 files changed
+2606
-784
No files matched your search
+141
@@ -0,0 +1,141 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.UsersManagement.Users;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UserEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserEntityMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidUserEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "testuser",
|
||||
Password = "hashedpassword",
|
||||
Libraries = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(entity.Id);
|
||||
result.Username.Should().Be(entity.Username);
|
||||
result.Created.Should().Be(entity.Created);
|
||||
result.Updated.Should().Be(entity.Updated);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1")]
|
||||
[InlineData("test.user")]
|
||||
[InlineData("john_doe")]
|
||||
[InlineData("jane.doe@example.com")]
|
||||
public void ToResponse_WhenMappingDifferentUsernames_ShouldMapCorrectly(string username)
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = username,
|
||||
Password = "hashedpassword",
|
||||
Libraries = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(username);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingWithUpdatedDateTime_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DateTime updated = DateTime.UtcNow.AddDays(-1);
|
||||
UserEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "testuser",
|
||||
Password = "hashedpassword",
|
||||
Libraries = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = updated
|
||||
};
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Updated.Should().Be(updated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingWithLibraries_ShouldNotAffectMapping()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "testuser",
|
||||
Password = "hashedpassword",
|
||||
Libraries =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 1",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 2",
|
||||
LibraryType = LibraryType.Movie,
|
||||
ContentLocations = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
}
|
||||
],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Should().Be(entity.Id);
|
||||
result.Username.Should().Be(entity.Username);
|
||||
result.Created.Should().Be(entity.Created);
|
||||
result.Updated.Should().Be(entity.Updated);
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Mapping.Common.Metadata;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UserMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingValidUser_ShouldOnlyUpdateUsername()
|
||||
{
|
||||
// Arrange
|
||||
User domainEntity = User.Create(
|
||||
UserId.Create(Guid.NewGuid()),
|
||||
"newusername"
|
||||
).Value;
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
TotpSecret = "totpsecret",
|
||||
VerificationToken = "verificationtoken",
|
||||
VerificationTokenCreated = DateTime.UtcNow,
|
||||
Libraries = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().BeSameAs(repositoryEntity); // Should modify the same instance
|
||||
result.Username.Should().Be(domainEntity.Username); // Only username should be updated
|
||||
|
||||
// Verify other properties remain unchanged
|
||||
result.Id.Should().Be(repositoryEntity.Id);
|
||||
result.Password.Should().Be(repositoryEntity.Password);
|
||||
result.TotpSecret.Should().Be(repositoryEntity.TotpSecret);
|
||||
result.VerificationToken.Should().Be(repositoryEntity.VerificationToken);
|
||||
result.VerificationTokenCreated.Should().Be(repositoryEntity.VerificationTokenCreated);
|
||||
result.Libraries.Should().BeSameAs(repositoryEntity.Libraries);
|
||||
result.Created.Should().Be(repositoryEntity.Created);
|
||||
result.Updated.Should().Be(repositoryEntity.Updated);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("user1")]
|
||||
[InlineData("test.user")]
|
||||
[InlineData("john_doe")]
|
||||
[InlineData("jane.doe@example.com")]
|
||||
public void ToRepositoryEntity_WhenMappingDifferentUsernames_ShouldUpdateCorrectly(string newUsername)
|
||||
{
|
||||
// Arrange
|
||||
User domainEntity = User.Create(
|
||||
UserId.Create(Guid.NewGuid()),
|
||||
newUsername
|
||||
).Value;
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
Libraries = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Username.Should().Be(newUsername);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenRepositoryEntityHasLibraries_ShouldPreserveLibraries()
|
||||
{
|
||||
// Arrange
|
||||
User domainEntity = User.Create(
|
||||
UserId.Create(Guid.NewGuid()),
|
||||
"newusername"
|
||||
).Value;
|
||||
|
||||
List<LibraryEntity> libraries =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 1",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "Library 2",
|
||||
LibraryType = LibraryType.Movie,
|
||||
ContentLocations = [],
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
}
|
||||
];
|
||||
|
||||
UserEntity repositoryEntity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Username = "oldusername",
|
||||
Password = "hashedpassword",
|
||||
Libraries = libraries,
|
||||
Created = DateTime.UtcNow,
|
||||
Updated = null
|
||||
};
|
||||
|
||||
// Act
|
||||
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Libraries.Should().BeSameAs(libraries);
|
||||
result.Libraries.Should().HaveCount(2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user