2022-06-29 19:46:41 -04:00
|
|
|
|
using AutoFixture;
|
2020-11-23 08:48:05 -06:00
|
|
|
|
using AutoFixture.Kernel;
|
|
|
|
|
|
|
2022-08-29 15:53:48 -04:00
|
|
|
|
namespace Bit.Test.Common.AutoFixture.Attributes
|
2020-11-23 08:48:05 -06:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
public class SutProviderCustomization : ICustomization, ISpecimenBuilder
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
private IFixture _fixture = null;
|
|
|
|
|
|
|
|
|
|
|
|
public object Create(object request, ISpecimenContext context)
|
2020-11-23 08:48:05 -06:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
if (context == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new ArgumentNullException(nameof(context));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!(request is Type typeRequest))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new NoSpecimen();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!typeof(ISutProvider).IsAssignableFrom(typeRequest))
|
|
|
|
|
|
{
|
|
|
|
|
|
return new NoSpecimen();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ((ISutProvider)Activator.CreateInstance(typeRequest, _fixture)).Create();
|
2020-11-23 08:48:05 -06:00
|
|
|
|
}
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
|
|
|
|
|
public void Customize(IFixture fixture)
|
2022-08-29 14:53:16 -04:00
|
|
|
|
{
|
2022-08-29 15:53:48 -04:00
|
|
|
|
_fixture = fixture;
|
|
|
|
|
|
fixture.Customizations.Add(this);
|
2022-08-29 14:53:16 -04:00
|
|
|
|
}
|
2020-11-23 08:48:05 -06:00
|
|
|
|
}
|
|
|
|
|
|
}
|