2020-11-23 15:48:05 +01:00
|
|
|
using System;
|
|
|
|
using AutoFixture;
|
|
|
|
using AutoFixture.Kernel;
|
|
|
|
|
2021-10-29 21:05:45 +02:00
|
|
|
namespace Bit.Test.Common.AutoFixture.Attributes
|
2020-11-23 15:48:05 +01:00
|
|
|
{
|
|
|
|
public class SutProviderCustomization : ICustomization, ISpecimenBuilder
|
|
|
|
{
|
2021-02-04 19:54:21 +01:00
|
|
|
private IFixture _fixture = null;
|
|
|
|
|
2020-11-23 15:48:05 +01:00
|
|
|
public object Create(object request, ISpecimenContext context)
|
|
|
|
{
|
|
|
|
if (context == null)
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(context));
|
|
|
|
}
|
|
|
|
if (!(request is Type typeRequest))
|
|
|
|
{
|
|
|
|
return new NoSpecimen();
|
|
|
|
}
|
|
|
|
if (!typeof(ISutProvider).IsAssignableFrom(typeRequest))
|
|
|
|
{
|
|
|
|
return new NoSpecimen();
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:54:21 +01:00
|
|
|
return ((ISutProvider)Activator.CreateInstance(typeRequest, _fixture)).Create();
|
2020-11-23 15:48:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Customize(IFixture fixture)
|
|
|
|
{
|
2021-02-04 19:54:21 +01:00
|
|
|
_fixture = fixture;
|
2020-11-23 15:48:05 +01:00
|
|
|
fixture.Customizations.Add(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|