Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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 -----]


Posted 09-19-2008 9:41 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

Joshua Flanagan wrote re: StructureMap Automocker & FillDependencies Error(230)
on 09-21-2008 10:36 AM

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."

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)