Implements Authorization system

This commit is contained in:
BinaryAlley committed 2024-11-22 18:02:42 +02:00
1 parent 5bfb2ca212
commit 2c9c210e43
68 files changed
+2734 -336

No files matched your search

@@ -1,8 +1,11 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Time;
using Lumina.DataAccess.Common.DependencyInjection;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
using Lumina.DataAccess.UnitTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -22,6 +25,9 @@ public class RepositoryFactoryTests
// Arrange
ServiceCollection services = new();
DataAccessLayerServices.AddDataAccessLayerServices(services);
services.AddTransient<ICurrentUserService, TestCurrentUserService>();
services.AddTransient<IDateTimeProvider, TestDateTimeProvider>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
RepositoryFactory repositoryFactory = new(serviceProvider);
@@ -48,4 +54,4 @@ public class RepositoryFactoryTests
}
}
public interface IUnregisteredRepository { }
public interface IUnregisteredRepository { }
@@ -44,12 +44,12 @@ public class UserEntityFixture
.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.VerificationToken, f => f.Random.Bool() ? f.Random.Guid().ToString() : null)
.RuleFor(x => x.VerificationTokenCreated, (f, u) => u.VerificationToken != null ? f.Date.Past() : 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.Created, f => f.Date.Past())
.RuleFor(x => x.Updated, f => f.Random.Bool() ? f.Date.Recent() : null)
.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();
}
@@ -155,8 +155,11 @@ public class UserRepositoryTests
TempPassword = "TempPass456",
TotpSecret = "NewSecret",
Libraries = [],
Created = existingUser.Created,
Updated = DateTime.UtcNow
UserRoles = [],
UserPermissions = [],
CreatedBy = existingUser.Id,
CreatedOnUtc = existingUser.CreatedOnUtc,
UpdatedOnUtc = DateTime.UtcNow
};
// Act
@@ -1,12 +1,15 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Time;
using Lumina.DataAccess.Common.DependencyInjection;
using Lumina.DataAccess.Core.Repositories.Common.Factory;
using Lumina.DataAccess.Core.UoW;
using Lumina.DataAccess.UnitTests.Common.Setup;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
@@ -47,6 +50,8 @@ public class UnitOfWorkTests
// Arrange
ServiceCollection services = new();
DataAccessLayerServices.AddDataAccessLayerServices(services);
services.AddTransient<ICurrentUserService, TestCurrentUserService>();
services.AddTransient<IDateTimeProvider, TestDateTimeProvider>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
UnitOfWork unitOfWork = (UnitOfWork)serviceProvider.GetRequiredService<IUnitOfWork>();
@@ -63,6 +68,8 @@ public class UnitOfWorkTests
// Arrange
ServiceCollection services = new();
DataAccessLayerServices.AddDataAccessLayerServices(services);
services.AddTransient<ICurrentUserService, TestCurrentUserService>();
services.AddTransient<IDateTimeProvider, TestDateTimeProvider>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
UnitOfWork unitOfWork = (UnitOfWork)serviceProvider.GetRequiredService<IUnitOfWork>();
int initialCount = unitOfWork.Repositories.Count;
@@ -96,6 +103,8 @@ public class UnitOfWorkTests
// Arrange
ServiceCollection services = new();
DataAccessLayerServices.AddDataAccessLayerServices(services);
services.AddTransient<ICurrentUserService, TestCurrentUserService>();
services.AddTransient<IDateTimeProvider, TestDateTimeProvider>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
UnitOfWork unitOfWork = (UnitOfWork)serviceProvider.GetRequiredService<IUnitOfWork>();
unitOfWork.ResetRepositories();
@@ -113,6 +122,8 @@ public class UnitOfWorkTests
// Arrange
ServiceCollection services = new();
DataAccessLayerServices.AddDataAccessLayerServices(services);
services.AddTransient<ICurrentUserService, TestCurrentUserService>();
services.AddTransient<IDateTimeProvider, TestDateTimeProvider>();
ServiceProvider serviceProvider = services.BuildServiceProvider();
UnitOfWork unitOfWork = (UnitOfWork)serviceProvider.GetRequiredService<IUnitOfWork>();
@@ -135,4 +146,4 @@ public class UnitOfWorkTests
// Assert
await dbContext.Received(1).SaveChangesAsync(cancellationToken);
}
}
}