Using Rhino Mocks with Windows 7

There’s a very useful article by Stephen Walther here. Some parts do need to be updated, though:

  1. Rhino Mocks downloads have moved to hibernatingrhinos.com
  2. The warning about using assemblies downloaded from the internet in Windows Vista also applies to Windows 7:

    One warning about using Rhino Mocks on Windows Vista. Vista will prevent you from using assemblies that you download from the Internet. Before you reference the Rhino.Mocks.dll assembly in Visual Studio, you need to Unblock the assembly: right-click the assembly file and click the Unblock button under the General tab (see Figure 1).

    If you reference the assembly before doing this, you’ll need to remove the reference, delete the rhinomocks.dll from the bin folder, and then re-add the reference to the enabled assembly file before you’ll be able to use it.

Quick Reminders

  • To stub an object: var myStubbedObject = MockRepository.GenerateStub<IStubbedObject>();
  • To stub a method: myStubbedObject.Stub(x => x.MyStubbedMethod(myParameter)).Return("testValue");
  • To stub a property: myStubbedObject.Stub(x => x.MyStubbedProperty).Return("testValue");
  • If you get an exception message along the lines of ‘Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method)’ then make sure you have stubbed the interface and not the implementing class (assuming that you are working with classes which implement an interface, of course).
  • You can’t stub static methods with Rhino Mocks. If you want to stub File methods, for example, you can get round this issue by creating a wrapper class and stubbing that instead.
  • Remember that you don’t have to stub lists if what you need is a list of stubbed objects – just use a real list and add the stubbed objects to it!
Advertisements

About Jennifer Phillips Campbell

Software Developer and Medieval Historian
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s