1
0
mirror of https://github.com/bitwarden/server synced 2025-12-14 15:23:42 +00:00

[SM-151] Move EF Dapper tests to Infrastructure.EFIntegration.Test (#2204)

This commit is contained in:
Oscar Hinton
2022-08-29 15:40:59 +02:00
committed by GitHub
parent 2b2f9fafd2
commit 194c695cd0
104 changed files with 4098 additions and 1898 deletions

View File

@@ -0,0 +1,50 @@
using Bit.Core.Entities;
using Bit.Core.Test.AutoFixture.Attributes;
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
using Xunit;
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
namespace Bit.Infrastructure.EFIntegration.Test.Repositories
{
public class CollectionRepositoryTests
{
[CiSkippedTheory, EfCollectionAutoData]
public async void CreateAsync_Works_DataMatches(
Collection collection,
Organization organization,
CollectionCompare equalityComparer,
List<EfRepo.CollectionRepository> suts,
List<EfRepo.OrganizationRepository> efOrganizationRepos,
SqlRepo.CollectionRepository sqlCollectionRepo,
SqlRepo.OrganizationRepository sqlOrganizationRepo
)
{
var savedCollections = new List<Collection>();
foreach (var sut in suts)
{
var i = suts.IndexOf(sut);
var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
sut.ClearChangeTracking();
collection.OrganizationId = efOrganization.Id;
var postEfCollection = await sut.CreateAsync(collection);
sut.ClearChangeTracking();
var savedCollection = await sut.GetByIdAsync(postEfCollection.Id);
savedCollections.Add(savedCollection);
}
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
collection.OrganizationId = sqlOrganization.Id;
var sqlCollection = await sqlCollectionRepo.CreateAsync(collection);
var savedSqlCollection = await sqlCollectionRepo.GetByIdAsync(sqlCollection.Id);
savedCollections.Add(savedSqlCollection);
var distinctItems = savedCollections.Distinct(equalityComparer);
Assert.True(!distinctItems.Skip(1).Any());
}
}
}