mirror of
https://github.com/bitwarden/server.git
synced 2024-12-11 15:17:44 +01:00
4e7b9d2edd
* Extract Import-Api endpoints into separate controller Moved ciphers/import and ciphers/import-organization into new ImportController Paths have been kept intact for now (no changes on clients needed) Moved request-models used for import into tools-subfolder * Update CODEOWNERS for team-tools-dev * Move HibpController (reports) to tools * Moving files related to Send * Moving files related to ReferenceEvent * Removed unneeded newline
68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using Bit.Core.Entities;
|
|
using Bit.Core.Test.AutoFixture.Attributes;
|
|
using Bit.Core.Tools.Entities;
|
|
using Bit.Infrastructure.EFIntegration.Test.Tools.AutoFixture;
|
|
using Bit.Infrastructure.EFIntegration.Test.Tools.Repositories.EqualityComparers;
|
|
using Xunit;
|
|
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
|
using EfSendRepo = Bit.Infrastructure.EntityFramework.Tools.Repositories;
|
|
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
|
using SqlSendRepo = Bit.Infrastructure.Dapper.Tools.Repositories;
|
|
|
|
namespace Bit.Infrastructure.EFIntegration.Test.Tools.Repositories;
|
|
|
|
public class SendRepositoryTests
|
|
{
|
|
[CiSkippedTheory, EfUserSendAutoData, EfOrganizationSendAutoData]
|
|
public async void CreateAsync_Works_DataMatches(
|
|
Send send,
|
|
User user,
|
|
Organization org,
|
|
SendCompare equalityComparer,
|
|
List<EfSendRepo.SendRepository> suts,
|
|
List<EfRepo.UserRepository> efUserRepos,
|
|
List<EfRepo.OrganizationRepository> efOrgRepos,
|
|
SqlSendRepo.SendRepository sqlSendRepo,
|
|
SqlRepo.UserRepository sqlUserRepo,
|
|
SqlRepo.OrganizationRepository sqlOrgRepo
|
|
)
|
|
{
|
|
var savedSends = new List<Send>();
|
|
foreach (var sut in suts)
|
|
{
|
|
var i = suts.IndexOf(sut);
|
|
|
|
if (send.OrganizationId.HasValue)
|
|
{
|
|
var efOrg = await efOrgRepos[i].CreateAsync(org);
|
|
sut.ClearChangeTracking();
|
|
send.OrganizationId = efOrg.Id;
|
|
}
|
|
var efUser = await efUserRepos[i].CreateAsync(user);
|
|
sut.ClearChangeTracking();
|
|
|
|
send.UserId = efUser.Id;
|
|
var postEfSend = await sut.CreateAsync(send);
|
|
sut.ClearChangeTracking();
|
|
|
|
var savedSend = await sut.GetByIdAsync(postEfSend.Id);
|
|
savedSends.Add(savedSend);
|
|
}
|
|
|
|
var sqlUser = await sqlUserRepo.CreateAsync(user);
|
|
if (send.OrganizationId.HasValue)
|
|
{
|
|
var sqlOrg = await sqlOrgRepo.CreateAsync(org);
|
|
send.OrganizationId = sqlOrg.Id;
|
|
}
|
|
|
|
send.UserId = sqlUser.Id;
|
|
var sqlSend = await sqlSendRepo.CreateAsync(send);
|
|
var savedSqlSend = await sqlSendRepo.GetByIdAsync(sqlSend.Id);
|
|
savedSends.Add(savedSqlSend);
|
|
|
|
var distinctItems = savedSends.Distinct(equalityComparer);
|
|
Assert.True(!distinctItems.Skip(1).Any());
|
|
}
|
|
}
|