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:

You May Also Like

About the Author: rnowik

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.