1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-23 17:07:42 +01:00
bitwarden-server/test/Infrastructure.EFIntegration.Test/AutoFixture/OrganizationFixtures.cs
2022-08-29 16:06:55 -04:00

58 lines
1.8 KiB
C#

using AutoFixture;
using AutoFixture.Kernel;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Models;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
namespace Bit.Infrastructure.EFIntegration.Test.AutoFixture;
internal class OrganizationBuilder : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var type = request as Type;
if (type == null || type != typeof(Organization))
{
return new NoSpecimen();
}
var fixture = new Fixture();
var providers = fixture.Create<Dictionary<TwoFactorProviderType, TwoFactorProvider>>();
var organization = new Fixture().WithAutoNSubstitutions().Create<Organization>();
organization.SetTwoFactorProviders(providers);
return organization;
}
}
internal class EfOrganization : ICustomization
{
public void Customize(IFixture fixture)
{
fixture.Customizations.Add(new IgnoreVirtualMembersCustomization());
fixture.Customizations.Add(new GlobalSettingsBuilder());
fixture.Customizations.Add(new OrganizationBuilder());
fixture.Customizations.Add(new EfRepositoryListBuilder<OrganizationRepository>());
}
}
internal class EfOrganizationAutoDataAttribute : CustomAutoDataAttribute
{
public EfOrganizationAutoDataAttribute() : base(new SutProviderCustomization(), new EfOrganization())
{ }
}
internal class InlineEfOrganizationAutoDataAttribute : InlineCustomAutoDataAttribute
{
public InlineEfOrganizationAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
typeof(EfOrganization) }, values)
{ }
}