I am trying to use SUT Factory 'pattern' to create my SUT.
Given the structure of the SUT:
namespace MySut
{
public class Dep1
{
}
public class Dep2
{
}
public class Sut
{
public Sut( Dep1 dep1, Dep2 dep2 )
{
}
}
}
I use AutoFixture , and I am wondering what the best way to collapse the following specifications and the associated SUT factory method [valuable, but] busy:
namespace MySpecifications
{
using MySut;
public class MySpecification
{
public void TestCore()
{
var sut = CreateSut();
}
public void TestDep1Interaction()
{
var sut = CreateSut( new Mock<Dep1>().Object );
}
public void TestDep2Interaction()
{
var sut = CreateSut( new Mock<Dep2>().Object );
}
private object CreateSut( )
{
return CreateSut( CreateDep1(), CreateDep2() );
}
private object CreateSut( Dep1 dep1 )
{
return CreateSut( dep1, CreateDep2() );
}
private object CreateSut( Dep2 dep2 )
{
return CreateSut( CreateDep1(), dep2 );
}
private Sut CreateSut( Dep1 dep1, Dep2 dep2 )
{
return new Sut( dep1, dep2 );
}
private static Dep1 CreateDep1()
{
return new Fixture().CreateAnonymous<Dep1>();
}
private static Dep2 CreateDep2()
{
return new Fixture().CreateAnonymous<Dep2>();
}
}
}
to something like:
public class MyAutoFixturedSpecification
{
public void TestCore()
{
var sut = CreateSut();
}
public void TestDep1Interaction()
{
var sut = CreateSut( new Mock<Dep1>().Object );
}
public void TestDep2Interaction()
{
var sut = CreateSut( new Mock<Dep2>().Object );
}
private object CreateSut( params object[] injectedNonAnonymouses )
{
return new Fixture( ).Build<Sut>( ).;
}
}
or
public class MyAnticipatedAutoFixturedSpecification
{
public void TestCore()
{
var sut = new Fixture( ).Build<Sut>().CreateAnonymous( );
}
public void TestDep1Interaction()
{
var sut = new Fixture().Build<Sut>().CreateAnonymous();
}
public void TestDep2Interaction()
{
var sut = new Fixture().Build<Sut>().CreateAnonymous();
}
}
ie, deleting all the garbage factory, so my specifications can easily handle the switch to:
namespace MySutWithNewDependency
{
public class Dep1
{
}
public class Dep2
{
}
public class Dep3
{
}
public class Sut
{
public Sut( Dep1 dep1, Dep2 dep2, Dep3 dep3 )
{
}
}
}
, - 0 1 , Sut , .
( xUnit.net( SubSpec), Moq, Ninject2 ( DI ))