Sunday, June 01, 2008

Mocking templated methods with NMock2

Mocking a method like T GetSomething();

This is something that I have resorted to RinoMock to achieve in the past...
... well it turns out you can do it with NMock2 v1.0 as follows:

Expect.Once.On(a).Method("GetSomething", typeof(int)).Will(Return.Value(42));

I've tried to find this before.. and failed.. so I thought I should blog it to make it easier to find in google.

Thanks to ursenzler for commenting on http://www.fluidscape.co.nz/?q=node/82#comment-1692

Saturday, May 03, 2008

NDI: Unexpected bonus

NDependencyInjection Update:

Now that most of the code-base is using NDI we are really seeing the benefits.

The main bonus I'm getting is with how simple refactoring has become. Once you have the architecture modeling reality, whenever a class needs a service the correct instance is already available in the scope. This means all you need to do is ask for it in the constructor and it all just works. No wiring changes.

Wednesday, April 16, 2008

When did you last do a "Chicken Run"

"Chicken Run": The process of checking in new code and then leaving before the build has completed, leaving others to deal with the build if it breaks.

Monday, March 17, 2008

Quick svn trick

Here's a one liner to update svn with your local changes.


svn st |awk '/\?/{print "svn add " $2};/\!/{print "svn del " $2}' | sh


Sure there are problems with it... like if the filename has ? or ! in it, then it'll do the wrong thing, but it works for me, so I thought I'd share :)

Thursday, March 06, 2008

NDependency Injection: HasCollection Enforces Layered Architecture

I recently added a feature to NDependencyInjection called "HasCollection".

It lets you specify a set of subsystems that all provide the same interface and so can be viewed as a collection.

ISystemDefinition book = new SystemWiring();

book.HasCollection(Page1, Page2, Page2).Provides();


Here Page1, Page2, Page3 are all of type ISubsystemBuilder, which each define the wiring of a specific IPage.

You can only expose something from one of these subsystems if all subsystems implement it. This has the side-effect of enforcing Liskov's Substitution Principle.

At first this feels limiting, but it is leading us to better designs.

GitHub Projects