If you have not checked out the new AutoMocking Container that is part of StructureMap 2.5 I would highly suggest you do, it rocks.
I thought I would show how simple it is to create a PartialMock on the Class under Test (CUT) when using the RhinoAutoMocker.
Our Class we want to mock
public class VisitReassignmentRule : PersistingRule
{
public VisitReassignmentRule( ISynchronizationRepository synchronizationRepository,
IValidationRepository validationRepository,
IValidationLogger validationLogger ) : base( validationRepository, validationLogger )
{
SynchronizationRepository = synchronizationRepository;
}
public override InvocationActions ProcessRule( DataSet ds )
{
// logic goes here
return null;
}
public override bool DataIsInviolationOfRule( DataSet dataSet )
{
return false;
}
private ISynchronizationRepository SynchronizationRepository { get; set; }
}
Mocking Code
[Test]
public void ProcessRule_ViolatesRule()
{
var rule = new RhinoAutoMocker();
// This line here tell the mocking container to make it a partial ( I know, the method name tells u that to)
rule.PartialMockTheClassUnderTest();
rule.ClassUnderTest.Expect( x => x.DataIsInviolationOfRule( null ) ).IgnoreArguments().Return( false ).Repeat.Any();
// actually call the method
rule.ClassUnderTest.ProcessRule( dataset );
}
As you can see, telling the AutoMocking container that you want the Class under Test to be a partial is very easy. The one thing you want to make sure you do is not use the .Get<> syntax and just use the .ClassUnderTest syntax to set your expectation.
Till next time,
[----- Remember to check out DimeCasts.Net -----]
Posted
10-10-2008 7:54 AM
by
Derik Whittaker