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