mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07:11:10 +00:00
Centralizes and standardizes test fixtures.
This commit is contained in:
1 parent
dfc513da4f
commit
b648e2f054
294 files changed
+3807
-4437
No files matched your search
-74
@@ -1,74 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UserEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid user entity.
|
||||
/// </summary>
|
||||
/// <param name="libraryCount">Number of libraries to generate. Default is 0.</param>
|
||||
/// <returns>The created user entity.</returns>
|
||||
public static UserEntity CreateUserEntity(int libraryCount = 0)
|
||||
{
|
||||
Guid userId = Guid.NewGuid();
|
||||
List<LibraryEntity> libraries = [.. new Faker<LibraryEntity>()
|
||||
.CustomInstantiator(f => new LibraryEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
Title = f.Commerce.ProductName(),
|
||||
LibraryType = f.PickRandom<LibraryType>(),
|
||||
ContentLocations = [],
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = userId,
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
})
|
||||
.Generate(libraryCount)];
|
||||
|
||||
return new Faker<UserEntity>()
|
||||
.CustomInstantiator(f => new UserEntity
|
||||
{
|
||||
Id = userId,
|
||||
Username = default!,
|
||||
Password = default!,
|
||||
CreatedOnUtc = default,
|
||||
TotpSecret = default,
|
||||
Libraries = libraries,
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = userId
|
||||
})
|
||||
.RuleFor(x => x.Username, f => f.Internet.UserName())
|
||||
.RuleFor(x => x.Password, f => Uri.EscapeDataString(f.Internet.Password()))
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32) : null)
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of user entities.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of entities to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public static List<UserEntity> CreateMany(int count = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count)
|
||||
.Select(_ => CreateUserEntity())
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -3,7 +3,7 @@ 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.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Users;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,11 +19,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserEntityMappingTests
|
||||
{
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidUserEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity();
|
||||
UserEntity entity = _userEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
@@ -44,7 +46,7 @@ public class UserEntityMappingTests
|
||||
public void ToResponse_WhenMappingDifferentUsernames_ShouldMapCorrectly(string username)
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity();
|
||||
UserEntity entity = _userEntityFixture.Create();
|
||||
entity.Username = username;
|
||||
|
||||
// Act
|
||||
@@ -59,7 +61,7 @@ public class UserEntityMappingTests
|
||||
public void ToResponse_WhenMappingWithUpdatedDateTime_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity();
|
||||
UserEntity entity = _userEntityFixture.Create();
|
||||
entity.UpdatedOnUtc = DateTime.UtcNow.AddDays(-1);
|
||||
|
||||
// Act
|
||||
@@ -74,7 +76,7 @@ public class UserEntityMappingTests
|
||||
public void ToResponse_WhenMappingWithLibraries_ShouldNotAffectMapping()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity(2);
|
||||
UserEntity entity = _userEntityFixture.Create(2);
|
||||
|
||||
// Act
|
||||
UserResponse result = entity.ToResponse();
|
||||
@@ -91,7 +93,7 @@ public class UserEntityMappingTests
|
||||
public void ToResponses_WhenMappingMultipleEntities_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<UserEntity> entities = UserEntityFixture.CreateMany(3);
|
||||
List<UserEntity> entities = _userEntityFixture.CreateMany(3);
|
||||
|
||||
// Act
|
||||
IEnumerable<UserResponse> results = entities.ToResponses();
|
||||
@@ -127,7 +129,7 @@ public class UserEntityMappingTests
|
||||
public void ToResponse_WhenMappingWithoutUpdatedDateTime_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity entity = UserEntityFixture.CreateUserEntity();
|
||||
UserEntity entity = _userEntityFixture.Create();
|
||||
entity.UpdatedOnUtc = null;
|
||||
|
||||
// Act
|
||||
|
||||
Reference in new issue
Block a user