mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 22: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
@@ -1,38 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for the <see cref="Faker"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class BogusExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly"/> random data generation support to the <see cref="Faker"/> class.
|
||||
/// </summary>
|
||||
/// <param name="faker">The faker instance to extend.</param>
|
||||
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
|
||||
public static DateOnly DateOnly(this Faker faker)
|
||||
{
|
||||
return System.DateOnly.FromDateTime(faker.Date.Past());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly"/> random data generation within a specified interval support to the <see cref="Faker"/> class.
|
||||
/// </summary>
|
||||
/// <param name="faker">The faker instance to extend.</param>
|
||||
/// <param name="start">The start of the interval.</param>
|
||||
/// <param name="end">The end of the interval.</param>
|
||||
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
|
||||
public static DateOnly DateOnlyBetween(this Faker faker, DateOnly start, DateOnly end)
|
||||
{
|
||||
DateTime startDateTime = start.ToDateTime(TimeOnly.MinValue);
|
||||
DateTime endDateTime = end.ToDateTime(TimeOnly.MinValue);
|
||||
return System.DateOnly.FromDateTime(faker.Date.Between(startDateTime, endDateTime));
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DateOnlySpecimenBuilder : ISpecimenBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly"/> support to the AutoFixture library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to process.</param>
|
||||
/// <param name="context">The context within which the specimen is created.</param>
|
||||
/// <returns>A specimen based on the request.</returns>
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (request is Type type && type == typeof(DateOnly))
|
||||
return DateOnly.FromDateTime(DateTime.Now);
|
||||
return new NoSpecimen();
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture.Kernel;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class NullableDateOnlySpecimenBuilder : ISpecimenBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="DateOnly?"/> support to the AutoFixture library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to process.</param>
|
||||
/// <param name="context">The context within which the specimen is created.</param>
|
||||
/// <returns>A specimen based on the request.</returns>
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (request is Type type && type == typeof(DateOnly?))
|
||||
return (DateOnly?)DateOnly.FromDateTime(DateTime.Now);
|
||||
return new NoSpecimen();
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PermissionEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PermissionEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PermissionEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public PermissionEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
ConfigureCustomTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PermissionEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="PermissionEntity"/>.</returns>
|
||||
public PermissionEntity CreatePermissionModel()
|
||||
{
|
||||
return new Faker<PermissionEntity>()
|
||||
.RuleFor(x => x.Id, f => f.Random.Guid())
|
||||
.RuleFor(x => x.PermissionName, f => f.PickRandom<AuthorizationPermission>())
|
||||
.RuleFor(x => x.RolePermissions, [])
|
||||
.RuleFor(x => x.UserPermissions, [])
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.CreatedBy, f => f.Random.Guid())
|
||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
||||
.RuleFor(x => x.UpdatedBy, f => f.Random.Guid())
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures custom type generation rules for the AutoFixture instance.
|
||||
/// </summary>
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new PermissionEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
PermissionName = _fixture.Create<AuthorizationPermission>(),
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>(),
|
||||
UpdatedOnUtc = _fixture.Create<DateTime>(),
|
||||
UpdatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
}
|
||||
}
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="RolePermissionEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RolePermissionEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RolePermissionEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public RolePermissionEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_faker = new Faker();
|
||||
ConfigureCustomTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="RolePermissionEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="RolePermissionEntity"/>.</returns>
|
||||
public RolePermissionEntity CreateRolePermissionModel()
|
||||
{
|
||||
PermissionEntity permission = new()
|
||||
{
|
||||
Id = _faker.Random.Guid(),
|
||||
PermissionName = _faker.PickRandom<AuthorizationPermission>(),
|
||||
CreatedOnUtc = _faker.Date.Past(),
|
||||
CreatedBy = _faker.Random.Guid(),
|
||||
UpdatedOnUtc = _faker.Date.Recent(),
|
||||
UpdatedBy = _faker.Random.Guid()
|
||||
};
|
||||
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = _faker.Random.Guid(),
|
||||
RoleName = _faker.Random.String2(10),
|
||||
CreatedOnUtc = _faker.Date.Past(),
|
||||
CreatedBy = _faker.Random.Guid(),
|
||||
UpdatedOnUtc = _faker.Date.Recent(),
|
||||
UpdatedBy = _faker.Random.Guid()
|
||||
};
|
||||
|
||||
return new Faker<RolePermissionEntity>()
|
||||
.CustomInstantiator(f => new RolePermissionEntity
|
||||
{
|
||||
Id = f.Random.Guid(),
|
||||
RoleId = role.Id,
|
||||
Role = role,
|
||||
PermissionId = permission.Id,
|
||||
Permission = permission,
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = f.Random.Guid(),
|
||||
UpdatedOnUtc = f.Date.Recent(),
|
||||
UpdatedBy = f.Random.Guid()
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures custom type generation rules for the AutoFixture instance.
|
||||
/// </summary>
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new PermissionEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
PermissionName = _fixture.Create<AuthorizationPermission>(),
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>(),
|
||||
UpdatedOnUtc = _fixture.Create<DateTime>(),
|
||||
UpdatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
|
||||
_fixture.Register(() => new RoleEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
RoleName = _fixture.Create<string>(),
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>(),
|
||||
UpdatedOnUtc = _fixture.Create<DateTime>(),
|
||||
UpdatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
|
||||
_fixture.Register(() => new RolePermissionEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
RoleId = _fixture.Create<Guid>(),
|
||||
Role = _fixture.Create<RoleEntity>(),
|
||||
PermissionId = _fixture.Create<Guid>(),
|
||||
Permission = _fixture.Create<PermissionEntity>(),
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>(),
|
||||
UpdatedOnUtc = _fixture.Create<DateTime>(),
|
||||
UpdatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UserPermissionEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserPermissionEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserPermissionEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public UserPermissionEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_faker = new Faker();
|
||||
ConfigureCustomTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UserPermissionEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="UserPermissionEntity"/>.</returns>
|
||||
public UserPermissionEntity CreateUserPermissionModel(UserEntity user, PermissionEntity permission)
|
||||
{
|
||||
return new Faker<UserPermissionEntity>()
|
||||
.CustomInstantiator(f => new UserPermissionEntity
|
||||
{
|
||||
Id = f.Random.Guid(),
|
||||
UserId = user.Id,
|
||||
User = user,
|
||||
PermissionId = permission.Id,
|
||||
Permission = permission,
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = user.Id,
|
||||
UpdatedOnUtc = f.Random.Bool() ? f.Date.Recent() : null,
|
||||
UpdatedBy = f.Random.Bool() ? user.Id : null
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures custom type generation rules for the AutoFixture instance.
|
||||
/// </summary>
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new UserPermissionEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
UserId = _fixture.Create<Guid>(),
|
||||
User = _fixture.Create<UserEntity>(),
|
||||
PermissionId = _fixture.Create<Guid>(),
|
||||
Permission = _fixture.Create<PermissionEntity>(),
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>(),
|
||||
UpdatedOnUtc = _fixture.Create<DateTime>(),
|
||||
UpdatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
}
|
||||
}
|
||||
-91
@@ -1,91 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UserRoleEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserRoleEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserRoleEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public UserRoleEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
ConfigureCustomTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UserRoleEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="UserRoleEntity"/>.</returns>
|
||||
public UserRoleEntity CreateUserRoleModel()
|
||||
{
|
||||
return new Faker<UserRoleEntity>()
|
||||
.CustomInstantiator(f => new UserRoleEntity
|
||||
{
|
||||
Id = f.Random.Guid(),
|
||||
UserId = f.Random.Guid(),
|
||||
User = new()
|
||||
{
|
||||
Id = f.Random.Guid(),
|
||||
Username = f.Internet.UserName(),
|
||||
Password = f.Internet.Password(),
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = f.Random.Guid()
|
||||
},
|
||||
RoleId = f.Random.Guid(),
|
||||
Role = new()
|
||||
{
|
||||
Id = f.Random.Guid(),
|
||||
RoleName = f.Random.String2(f.Random.Number(1, 50)),
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = f.Random.Guid()
|
||||
},
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = f.Random.Guid()
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures custom type generation rules for the AutoFixture instance.
|
||||
/// </summary>
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new UserEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
Username = _fixture.Create<string>(),
|
||||
Password = _fixture.Create<string>(),
|
||||
Libraries = [],
|
||||
UserRole = null,
|
||||
UserPermissions = [],
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
|
||||
_fixture.Register(() => new RoleEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
RoleName = _fixture.Create<string>(),
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
}
|
||||
}
|
||||
+5
-15
@@ -2,9 +2,9 @@
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
@@ -42,7 +42,7 @@ public class PermissionRepositoryTests
|
||||
public async Task InsertAsync_WhenPermissionDoesNotExist_ShouldAddPermissionToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
PermissionEntity permissionModel = _permissionEntityFixture.CreatePermissionModel();
|
||||
PermissionEntity permissionModel = _permissionEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(permissionModel, CancellationToken.None);
|
||||
@@ -61,7 +61,7 @@ public class PermissionRepositoryTests
|
||||
public async Task InsertAsync_WhenPermissionAlreadyExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
PermissionEntity permissionModel = _permissionEntityFixture.CreatePermissionModel();
|
||||
PermissionEntity permissionModel = _permissionEntityFixture.Create();
|
||||
|
||||
_mockContext.Permissions.Add(permissionModel);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -79,12 +79,7 @@ public class PermissionRepositoryTests
|
||||
public async Task GetAllAsync_WhenPermissionsExist_ShouldReturnAllPermissions()
|
||||
{
|
||||
// Arrange
|
||||
List<PermissionEntity> permissions =
|
||||
[
|
||||
_permissionEntityFixture.CreatePermissionModel(),
|
||||
_permissionEntityFixture.CreatePermissionModel(),
|
||||
_permissionEntityFixture.CreatePermissionModel()
|
||||
];
|
||||
List<PermissionEntity> permissions = _permissionEntityFixture.CreateMany(3);
|
||||
_mockContext.Permissions.AddRange(permissions);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -114,12 +109,7 @@ public class PermissionRepositoryTests
|
||||
public async Task GetByIdsAsync_WhenPermissionsExist_ShouldReturnMatchingPermissions()
|
||||
{
|
||||
// Arrange
|
||||
List<PermissionEntity> permissions =
|
||||
[
|
||||
_permissionEntityFixture.CreatePermissionModel(),
|
||||
_permissionEntityFixture.CreatePermissionModel(),
|
||||
_permissionEntityFixture.CreatePermissionModel()
|
||||
];
|
||||
List<PermissionEntity> permissions = _permissionEntityFixture.CreateMany(3);
|
||||
_mockContext.Permissions.AddRange(permissions);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
@@ -39,7 +39,7 @@ public class RolePermissionRepositoryTests
|
||||
public async Task InsertAsync_WhenCalled_ShouldAddRolePermissionToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntity rolePermissionModel = _rolePermissionEntityFixture.CreateRolePermissionModel();
|
||||
RolePermissionEntity rolePermissionModel = _rolePermissionEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(rolePermissionModel, CancellationToken.None);
|
||||
|
||||
+5
-5
@@ -2,9 +2,9 @@
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
@@ -212,7 +212,7 @@ public class RoleRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.CreateRolePermissionModel();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RoleEntity role = rolePermission.Role;
|
||||
|
||||
_mockContext.Roles.Add(role);
|
||||
@@ -307,14 +307,14 @@ public class RoleRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.CreateRolePermissionModel();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RoleEntity existingRole = rolePermission.Role;
|
||||
existingRole.RolePermissions = [rolePermission];
|
||||
|
||||
_mockContext.Roles.Add(existingRole);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
RolePermissionEntity newRolePermission = rolePermissionFixture.CreateRolePermissionModel();
|
||||
RolePermissionEntity newRolePermission = rolePermissionFixture.Create();
|
||||
RoleEntity updatedRole = new()
|
||||
{
|
||||
Id = existingRole.Id,
|
||||
@@ -387,7 +387,7 @@ public class RoleRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionEntityFixture rolePermissionFixture = new();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.CreateRolePermissionModel();
|
||||
RolePermissionEntity rolePermission = rolePermissionFixture.Create();
|
||||
RoleEntity existingRole = rolePermission.Role;
|
||||
existingRole.RolePermissions = [rolePermission];
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.DataAccess.Core.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
@@ -39,7 +39,7 @@ public class UserRoleRepositoryTests
|
||||
public async Task InsertAsync_WhenUserRoleIsValid_ShouldAddToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
UserRoleEntity userRole = _userRoleEntityFixture.CreateUserRoleModel();
|
||||
UserRoleEntity userRole = _userRoleEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(userRole, CancellationToken.None);
|
||||
|
||||
+19
-24
@@ -2,9 +2,9 @@
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.DataAccess.Core.Repositories.Books;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
@@ -44,7 +44,7 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenBookDoesNotExist_ShouldAddBookToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookModel = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(bookModel, CancellationToken.None);
|
||||
@@ -63,7 +63,7 @@ public class BookRepositoryTests
|
||||
public async Task InsertAsync_WhenBookAlreadyExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity bookModel = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookEntityFixture.Create();
|
||||
|
||||
_mockContext.Books.Add(bookModel);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -85,7 +85,7 @@ public class BookRepositoryTests
|
||||
_mockContext.Set<TagEntity>().Add(existingTag);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
BookEntity bookModel = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookEntityFixture.Create();
|
||||
bookModel.Tags = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
@@ -112,7 +112,7 @@ public class BookRepositoryTests
|
||||
_mockContext.Set<GenreEntity>().Add(existingGenre);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
BookEntity bookModel = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity bookModel = _bookEntityFixture.Create();
|
||||
bookModel.Genres = [new("Existing"), new("New")];
|
||||
|
||||
// Act
|
||||
@@ -135,12 +135,7 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenCalled_ShouldReturnAllBooks()
|
||||
{
|
||||
// Arrange
|
||||
List<BookEntity> books =
|
||||
[
|
||||
_bookEntityFixture.CreateBookModel(),
|
||||
_bookEntityFixture.CreateBookModel(),
|
||||
_bookEntityFixture.CreateBookModel()
|
||||
];
|
||||
List<BookEntity> books = _bookEntityFixture.CreateMany(3);
|
||||
_mockContext.Books.AddRange(books);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -170,7 +165,7 @@ public class BookRepositoryTests
|
||||
public async Task GetAllAsync_WhenCalled_ShouldIncludeRelatedEntities()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity book = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity book = _bookEntityFixture.Create();
|
||||
book.Tags = [new TagEntity("Tag1"), new TagEntity("Tag2")];
|
||||
book.Genres = [new GenreEntity("Genre1"), new GenreEntity("Genre2")];
|
||||
book.ISBNs = [new IsbnEntity("1234567890", IsbnFormat.Isbn10), new IsbnEntity("1234567890123", IsbnFormat.Isbn13)];
|
||||
@@ -195,9 +190,9 @@ public class BookRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
BookEntity bookOfLibrary = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity bookOfLibrary = _bookEntityFixture.Create();
|
||||
bookOfLibrary.LibraryId = libraryId;
|
||||
BookEntity bookOfAnotherLibrary = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity bookOfAnotherLibrary = _bookEntityFixture.Create();
|
||||
bookOfAnotherLibrary.LibraryId = Guid.NewGuid();
|
||||
_mockContext.Books.AddRange(bookOfLibrary, bookOfAnotherLibrary);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -215,7 +210,7 @@ public class BookRepositoryTests
|
||||
public async Task GetByPathAsync_WhenBookExists_ShouldReturnTheBook()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity book = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity book = _bookEntityFixture.Create();
|
||||
_mockContext.Books.Add(book);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -231,7 +226,7 @@ public class BookRepositoryTests
|
||||
public async Task GetByPathAsync_WhenBookDoesNotExist_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity book = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity book = _bookEntityFixture.Create();
|
||||
_mockContext.Books.Add(book);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -248,19 +243,19 @@ public class BookRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
BookEntity pendingBook = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity pendingBook = _bookEntityFixture.Create();
|
||||
pendingBook.LibraryId = libraryId;
|
||||
pendingBook.Path = "/books/a.epub";
|
||||
pendingBook.MetadataStatus = MetadataStatus.Pending;
|
||||
BookEntity enrichedBook = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity enrichedBook = _bookEntityFixture.Create();
|
||||
enrichedBook.LibraryId = libraryId;
|
||||
enrichedBook.Path = "/books/b.epub";
|
||||
enrichedBook.MetadataStatus = MetadataStatus.Enriched;
|
||||
BookEntity failedBook = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity failedBook = _bookEntityFixture.Create();
|
||||
failedBook.LibraryId = libraryId;
|
||||
failedBook.Path = "/books/c.epub";
|
||||
failedBook.MetadataStatus = MetadataStatus.Failed;
|
||||
BookEntity bookOfAnotherLibrary = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity bookOfAnotherLibrary = _bookEntityFixture.Create();
|
||||
bookOfAnotherLibrary.LibraryId = Guid.NewGuid();
|
||||
bookOfAnotherLibrary.MetadataStatus = MetadataStatus.Pending;
|
||||
_mockContext.Books.AddRange(pendingBook, enrichedBook, failedBook, bookOfAnotherLibrary);
|
||||
@@ -281,10 +276,10 @@ public class BookRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
BookEntity firstBook = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity firstBook = _bookEntityFixture.Create();
|
||||
firstBook.LibraryId = libraryId;
|
||||
firstBook.Path = "/books/a.epub";
|
||||
BookEntity secondBook = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity secondBook = _bookEntityFixture.Create();
|
||||
secondBook.LibraryId = libraryId;
|
||||
secondBook.Path = "/books/b.epub";
|
||||
_mockContext.Books.AddRange(firstBook, secondBook);
|
||||
@@ -303,7 +298,7 @@ public class BookRepositoryTests
|
||||
public async Task UpdateAsync_WhenBookExists_ShouldUpdateItsScalarProperties()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity book = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity book = _bookEntityFixture.Create();
|
||||
_mockContext.Books.Add(book);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -323,7 +318,7 @@ public class BookRepositoryTests
|
||||
public async Task UpdateAsync_WhenBookDoesNotExist_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookEntity book = _bookEntityFixture.CreateBookModel();
|
||||
BookEntity book = _bookEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(book, CancellationToken.None);
|
||||
|
||||
-254
@@ -1,254 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public BookEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
|
||||
_faker = new Faker();
|
||||
ConfigureCustomTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="BookEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="BookEntity"/>.</returns>
|
||||
public BookEntity CreateBookModel()
|
||||
{
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
return new Faker<BookEntity>()
|
||||
.RuleFor(x => x.Id, f => f.Random.Guid())
|
||||
.RuleFor(x => x.LibraryId, f => f.Random.Guid())
|
||||
.RuleFor(x => x.Path, f => f.System.FilePath())
|
||||
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
|
||||
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
|
||||
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
|
||||
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
|
||||
.RuleFor(x => x.ReReleaseDate, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)))
|
||||
.RuleFor(x => x.ReReleaseYear, reReleaseYear)
|
||||
.RuleFor(x => x.ReleaseCountry, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.LanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.Tags, f => new HashSet<TagEntity>(CreateTags(f.Random.Number(1, 5))))
|
||||
.RuleFor(x => x.Genres, f => new HashSet<GenreEntity>(CreateGenres(f.Random.Number(1, 5))))
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300))
|
||||
.RuleFor(x => x.Format, f => f.PickRandom<BookFormat>())
|
||||
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
|
||||
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
|
||||
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
|
||||
.RuleFor(x => x.LCCN, CreateLCCN)
|
||||
.RuleFor(x => x.OCLCNumber, CreateOCLCNumber)
|
||||
.RuleFor(x => x.OpenLibraryId, CreateOpenLibraryId)
|
||||
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(x => x.GoogleBooksId, CreateGoogleBooksId)
|
||||
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
|
||||
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
|
||||
.RuleFor(x => x.ISBNs, f => CreateIsbns(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.Ratings, f => CreateBookRatings(f.Random.Number(1, 5)))
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of tag entities with random data.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of tags to create.</param>
|
||||
/// <returns>A list of randomly generated tag entities.</returns>
|
||||
private static List<TagEntity> CreateTags(int count)
|
||||
{
|
||||
return new Faker<TagEntity>()
|
||||
.CustomInstantiator(f => new TagEntity(f.Random.String2(f.Random.Number(1, 50))))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of genre entities with random data.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of genres to create.</param>
|
||||
/// <returns>A list of randomly generated genre entities.</returns>
|
||||
private static List<GenreEntity> CreateGenres(int count)
|
||||
{
|
||||
return new Faker<GenreEntity>()
|
||||
.CustomInstantiator(f => new GenreEntity(f.Random.String2(f.Random.Number(1, 50))))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid Library of Congress Control Number (LCCN).
|
||||
/// </summary>
|
||||
/// <param name="f">The Faker instance used for generating random data.</param>
|
||||
/// <returns>A properly formatted LCCN string.</returns>
|
||||
private string CreateLCCN(Faker f)
|
||||
{
|
||||
string letters = new(Enumerable.Range(0, f.Random.Number(0, 3))
|
||||
.Select(_ => f.Random.Char('a', 'z'))
|
||||
.ToArray());
|
||||
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
|
||||
return letters + digits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid OCLC (Online Computer Library Center) number.
|
||||
/// </summary>
|
||||
/// <param name="f">The Faker instance used for generating random data.</param>
|
||||
/// <returns>A properly formatted OCLC number string with valid prefix.</returns>
|
||||
private string CreateOCLCNumber(Faker f)
|
||||
{
|
||||
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
|
||||
string prefix = f.Random.ArrayElement(prefixes);
|
||||
string number = prefix switch
|
||||
{
|
||||
"ocm" => f.Random.String2(8, "0123456789"),
|
||||
"ocn" => f.Random.String2(f.Random.Number(9, 11), "0123456789"),
|
||||
"on" => f.Random.String2(10, "0123456789"),
|
||||
"(OCoLC)" => f.Random.String2(f.Random.Number(8, 10), "0123456789"),
|
||||
_ => f.Random.String2(f.Random.Number(8, 10), "0123456789")
|
||||
};
|
||||
return prefix + number;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid Open Library ID.
|
||||
/// </summary>
|
||||
/// <param name="f">The Faker instance used for generating random data.</param>
|
||||
/// <returns>A properly formatted Open Library ID string.</returns>
|
||||
private string CreateOpenLibraryId(Faker f)
|
||||
{
|
||||
int firstDigit = f.Random.Number(1, 9);
|
||||
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
|
||||
char suffix = f.Random.ArrayElement(new[] { 'A', 'M', 'W' });
|
||||
return $"OL{firstDigit}{remainingDigits}{suffix}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid Google Books ID.
|
||||
/// </summary>
|
||||
/// <param name="f">The Faker instance used for generating random data.</param>
|
||||
/// <returns>A properly formatted Google Books ID string.</returns>
|
||||
private string CreateGoogleBooksId(Faker f)
|
||||
{
|
||||
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
return new string(Enumerable.Repeat(VALID_CHARS, 12)
|
||||
.Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of ISBN entities with random data.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of ISBNs to create.</param>
|
||||
/// <returns>A list of randomly generated ISBN entities.</returns>
|
||||
private static List<IsbnEntity> CreateIsbns(int count)
|
||||
{
|
||||
return new Faker<IsbnEntity>()
|
||||
.CustomInstantiator(f => new IsbnEntity(CreateIsbn(f), f.PickRandom<IsbnFormat>()))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid ISBN (International Standard Book Number).
|
||||
/// </summary>
|
||||
/// <param name="f">The Faker instance used for generating random data.</param>
|
||||
/// <returns>A properly formatted ISBN-10 or ISBN-13 string with valid checksum.</returns>
|
||||
private static string CreateIsbn(Faker f)
|
||||
{
|
||||
bool isIsbn13 = f.Random.Bool();
|
||||
if (isIsbn13)
|
||||
{
|
||||
string prefix = f.Random.Bool() ? "978" : "979";
|
||||
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
|
||||
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
|
||||
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
|
||||
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] digits = new int[9];
|
||||
for (int i = 0; i < 9; i++)
|
||||
digits[i] = f.Random.Number(0, 9);
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// Creates a list of book rating entities with random data.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of ratings to create.</param>
|
||||
/// <returns>A list of randomly generated book rating entities.</returns>
|
||||
private static List<BookRatingEntity> CreateBookRatings(int count)
|
||||
{
|
||||
return new Faker<BookRatingEntity>()
|
||||
.CustomInstantiator(f => new BookRatingEntity(
|
||||
f.Random.Decimal(1, 5),
|
||||
5,
|
||||
f.PickRandom<BookRatingSource>(),
|
||||
f.Random.Number(1, 1000)
|
||||
))
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures custom type generation rules for the AutoFixture instance.
|
||||
/// </summary>
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new TagEntity(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new GenreEntity(_fixture.Create<string>()));
|
||||
_fixture.Register(() => new IsbnEntity(_fixture.Create<string>(), _fixture.Create<IsbnFormat>()));
|
||||
_fixture.Register(() => new BookRatingEntity(
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
_fixture.Create<int>()
|
||||
));
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="LibraryMetadataProviderConfigurationEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryMetadataProviderConfigurationEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="LibraryMetadataProviderConfigurationEntity"/> for the provided media library, plugin and rank.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the configuration belongs to.</param>
|
||||
/// <param name="pluginId">The Id of the plugin providing the metadata.</param>
|
||||
/// <param name="rank">The rank of the metadata provider, determining the order in which providers are tried.</param>
|
||||
/// <returns>The created <see cref="LibraryMetadataProviderConfigurationEntity"/>.</returns>
|
||||
public LibraryMetadataProviderConfigurationEntity CreateConfiguration(Guid libraryId, Guid pluginId, int rank)
|
||||
{
|
||||
return new Faker<LibraryMetadataProviderConfigurationEntity>()
|
||||
.RuleFor(configuration => configuration.Id, faker => faker.Random.Guid())
|
||||
.RuleFor(configuration => configuration.LibraryId, libraryId)
|
||||
.RuleFor(configuration => configuration.PluginId, pluginId)
|
||||
.RuleFor(configuration => configuration.IsEnabled, faker => faker.Random.Bool())
|
||||
.RuleFor(configuration => configuration.Rank, rank)
|
||||
.RuleFor(configuration => configuration.CreatedOnUtc, faker => faker.Date.Past())
|
||||
.RuleFor(configuration => configuration.CreatedBy, faker => faker.Random.Guid())
|
||||
.RuleFor(configuration => configuration.UpdatedOnUtc, faker => faker.Date.Recent())
|
||||
.RuleFor(configuration => configuration.UpdatedBy, faker => faker.Random.Guid())
|
||||
.Generate();
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PluginEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginEntityFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PluginEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the plugin, or <see langword="null"/> to generate a random one.</param>
|
||||
/// <returns>The created <see cref="PluginEntity"/>.</returns>
|
||||
public PluginEntity CreatePluginEntity(Guid? id = null)
|
||||
{
|
||||
return new Faker<PluginEntity>()
|
||||
.RuleFor(plugin => plugin.Id, faker => id ?? faker.Random.Guid())
|
||||
.RuleFor(plugin => plugin.Name, faker => faker.Company.CompanyName())
|
||||
.RuleFor(plugin => plugin.Author, faker => faker.Name.FullName())
|
||||
.RuleFor(plugin => plugin.Version, faker => faker.System.Semver())
|
||||
.RuleFor(plugin => plugin.Description, faker => faker.Lorem.Sentence())
|
||||
.RuleFor(plugin => plugin.LoadStatus, faker => faker.PickRandom<PluginLoadStatus>())
|
||||
.RuleFor(plugin => plugin.SettingsJson, faker => JsonSerializer.Serialize(new Dictionary<string, string> { [faker.Random.String2(1, 10)] = faker.Random.String2(1, 20) }))
|
||||
.RuleFor(plugin => plugin.CreatedOnUtc, faker => faker.Date.Past())
|
||||
.RuleFor(plugin => plugin.CreatedBy, faker => faker.Random.Guid())
|
||||
.RuleFor(plugin => plugin.UpdatedOnUtc, faker => faker.Date.Recent())
|
||||
.RuleFor(plugin => plugin.UpdatedBy, faker => faker.Random.Guid())
|
||||
.Generate();
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.DataAccess.Core.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -37,8 +37,8 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfLibrary = _configurationFixture.CreateConfiguration(libraryId, Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfAnotherLibrary = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfLibrary = _configurationFixture.Create(libraryId, Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configurationOfAnotherLibrary = _configurationFixture.Create(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
_mockContext.LibraryMetadataProviderConfigurations.AddRange(configurationOfLibrary, configurationOfAnotherLibrary);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -55,7 +55,7 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
public async Task GetByLibraryAndPluginIdAsync_WhenConfigurationExists_ShouldReturnIt()
|
||||
{
|
||||
// Arrange
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.Create(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
_mockContext.LibraryMetadataProviderConfigurations.Add(configuration);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -71,7 +71,7 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
public async Task UpsertAsync_WhenConfigurationDoesNotExist_ShouldInsertIt()
|
||||
{
|
||||
// Arrange
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.Create(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpsertAsync(configuration, CancellationToken.None);
|
||||
@@ -86,11 +86,11 @@ public class LibraryMetadataProviderConfigurationRepositoryTests
|
||||
public async Task UpsertAsync_WhenConfigurationExists_ShouldUpdateIt()
|
||||
{
|
||||
// Arrange
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.CreateConfiguration(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
LibraryMetadataProviderConfigurationEntity configuration = _configurationFixture.Create(Guid.NewGuid(), Guid.NewGuid(), 1);
|
||||
_mockContext.LibraryMetadataProviderConfigurations.Add(configuration);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
LibraryMetadataProviderConfigurationEntity updatedConfiguration = _configurationFixture.CreateConfiguration(configuration.LibraryId, configuration.PluginId, 5);
|
||||
LibraryMetadataProviderConfigurationEntity updatedConfiguration = _configurationFixture.Create(configuration.LibraryId, configuration.PluginId, 5);
|
||||
updatedConfiguration.IsEnabled = true;
|
||||
|
||||
// Act
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.DataAccess.Core.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
@@ -37,7 +37,7 @@ public class PluginRepositoryTests
|
||||
public async Task GetByIdAsync_WhenPluginExists_ShouldReturnIt()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.Create();
|
||||
_mockContext.Plugins.Add(plugin);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PluginRepositoryTests
|
||||
public async Task UpsertAsync_WhenPluginDoesNotExist_ShouldInsertIt()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpsertAsync(plugin, CancellationToken.None);
|
||||
@@ -68,12 +68,12 @@ public class PluginRepositoryTests
|
||||
public async Task UpsertAsync_WhenPluginExists_ShouldUpdateDetectionFieldsAndPreserveSettings()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.Create();
|
||||
plugin.SettingsJson = """{"preferredLanguage":"en"}""";
|
||||
_mockContext.Plugins.Add(plugin);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
PluginEntity updatedPlugin = _pluginFixture.CreatePluginEntity(plugin.Id);
|
||||
PluginEntity updatedPlugin = _pluginFixture.Create(plugin.Id);
|
||||
updatedPlugin.Name = "Updated Name";
|
||||
updatedPlugin.SettingsJson = null; // the stored settings must be preserved
|
||||
|
||||
@@ -92,7 +92,7 @@ public class PluginRepositoryTests
|
||||
public async Task UpdateSettingsAsync_WhenPluginExists_ShouldUpdateItsSettings()
|
||||
{
|
||||
// Arrange
|
||||
PluginEntity plugin = _pluginFixture.CreatePluginEntity();
|
||||
PluginEntity plugin = _pluginFixture.Create();
|
||||
_mockContext.Plugins.Add(plugin);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
|
||||
-118
@@ -1,118 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
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;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Users.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="UserEntity"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Faker _faker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserEntityFixture"/> class.
|
||||
/// </summary>
|
||||
public UserEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_faker = new Faker();
|
||||
ConfigureCustomTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UserEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="UserEntity"/>.</returns>
|
||||
public UserEntity CreateUserModel()
|
||||
{
|
||||
Guid userId = _faker.Random.Guid();
|
||||
|
||||
return new Faker<UserEntity>()
|
||||
.RuleFor(x => x.Id, _ => userId)
|
||||
.RuleFor(x => x.Username, f => f.Internet.UserName())
|
||||
.RuleFor(x => x.Password, f => f.Internet.Password(12))
|
||||
.RuleFor(x => x.TempPassword, f => f.Random.Bool() ? f.Internet.Password(8) : null)
|
||||
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32, "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567") : null)
|
||||
.RuleFor(x => x.TempPasswordCreated, (f, u) => u.TempPassword != null ? f.Date.Past() : null)
|
||||
.RuleFor(x => x.Libraries, _ => CreateLibraries(_faker.Random.Number(1, 3), userId))
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.CreatedBy, _ => userId)
|
||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Random.Bool() ? f.Date.Recent() : null)
|
||||
.RuleFor(x => x.UpdatedBy, _ => userId)
|
||||
.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid collection of user libraries.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of user libraries to create.</param>
|
||||
/// <param name="userId">The unique identifier of the user for whom to create the libraries.</param>
|
||||
/// <returns>A collection of <see cref="LibraryEntity"/>.</returns>
|
||||
private static List<LibraryEntity> CreateLibraries(int count, Guid userId)
|
||||
{
|
||||
return new Faker<LibraryEntity>()
|
||||
.CustomInstantiator(f => new LibraryEntity
|
||||
{
|
||||
Id = f.Random.Guid(),
|
||||
UserId = userId,
|
||||
Title = f.Random.String2(f.Random.Number(1, 50)),
|
||||
LibraryType = f.PickRandom<LibraryType>(),
|
||||
ContentLocations = CreateContentLocations(f.Random.Number(1, 3)),
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = userId,
|
||||
UpdatedOnUtc = f.Random.Bool() ? f.Date.Recent() : null,
|
||||
UpdatedBy = f.Random.Bool() ? userId : null,
|
||||
})
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid collection of media paths for a library.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of media library contents to create.</param>
|
||||
/// <returns>A collection of <see cref="LibraryContentLocationEntity"/>.</returns>
|
||||
private static List<LibraryContentLocationEntity> CreateContentLocations(int count)
|
||||
{
|
||||
return new Faker<LibraryContentLocationEntity>()
|
||||
.CustomInstantiator(f => new LibraryContentLocationEntity
|
||||
{
|
||||
Path = f.System.FilePath()
|
||||
})
|
||||
.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures custom type generation rules for the AutoFixture instance.
|
||||
/// </summary>
|
||||
private void ConfigureCustomTypes()
|
||||
{
|
||||
_fixture.Register(() => new LibraryEntity
|
||||
{
|
||||
Id = _fixture.Create<Guid>(),
|
||||
UserId = _fixture.Create<Guid>(),
|
||||
Title = _fixture.Create<string>(),
|
||||
LibraryType = _fixture.Create<LibraryType>(),
|
||||
ContentLocations = [],
|
||||
CreatedOnUtc = _fixture.Create<DateTime>(),
|
||||
CreatedBy = _fixture.Create<Guid>(),
|
||||
UpdatedOnUtc = _fixture.Create<DateTime>(),
|
||||
UpdatedBy = _fixture.Create<Guid>()
|
||||
});
|
||||
|
||||
_fixture.Register(() => new LibraryContentLocationEntity
|
||||
{
|
||||
Path = _fixture.Create<string>()
|
||||
});
|
||||
}
|
||||
}
|
||||
+18
-23
@@ -2,10 +2,10 @@
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.DataAccess.Core.Repositories.Users;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Users.Fixtures;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -46,7 +46,7 @@ public class UserRepositoryTests
|
||||
public async Task InsertAsync_WhenUserDoesNotExist_ShouldAddUserToContextAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity userModel = _userEntityFixture.CreateUserModel();
|
||||
UserEntity userModel = _userEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = await _sut.InsertAsync(userModel, CancellationToken.None);
|
||||
@@ -64,7 +64,7 @@ public class UserRepositoryTests
|
||||
public async Task InsertAsync_WhenUserAlreadyExists_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity userModel = _userEntityFixture.CreateUserModel();
|
||||
UserEntity userModel = _userEntityFixture.Create();
|
||||
|
||||
_mockContext.Users.Add(userModel);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
@@ -82,12 +82,7 @@ public class UserRepositoryTests
|
||||
public async Task GetAllAsync_WhenCalled_ShouldReturnAllUsers()
|
||||
{
|
||||
// Arrange
|
||||
List<UserEntity> users =
|
||||
[
|
||||
_userEntityFixture.CreateUserModel(),
|
||||
_userEntityFixture.CreateUserModel(),
|
||||
_userEntityFixture.CreateUserModel()
|
||||
];
|
||||
List<UserEntity> users = _userEntityFixture.CreateMany();
|
||||
_mockContext.Users.AddRange(users);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -117,7 +112,7 @@ public class UserRepositoryTests
|
||||
public async Task GetByUsernameAsync_WhenUserExists_ShouldReturnUser()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity userModel = _userEntityFixture.CreateUserModel();
|
||||
UserEntity userModel = _userEntityFixture.Create();
|
||||
_mockContext.Users.Add(userModel);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -145,7 +140,7 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenUserExists_ShouldUpdateUserAndReturnUpdated()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity existingUser = _userEntityFixture.CreateUserModel();
|
||||
UserEntity existingUser = _userEntityFixture.Create();
|
||||
_mockContext.Users.Add(existingUser);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -183,7 +178,7 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenUserDoesNotExist_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity userModel = _userEntityFixture.CreateUserModel();
|
||||
UserEntity userModel = _userEntityFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await _sut.UpdateAsync(userModel, CancellationToken.None);
|
||||
@@ -197,7 +192,7 @@ public class UserRepositoryTests
|
||||
public async Task GetByIdAsync_WhenUserExists_ShouldReturnUserWithAllRelations()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity userModel = _userEntityFixture.CreateUserModel();
|
||||
UserEntity userModel = _userEntityFixture.Create();
|
||||
_mockContext.Users.Add(userModel);
|
||||
await _mockContext.SaveChangesAsync();
|
||||
|
||||
@@ -233,9 +228,9 @@ public class UserRepositoryTests
|
||||
public async Task UpdateAsync_WhenUserExistsWithPermissions_ShouldUpdatePermissionsAndReturnUpdated()
|
||||
{
|
||||
// Arrange
|
||||
UserEntity existingUser = _userEntityFixture.CreateUserModel();
|
||||
PermissionEntity oldPermission = _permissionEntityFixture.CreatePermissionModel();
|
||||
PermissionEntity newPermission = _permissionEntityFixture.CreatePermissionModel();
|
||||
UserEntity existingUser = _userEntityFixture.Create();
|
||||
PermissionEntity oldPermission = _permissionEntityFixture.Create();
|
||||
PermissionEntity newPermission = _permissionEntityFixture.Create();
|
||||
|
||||
_mockContext.Users.Add(existingUser);
|
||||
_mockContext.Permissions.Add(oldPermission);
|
||||
@@ -291,9 +286,9 @@ public class UserRepositoryTests
|
||||
PermissionEntityFixture permissionFixture = new();
|
||||
UserPermissionEntityFixture userPermissionFixture = new();
|
||||
|
||||
UserEntity existingUser = userFixture.CreateUserModel();
|
||||
PermissionEntity oldPermission = permissionFixture.CreatePermissionModel();
|
||||
PermissionEntity newPermission = permissionFixture.CreatePermissionModel();
|
||||
UserEntity existingUser = userFixture.Create();
|
||||
PermissionEntity oldPermission = permissionFixture.Create();
|
||||
PermissionEntity newPermission = permissionFixture.Create();
|
||||
|
||||
UserEntity userWithPermissions = new()
|
||||
{
|
||||
@@ -304,7 +299,7 @@ public class UserRepositoryTests
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
userPermissionFixture.CreateUserPermissionModel(existingUser, oldPermission)
|
||||
userPermissionFixture.Create(existingUser, oldPermission)
|
||||
],
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
@@ -324,7 +319,7 @@ public class UserRepositoryTests
|
||||
UserRole = null,
|
||||
UserPermissions =
|
||||
[
|
||||
userPermissionFixture.CreateUserPermissionModel(existingUser, newPermission)
|
||||
userPermissionFixture.Create(existingUser, newPermission)
|
||||
],
|
||||
CreatedBy = existingUser.CreatedBy,
|
||||
CreatedOnUtc = existingUser.CreatedOnUtc,
|
||||
@@ -464,7 +459,7 @@ public class UserRepositoryTests
|
||||
UserEntityFixture userFixture = new();
|
||||
UserRoleEntityFixture userRoleFixture = new();
|
||||
|
||||
UserRoleEntity oldUserRole = userRoleFixture.CreateUserRoleModel();
|
||||
UserRoleEntity oldUserRole = userRoleFixture.Create();
|
||||
|
||||
UserEntity existingUser = new()
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ 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.UsersManagement;
|
||||
using Lumina.DataAccess.Core.Seed;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Users.Fixtures;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using NSubstitute;
|
||||
@@ -375,7 +375,7 @@ public class DataSeedServiceTests
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
UserEntityFixture userFixture = new();
|
||||
UserEntity adminUser = userFixture.CreateUserModel();
|
||||
UserEntity adminUser = userFixture.Create();
|
||||
// Use the adminUser.Id instead of the randomly generated userId
|
||||
userId = adminUser.Id;
|
||||
|
||||
@@ -464,7 +464,7 @@ public class DataSeedServiceTests
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
RoleEntity adminRole = new() { Id = Guid.NewGuid(), RoleName = "Admin" };
|
||||
UserEntity adminUser = new UserEntityFixture().CreateUserModel();
|
||||
UserEntity adminUser = new UserEntityFixture().Create();
|
||||
|
||||
Error expectedError = Error.Failure("UserRole.InsertFailed", "Failed to insert user role");
|
||||
|
||||
|
||||
@@ -42,5 +42,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.DataAccess\Lumina.DataAccess.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Lumina.Application.Fixtures\Lumina.Application.Fixtures.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user