2023-11-29 00:18:08 +01:00
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
|
|
|
|
using Bit.Core.Auth.Entities;
|
2023-04-14 19:25:56 +02:00
|
|
|
|
using Bit.Core.Entities;
|
2022-09-26 19:21:13 +02:00
|
|
|
|
using Bit.Core.Test.AutoFixture.Attributes;
|
2023-04-14 19:25:56 +02:00
|
|
|
|
using Bit.Infrastructure.EFIntegration.Test.Auth.AutoFixture;
|
|
|
|
|
using Bit.Infrastructure.EFIntegration.Test.Auth.Repositories.EqualityComparers;
|
2022-09-26 19:21:13 +02:00
|
|
|
|
using Xunit;
|
2023-04-14 19:25:56 +02:00
|
|
|
|
using EfAuthRepo = Bit.Infrastructure.EntityFramework.Auth.Repositories;
|
2022-09-26 19:21:13 +02:00
|
|
|
|
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
2023-04-14 19:25:56 +02:00
|
|
|
|
using SqlAuthRepo = Bit.Infrastructure.Dapper.Auth.Repositories;
|
2022-09-26 19:21:13 +02:00
|
|
|
|
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
|
|
|
|
|
2023-04-14 19:25:56 +02:00
|
|
|
|
namespace Bit.Infrastructure.EFIntegration.Test.Auth.Repositories;
|
2022-09-26 19:21:13 +02:00
|
|
|
|
|
|
|
|
|
public class AuthRequestRepositoryTests
|
|
|
|
|
{
|
|
|
|
|
[CiSkippedTheory, EfAuthRequestAutoData]
|
2024-02-22 17:59:08 +01:00
|
|
|
|
public async Task CreateAsync_Works_DataMatches(
|
2022-09-26 19:21:13 +02:00
|
|
|
|
AuthRequest authRequest,
|
|
|
|
|
AuthRequestCompare equalityComparer,
|
2023-04-14 19:25:56 +02:00
|
|
|
|
List<EfAuthRepo.AuthRequestRepository> suts,
|
|
|
|
|
SqlAuthRepo.AuthRequestRepository sqlAuthRequestRepo,
|
2023-06-15 23:54:08 +02:00
|
|
|
|
Organization organization,
|
2022-09-26 19:21:13 +02:00
|
|
|
|
User user,
|
|
|
|
|
List<EfRepo.UserRepository> efUserRepos,
|
2023-06-15 23:54:08 +02:00
|
|
|
|
List<EfRepo.OrganizationRepository> efOrgRepos,
|
|
|
|
|
SqlRepo.UserRepository sqlUserRepo,
|
|
|
|
|
SqlRepo.OrganizationRepository sqlOrgRepo
|
2022-09-26 19:21:13 +02:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
authRequest.ResponseDeviceId = null;
|
|
|
|
|
var savedAuthRequests = new List<AuthRequest>();
|
|
|
|
|
foreach (var sut in suts)
|
|
|
|
|
{
|
|
|
|
|
var i = suts.IndexOf(sut);
|
|
|
|
|
|
|
|
|
|
var efUser = await efUserRepos[i].CreateAsync(user);
|
|
|
|
|
sut.ClearChangeTracking();
|
|
|
|
|
authRequest.UserId = efUser.Id;
|
|
|
|
|
|
2023-06-15 23:54:08 +02:00
|
|
|
|
var efOrg = await efOrgRepos[i].CreateAsync(organization);
|
|
|
|
|
sut.ClearChangeTracking();
|
|
|
|
|
authRequest.OrganizationId = efOrg.Id;
|
|
|
|
|
|
2022-09-26 19:21:13 +02:00
|
|
|
|
var postEfAuthRequest = await sut.CreateAsync(authRequest);
|
|
|
|
|
sut.ClearChangeTracking();
|
|
|
|
|
|
|
|
|
|
var savedAuthRequest = await sut.GetByIdAsync(postEfAuthRequest.Id);
|
|
|
|
|
savedAuthRequests.Add(savedAuthRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
|
|
|
|
authRequest.UserId = sqlUser.Id;
|
2023-06-15 23:54:08 +02:00
|
|
|
|
var sqlOrg = await sqlOrgRepo.CreateAsync(organization);
|
|
|
|
|
authRequest.OrganizationId = sqlOrg.Id;
|
2022-09-26 19:21:13 +02:00
|
|
|
|
var sqlAuthRequest = await sqlAuthRequestRepo.CreateAsync(authRequest);
|
|
|
|
|
var savedSqlAuthRequest = await sqlAuthRequestRepo.GetByIdAsync(sqlAuthRequest.Id);
|
|
|
|
|
savedAuthRequests.Add(savedSqlAuthRequest);
|
|
|
|
|
|
|
|
|
|
var distinctItems = savedAuthRequests.Distinct(equalityComparer);
|
|
|
|
|
Assert.True(!distinctItems.Skip(1).Any());
|
|
|
|
|
}
|
|
|
|
|
}
|