2022-08-29 15:40:59 +02:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using AutoFixture;
|
|
|
|
|
using AutoFixture.Kernel;
|
|
|
|
|
using AutoFixture.Xunit2;
|
|
|
|
|
using Bit.Core.Test.Helpers.Factories;
|
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
namespace Bit.Test.Common.AutoFixture;
|
|
|
|
|
|
|
|
|
|
public class GlobalSettingsBuilder : ISpecimenBuilder
|
2022-08-29 15:40:59 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
public object Create(object request, ISpecimenContext context)
|
2022-08-29 15:40:59 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
if (context == null)
|
2022-08-29 15:40:59 +02:00
|
|
|
|
{
|
2022-08-29 22:06:55 +02:00
|
|
|
|
throw new ArgumentNullException(nameof(context));
|
|
|
|
|
}
|
2022-08-29 15:40:59 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
var pi = request as ParameterInfo;
|
|
|
|
|
var fixture = new Fixture();
|
2022-08-29 15:40:59 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
if (pi == null || pi.ParameterType != typeof(Bit.Core.Settings.GlobalSettings))
|
|
|
|
|
return new NoSpecimen();
|
2022-08-29 15:40:59 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
return GlobalSettingsFactory.GlobalSettings;
|
2022-08-29 15:40:59 +02:00
|
|
|
|
}
|
2022-08-29 22:06:55 +02:00
|
|
|
|
}
|
2022-08-29 15:40:59 +02:00
|
|
|
|
|
2022-08-29 22:06:55 +02:00
|
|
|
|
public class GlobalSettingsCustomizeAttribute : CustomizeAttribute
|
|
|
|
|
{
|
|
|
|
|
public override ICustomization GetCustomization(ParameterInfo parameter) => new GlobalSettings();
|
2022-08-29 15:40:59 +02:00
|
|
|
|
}
|