Some More RhinoMocks Examples

Here is a little bit of example code testing readonly / writeonly properties on a interface, as well as void methods

var mockRepository = new MockRepository();
var foo = mockRepository.StrictMock<IFoo>();

using (mockRepository.Record())
  // Test property is set set to 88;
  foo.TestProperty = 88;

  // Force return value of property to 99

  // Force return value of property to 99

  // Test property is set to 297
  // could also do Expect.Call(() => foo.TestWriteOnlyProperty = 297);
  foo.TestWriteOnlyProperty = 297;

  // Ensure void method is called (no params)
  // Could also do Expect.Call(() => foo.TestVoidMethodNoParams());
  // Ensure method is called with a specific param.
  // Could also do Expect.Call(() => foo.TestVoidMethod(297));
  // if we wanted to specify stuff on (e.g. ignore args)

using (mockRepository.Playback())
  var bar = new Bar(foo);

Here is a good RhinoMocks quick reference guide:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>