Permalink
Fetching contributors…
Cannot retrieve contributors at this time
44 lines (37 sloc) 1.22 KB
using System;
using System.Reflection;
using Autofac;
using AutofacContrib.NSubstitute;
namespace TestStack.Seleno.Tests.Specify
{
internal abstract class SpecificationFor<T> : Specification
{
public T SUT { get; set; }
protected AutoSubstitute AutoSubstitute;
protected SpecificationFor()
{
AutoSubstitute = CreateContainer();
InitialiseSystemUnderTest();
}
public virtual void InitialiseSystemUnderTest()
{
SUT = AutoSubstitute.Resolve<T>();
}
public TSubstitute SubstituteFor<TSubstitute>() where TSubstitute : class
{
return AutoSubstitute.ResolveAndSubstituteFor<TSubstitute>();
}
public override Type Story
{
get { return typeof(T); }
}
private static AutoSubstitute CreateContainer()
{
Action<ContainerBuilder> autofacCustomisation = c => c
.RegisterType<T>()
.FindConstructorsWith(t => t.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
.PropertiesAutowired();
return new AutoSubstitute(autofacCustomisation);
}
}
}