mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 09:32:48 -05:00
Create common test infrastructure project
This commit is contained in:
45
test/Common/AutoFixture/GlobalSettingsFixtures.cs
Normal file
45
test/Common/AutoFixture/GlobalSettingsFixtures.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using AutoFixture;
|
||||
using AutoFixture.Kernel;
|
||||
using AutoFixture.Xunit2;
|
||||
using Bit.Test.Common.Helpers.Factories;
|
||||
|
||||
namespace Bit.Test.Common.AutoFixture
|
||||
{
|
||||
public class GlobalSettingsBuilder : ISpecimenBuilder
|
||||
{
|
||||
public object Create(object request, ISpecimenContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
var pi = request as ParameterInfo;
|
||||
var fixture = new Fixture();
|
||||
|
||||
if (pi == null || pi.ParameterType != typeof(Bit.Core.Settings.GlobalSettings))
|
||||
return new NoSpecimen();
|
||||
|
||||
return GlobalSettingsFactory.GlobalSettings;
|
||||
}
|
||||
}
|
||||
|
||||
public class GlobalSettings : ICustomization
|
||||
{
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
fixture.Customize<Bit.Core.Settings.GlobalSettings>(composer => composer
|
||||
.Without(s => s.BaseServiceUri)
|
||||
.Without(s => s.Attachment)
|
||||
.Without(s => s.Send)
|
||||
.Without(s => s.DataProtection));
|
||||
}
|
||||
}
|
||||
|
||||
public class GlobalSettingsCustomizeAttribute : CustomizeAttribute
|
||||
{
|
||||
public override ICustomization GetCustomization(ParameterInfo parameter) => new GlobalSettings();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user