Minimal Rhino Mocks sample

var myMock = MockRepository.GenerateMock();
Console.WriteLine(myMock.Execute(“Hello”) ?? “”);

MockRepository mocks = new MockRepository();

var myMock2 = mocks.Stub();
using (mocks.Record())
{
SetupResult.For(myMock2.Execute(“Hello”)).Return(“World”);
}
Console.WriteLine(myMock2.Execute(“Hello”) ?? “”);

I still wonder why mocking frameworks are so popular. Handcrafted mocks seem to do the job quite well and are easy to implement as:

Stub – Ignore inputs and return as little as possible (I frequently return 42 as an integer result)
Spy – Record and log callers.
Saboteur – fail in a controlled fashion (i.e. a stream that will fail with an exception upon the fifth byte read).

If your interfaces are too big then you are not following SOLID properly. If changing the interface causes too many problems then you have not isolated the tests from the code enough (factories and helper methods).

Entity Framework Code First Fluent API – Can I create a fluent rules engine.

I am currently working through a lot of training courses (due to my employer being in special administration).

I have started on the Entity Framework Code First modules.
EF Code first seems to provide a declarative way of having a set of business entities that do not know about the database be persisted and loaded.

I am not interested in the annotation api since that is tying the business entities to the database.
[Rule #1 The model should not know about the view or the database.]

However the fluent api looks very interesting in that it can be used as an ORM (albeit a very simple one).
This means that a model could have two databases that it maps to (say old system and new system, or production and archive) that have distinct schema’s.

What would be interesting would be to see if this fluent api could not also be used as a validating rules engine. A given object can have different validation rules depending upon context.