mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
42cec31d07
* note: IPolicyData and EntityFramework Policy.cs are moved without any changes to namespace or content in order to preserve git history.
54 lines
2.1 KiB
C#
54 lines
2.1 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 Xunit;
|
|
using EfAdminConsoleRepo = Bit.Infrastructure.EntityFramework.AdminConsole.Repositories;
|
|
using EfRepo = Bit.Infrastructure.EntityFramework.Repositories;
|
|
using Policy = Bit.Core.AdminConsole.Entities.Policy;
|
|
using SqlAdminConsoleRepo = Bit.Infrastructure.Dapper.AdminConsole.Repositories;
|
|
using SqlRepo = Bit.Infrastructure.Dapper.Repositories;
|
|
|
|
namespace Bit.Infrastructure.EFIntegration.Test.AdminConsole.Repositories;
|
|
|
|
public class PolicyRepositoryTests
|
|
{
|
|
[CiSkippedTheory, EfPolicyAutoData]
|
|
public async void CreateAsync_Works_DataMatches(
|
|
Policy policy,
|
|
Organization organization,
|
|
PolicyCompare equalityComparer,
|
|
List<EfAdminConsoleRepo.PolicyRepository> suts,
|
|
List<EfRepo.OrganizationRepository> efOrganizationRepos,
|
|
SqlAdminConsoleRepo.PolicyRepository sqlPolicyRepo,
|
|
SqlRepo.OrganizationRepository sqlOrganizationRepo
|
|
)
|
|
{
|
|
var savedPolicys = new List<Policy>();
|
|
foreach (var sut in suts)
|
|
{
|
|
var i = suts.IndexOf(sut);
|
|
|
|
var efOrganization = await efOrganizationRepos[i].CreateAsync(organization);
|
|
sut.ClearChangeTracking();
|
|
|
|
policy.OrganizationId = efOrganization.Id;
|
|
var postEfPolicy = await sut.CreateAsync(policy);
|
|
sut.ClearChangeTracking();
|
|
|
|
var savedPolicy = await sut.GetByIdAsync(postEfPolicy.Id);
|
|
savedPolicys.Add(savedPolicy);
|
|
}
|
|
|
|
var sqlOrganization = await sqlOrganizationRepo.CreateAsync(organization);
|
|
|
|
policy.OrganizationId = sqlOrganization.Id;
|
|
var sqlPolicy = await sqlPolicyRepo.CreateAsync(policy);
|
|
var savedSqlPolicy = await sqlPolicyRepo.GetByIdAsync(sqlPolicy.Id);
|
|
savedPolicys.Add(savedSqlPolicy);
|
|
|
|
var distinctItems = savedPolicys.Distinct(equalityComparer);
|
|
Assert.True(!distinctItems.Skip(1).Any());
|
|
}
|
|
}
|