You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
618 B
27 lines
618 B
using System.Reflection;
|
|
using Autofac;
|
|
using AutoFixture.Kernel;
|
|
|
|
namespace TestLibrary.AutoFixture;
|
|
|
|
public class AutofacSpecimenBuilder : ISpecimenBuilder
|
|
{
|
|
private readonly IContainer _container;
|
|
|
|
public AutofacSpecimenBuilder(IContainer container)
|
|
{
|
|
_container = container;
|
|
}
|
|
|
|
public object Create(object request, ISpecimenContext context)
|
|
{
|
|
if (request is not ParameterInfo paramInfo)
|
|
{
|
|
return new NoSpecimen();
|
|
}
|
|
|
|
var instance = _container.ResolveOptional(paramInfo.ParameterType);
|
|
return instance ?? new NoSpecimen();
|
|
}
|
|
}
|