Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



StructureMap Automocker & FillDependencies Error(230)

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 -----]



Comments

Joshua Flanagan said:

It is a potentially misleading name. It should probably be something like "Auto Dependency Filler". We are used to using "mock" tools on interfaces, so we immediately think to apply an "automocker" to an interface. But its really just a way of saying "let me test this class, I don't necessarily care about its dependencies."

# September 21, 2008 10:36 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Red-Gate!