I have been giving the AutoMocker that is part of StructureMap 2.5 a go lately. Today I was trying to setup my test and I get running into the following error:
failed: StructureMap.StructureMapException: StructureMap Exception Code: 230
Cannot call "FillDependencies" on type IGatheringPipeline. Check that the type is concrete and has no primitive arguments
Everything looked right and I knew i could create my objects directly via the ObjectFactory method, but I just could not figure out what was wrong. My 'bad' code is below.
[TestMethod]
public void IsSynchronizationNeeded_EnsureHitsRepository()
{
var pipelineMocker = new RhinoAutoMocker<IGatheringPipeline>();
pipelineMocker.Get<iRepository>().Expect( x => x.DataNeedsSynchrnoization() ).Return( true ).Repeat.Once();
var isSynchronizationNeeded = pipelineMocker.ClassUnderTest.IsSynchronizationNeeded();
Assert.AreEqual( true, isSynchronizationNeeded );
}
After staring at the code and taking another look at its intent it dawned on me what the issue was. I was creating the automocker with an interface and I wanted to call methods on that interface and actually have the logic execute. In order to get this to work I simply needed to change my class in the auto mocker to the concrete.
[TestMethod]
public void IsSynchronizationNeeded_EnsureHitsRepository()
{
// Using the Concrete here
var pipelineMocker = new RhinoAutoMocker<GatheringPipeline>();
pipelineMocker.Get<iRepository>().Expect( x => x.DataNeedsSynchrnoization() ).Return( true ).Repeat.Once();
var isSynchronizationNeeded = pipelineMocker.ClassUnderTest.IsSynchronizationNeeded();
Assert.AreEqual( true, isSynchronizationNeeded );
}
After I changed my test to use the code above everything worked out well.
Hope this helps,
Till next time,
[----- Remember to check out DimeCasts.Net -----]