Registration rework

+ InvitesRepository
+ AdminsRepository
+ rework jwt
This commit is contained in:
Artemy
2025-06-24 14:27:08 +07:00
parent 410a1ce1cc
commit ce013eae49
37 changed files with 2084 additions and 29 deletions
@@ -0,0 +1,48 @@
using AutoFixture;
using Govor.Core.Models;
using Govor.Data;
using Govor.Data.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace Govor.API.Tests.IntegrationTests.EF.Repositories;
[TestFixture]
public class AdminsRepositoryTests
{
private Fixture _fixture;
private DbContextOptions<GovorDbContext> _options;
private int _testIteration = 0;
[SetUp]
public void Setup()
{
_fixture = new Fixture();
_options = new DbContextOptionsBuilder<GovorDbContext>()
.UseInMemoryDatabase(databaseName: $"DbGovor_{nameof(AdminsRepositoryTests)}_{_testIteration}")
.Options;
}
[Test]
public async Task Given_NotEmptyDbSet_When_GetAllAsync_Then_Admins_Are_Returned()
{
// Arrange
var random = new Random();
var admins = _fixture.CreateMany<Admin>(random.Next(3, 10)).ToList();
await using var context = new GovorDbContext(_options);
var repository = new AdminsRepository(context);
context.AddRange(admins);
await context.SaveChangesAsync();
// Act
var result = await repository.GetAllAsync();
// Assert
Assert.That(result, Is.Not.Null);
Assert.That(result.Count(), Is.EqualTo(admins.Count()));
Assert.That(result.Select(r => r.UserId), Is.EquivalentTo(admins.Select(r => r.UserId)));
}
}
@@ -4,6 +4,8 @@ using Govor.Core.Infrastructure.Extensions;
using Govor.Core.Models;
using Govor.Core.Repositories.Users;
using Govor.API.Services.Authentication.Interfaces;
using Govor.Core.Repositories.Admins;
using Govor.Core.Repositories.Invaites;
using Moq;
namespace Govor.API.Tests.UnitTests.Services;
@@ -15,6 +17,9 @@ public class AuthServiceTests
private Mock<IPasswordHasher> _passwordHasherMock;
private Mock<IJwtService> _jwtServiceMock;
private Mock<IUsersRepository> _usersRepositoryMock;
private Mock<IAdminsRepository> _adminsRepositoryMock;
private Mock<IInvitesRepository> _invitesRepositoryMock;
private IAccountService _accountService;
[SetUp]
@@ -29,7 +34,9 @@ public class AuthServiceTests
_accountService = new AuthService(
_usersRepositoryMock.Object,
_jwtServiceMock.Object,
_passwordHasherMock.Object
_passwordHasherMock.Object,
_invitesRepositoryMock.Object,
_adminsRepositoryMock.Object
);
}
@@ -41,7 +48,7 @@ public class AuthServiceTests
// Act & Assert
Assert.ThrowsAsync<UserAlreadyExistException>(async () => await _accountService.RegistrationAsync(
_fixture.Create<string>(), _fixture.Create<string>()));
_fixture.Create<string>(), _fixture.Create<string>(), _fixture.Create<string>()));
}
[Test]
@@ -52,7 +59,7 @@ public class AuthServiceTests
// Act & Assert
Assert.DoesNotThrowAsync(async () => await _accountService.RegistrationAsync(
_fixture.Create<string>(), _fixture.Create<string>()));
_fixture.Create<string>(), _fixture.Create<string>(), _fixture.Create<string>()));
}
[Test]