1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-24 12:35:25 +01:00
bitwarden-server/test/Infrastructure.EFIntegration.Test/Repositories/CollectionRepository.cs
Thomas Rittson 9021236d61
AC Team code ownership moves: Organization pt. 1 (#3472)
* move Organization.cs files to AC Team code ownership
2023-11-28 17:18:08 -06:00

53 lines
2.0 KiB
C#

using Bit.Core.AdminConsole.Entities;
using Bit.Core.Entities;
using Bit.Core.Test.AutoFixture.Attributes;
using Bit.Infrastructure.EFIntegration.Test.AutoFixture;
using Bit.Infrastructure.EFIntegration.Test.Repositories.EqualityComparers;
using Bit.Test.Common.AutoFixture.Attributes;
using Xunit;
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
namespace Bit.Infrastructure.EFIntegration.Test.Repositories;
[EfCollectionCustomize]
public class CollectionRepositoryTests
{
[CiSkippedTheory, BitAutoData]
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());
}
}