About Me

Training

Nothin But .Net Developer Bootcamp

Navigation

Search

Categories

On this page

Archive

Blogroll

 Agile Developer Venkat's Blog
 Ayende @ Blog
 B#
 Barry Gervin's Software Architecture Perspectives
 Boy Meets World
 Brad Abrams
 Canadian Developers
 Christopher Steen
 Claritude Software News
 Clemens Vasters: Enterprise Development and Alien Abductions
 Coding Horror
 Coding in an Igloo
 Dare Obasanjo aka Carnage4Life
 Darrell Norton's Blog [MVP]
 David Hayden [MVP C#]
 Don Box's Spoutlet
 Eric Gunnerson's C# Compendium
 EZWeb guy: Jeffrey Palermo [C# MVP]
 Fear and Loathing
 Generalities & Details: Adventures in the High-tech Underbelly
 Greg Young [MVP]
 Greg's Cool [Insert Clever Name] of the Day
 IanG on Tap
 Ingo Rammer's Weblog
 ISerializable - Roy Osherove's Blog
 James Kovacs' Weblog
 Jason Haley
 Jean-Luc David
 Jeremy D. Miller -- The Shade Tree Developer
 JetBrains .NET Tools Blog
 Jimmy Nilsson's weblog
 John Bristowe's Weblog
 John Papa [MVP C#]
 Jon Skeet's Coding Blog
 JonGalloway.ToString()
 Jump the Fence or Walk Around
 Lambda the Ultimate - Programming Languages Weblog
 Larkware News
 Lutz Roeder
 Marquee de Sells: Chris's insight outlet
 Martin Fowler's Bliki
 Mike Nichols - SonOfNun Technology
 MSDN Magazine - .NET Matters
 MSDN Magazine - All Articles
 OdeToCode Blogs
 Onion Blog
 Planet TW
 Raymond Lewallen [MVP]
 Rockford Lhotka
 RodMan's Corner
 Roger Johansson's blog
 Sahil Malik - blah.winsmarts.com
 Sam Gentile's Blog
 Scott Bellware [MVP]
 Scott Hanselman's Computer Zen
 ScottGu's Blog
 secretGeek
 Service Station, by Aaron Skonnard
 Signum sine tinnitu--by Guy Kawasaki
 Stephen Toub
 Steve Eichert's Blog
 Steven Rockarts
 The Blog Ride
 The Coding Hillbilly
 The Daily WTF
 TheServerSide.net: News
 Tim Gifford
 Vance Morrison's Weblog
 you've been HAACKED

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 519
This Year: 28
This Month: 0
This Week: 0
Comments: 1589

 Friday, June 13, 2008
Friday, June 13, 2008 5:47:58 PM (Mountain Standard Time, UTC-07:00) ( C Sharp | Programming )

Having downloaded and started to use Rhino Mocks 3.5 beta pretty much as soon as Oren released. I am very happy with the AAA style (Arrange, Act, Assert) and the readability and brevity it has brought to my tests. The current project I am on has a huge set of tests. Here is an example of using Rhino Mocks, in conjunction with some BDD style naming:

[Concern(typeof (UnitOfWorkFactory))] public class When_a_new_unit_of_work_is_requested_to_be_created : behaves_like_unit_of_work_with_scope_storage_in_play { protected override void because() { sut.Create(); } [Observation] public void Should_access_scoped_storage_to_determine_if_a_unit_of_work_is_already_active() { scoped_storage.was_told_to(item => item.DoesNotContain<IUnitOfWork>()); } } [Concern(typeof (UnitOfWorkFactory))] public class When_creating_a_unit_of_work_and_the_scoped_storage_does_not_contain_an_active_unit_of_work : behaves_like_unit_of_work_with_scope_storage_in_play { private ISession session; protected override void establish_context() { base.establish_context(); session = Dependency<ISession>(); scoped_storage.setup_result(item => item.DoesNotContain<IUnitOfWork>()).Return(true); nhibernate_session_factory.setup_result(item => item.OpenSession()).Return(session); } protected override void because() { sut.Create(); } [Observation] public void Should_store_the_newly_created_unit_of_work_in_scoped_storage() { scoped_storage.was_told_to(item => item.Store(Arg<IUnitOfWork>.Matches(uow => uow != null))); } } [Concern(typeof (UnitOfWorkFactory))] public class When_a_new_unit_of_work_is_requested_and_one_already_exists_in_scoped_storage : behaves_like_unit_of_work_with_scope_storage_in_play { private ISession session; private IUnitOfWork new_unit_of_work; private IUnitOfWork active_unit_of_work; protected override void establish_context() { base.establish_context(); session = Dependency<ISession>(); active_unit_of_work = Dependency<IUnitOfWork>(); nhibernate_session_factory.setup_result(item => item.OpenSession()).Return(session); scoped_storage.setup_result(item => item.Contains<IUnitOfWork>()).Return(true); scoped_storage.setup_result(item => item.Retrieve<IUnitOfWork>()).Return(active_unit_of_work); } protected override void because() { new_unit_of_work = sut.Create(); } [Observation] public void Should_return_a_non_disposing_unit_of_work_proxy() { new_unit_of_work.should_be_an_instance_of<NonDisposableUnitOfWork>(); } }
 

I am no longer using the automocking container so you are probably wondering what the Dependency method call is all about. It is simply a method defined on a base ContextSpecification class whose definition is as follows:

 

[Context] public abstract class ContextSpecification { [SetUp] public void setup() { unit_test_container.Initialize(); establish_context(); because(); } [TearDown] public void teardown() { after_each_specification(); unit_test_container.tear_down_and_unregister_from_dependency_registry(); } protected abstract void because(); protected abstract void establish_context(); protected virtual void after_each_specification() { } protected InterfaceType Dependency<InterfaceType>() { return MockRepository.GenerateMock<InterfaceType>(); } protected InterfaceType Stub<InterfaceType>() { return MockRepository.GenerateStub<InterfaceType>(); } }

And I have some extension methods that wrap the RhinoMocks "assertions" with more language oriented assertions: Instead of AssertWasCalled you get was_told_to, and so on.

 

Develop With Passion!!

Friday, June 13, 2008 6:14:40 PM (Mountain Standard Time, UTC-07:00)
I'm digging your language oriented wrappers around Rhino.Mocks' default AssertXXX methods.

I have been trying to think of something more natural than AssertWasCalled, etc... but couldn't come up with something that felt clean. I'd tossed around the idea of using should_have_called and should_not_have_called, but I'm not sure it's exactly what I'm looking for.

I think I'll give was_told_to and was_not_told_to a shot and see if they stick. :)
Friday, June 13, 2008 9:32:41 PM (Mountain Standard Time, UTC-07:00)
Smells like someone needs to go back on dnrtv and catch us up on what he's been up to :)
Saturday, June 14, 2008 8:33:00 AM (Mountain Standard Time, UTC-07:00)
+1 on dnrTV. Updating the nothinbutdotnet web app would also be nice :-).
Tuesday, June 17, 2008 1:14:32 PM (Mountain Standard Time, UTC-07:00)
Hey JP,

Where do the [Context] and [Concern()] attributes come from?
Martin
Sunday, June 29, 2008 8:11:05 AM (Mountain Standard Time, UTC-07:00)
[quote]Smells like someone needs to go back on dnrtv and catch us up on what he's been up to :)[/quote]

I agree. I think JP should go back on dnrtv and do some more shows, id love to see some more design patterns shown. If your reading this JP maybe you could talk to carl or something.
tom
Tuesday, May 19, 2009 9:29:56 AM (Mountain Standard Time, UTC-07:00)
Good evening. Hola ;) Yesterday I was browsing and came here, still wanna come back ;) Would like to chat ;). Help me! Can not find sites on the: drug alcohol rehab. I found only this - <a href="http://design.ru-deluxe.ru/">adobe fotoshop skachat'</a>. Drug and alcohol treatment in south florida, providing individualized and comprehensive treatment for patients suffering from addiction in a nurturing. Premier tennessee drug rehabilitation, drug rehab center substance abuse and alcohol treatment center near nashville. Waiting for a reply :rolleyes:, Davan from Togo.
Friday, August 14, 2009 12:49:24 AM (Mountain Standard Time, UTC-07:00)
D'une manière très intéressante quoi que ce sujet se regardait s'il y avait tout au contraire ? ? Personne ne discute précieux info, mais je pense on ne sait pourquoi qu'en laissant nos remarques nous ne contribuerons pas du tout.
Wednesday, January 20, 2010 12:19:10 PM (Mountain Standard Time, UTC-07:00)
Oh my God this is what I was looking for
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):