Rhino Mocks.
Mocks, 'fake' objects used to record another object's (the one you're testing) interaction with those objects. I've read a lot about these and never been able to actually use them.
That has to be down to either / or both
a) Inexeprience
b) Bad design
I've started using Rhino Mocks with our latest project and have found the documentation to be dysmal.
So here is how I got my first Mock test going:
//Create the repositry (can be in setup)
MockRepository mocks = new MockRepository();
//Create the mock
IGameView mockView = mocks.CreateMock
//Make the call you're expecting to be made on it - could be clearer in doc
mockView.UpdateName(tgc, "TestName");
//Get the mock ready to start recording
mocks.Replay(mockView);
//Use the mock
tgc.UpdateName += mockView.UpdateName;
Game g = TestObjects.GetGame(); //(I want to mock this)
g.Name = "TestName";
g.Save();
tgc.SetCurrentGame(g);
//Check your expectations were met
mocks.Verify(mockView);
So far so good...


0 Comments:
Post a Comment
<< Home