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
Reseting Defaults in StructureMap when Injecting Stubs

This is just a short FYI post because this caused me some headache recently.

One thing to keep in mind when you are using StrucutreMap and are Injecting Stubs into the ObjectFactory, you will want to reset the ObjectFactory engine after you done with your tests.

To do this you will need to add this line of code.
ObjectFactory.ResetDefaults();

How you implement this and where you put it is up to you.  I simply put this as the last line of code in my tests, but you could put it in [TestFixtureTearDown] or if you wanted you could wrap your entire test in a try-finally block and put it there (I did not do this, did not think it was needed).

BTW, the error message you will receive if you have stubs lingering around in your ObjectFactory is the following ‘This action is invalid when the mock object is in verified state’.

Till next time


Posted 07-26-2007 7:05 AM by Derik Whittaker
Filed under: ,

[Advertisement]

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)