mirror of
https://github.com/bitwarden/server.git
synced 2024-11-29 13:25:17 +01:00
68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
|
using System;
|
||
|
using AutoFixture;
|
||
|
using AutoFixture.Kernel;
|
||
|
using AutoMapper;
|
||
|
using TableModel = Bit.Core.Models.Table;
|
||
|
using Bit.Core.Models.EntityFramework;
|
||
|
using Bit.Core.Test.AutoFixture.Attributes;
|
||
|
using Bit.Core.Test.AutoFixture.GlobalSettingsFixtures;
|
||
|
using Bit.Core.Test.AutoFixture.OrganizationFixtures;
|
||
|
using Bit.Core.Models.Data;
|
||
|
using System.Text.Json;
|
||
|
using Bit.Core.Test.AutoFixture.EntityFrameworkRepositoryFixtures;
|
||
|
using Bit.Core.Repositories.EntityFramework;
|
||
|
|
||
|
namespace Bit.Core.Test.AutoFixture.SsoConfigFixtures
|
||
|
{
|
||
|
internal class SsoConfigBuilder: 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(TableModel.SsoConfig))
|
||
|
{
|
||
|
return new NoSpecimen();
|
||
|
}
|
||
|
|
||
|
var fixture = new Fixture();
|
||
|
var ssoConfig = fixture.WithAutoNSubstitutions().Create<TableModel.SsoConfig>();
|
||
|
var ssoConfigData = fixture.WithAutoNSubstitutions().Create<SsoConfigurationData>();
|
||
|
ssoConfig.Data = JsonSerializer.Serialize(ssoConfigData, new JsonSerializerOptions(){
|
||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||
|
});
|
||
|
return ssoConfig;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
internal class EfSsoConfig: 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 SsoConfigBuilder());
|
||
|
fixture.Customizations.Add(new EfRepositoryListBuilder<SsoConfigRepository>());
|
||
|
fixture.Customizations.Add(new EfRepositoryListBuilder<OrganizationRepository>());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
internal class EfSsoConfigAutoDataAttribute : CustomAutoDataAttribute
|
||
|
{
|
||
|
public EfSsoConfigAutoDataAttribute() : base(new SutProviderCustomization(), new EfSsoConfig())
|
||
|
{ }
|
||
|
}
|
||
|
|
||
|
internal class InlineEfSsoConfigAutoDataAttribute : InlineCustomAutoDataAttribute
|
||
|
{
|
||
|
public InlineEfSsoConfigAutoDataAttribute(params object[] values) : base(new[] { typeof(SutProviderCustomization),
|
||
|
typeof(EfSsoConfig) }, values)
|
||
|
{ }
|
||
|
}
|
||
|
}
|