1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-28 13:15:12 +01:00
bitwarden-server/test/Infrastructure.EFIntegration.Test/Repositories/CollectionRepository.cs
Matt Gibson a6d97118fa
Feature/bit auto data (#2219)
* Update ProviderService tests

* Use BitAutoData in CipherService tests

* Simplify UserCipher fixture

Because we use a single customizer for all ciphers, they all have the same userId.

* Clean up more cipher fixtures

* Swap Cipher Fixtures to BitCustomizeAttribute

* Clean up collection fixtures

* Clean up GroupFixtures

* Move SendService Tests to BitAutoData

* Clean up Organization Fixtures

TODO: The customize attributes should not be customizing more than one class

* Name files after the class they contain

* Clear up usage of CustomAutoDataAttribute in tests

* Clean up usages of InlineCustomAutoData

* format

* Manually merge with file-scoped-namespace changes
2022-08-31 08:38:35 -05:00

52 lines
2.0 KiB
C#

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());
}
}