Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,128 | Comments: 45,550

filter by tags archive

Hibernating Rhinos - Episode #1: Rhino Mocks 101

time to read 1 min | 136 words

To celebrate the Rhino Mocks 3.0 release, I produced a screen cast of about an hour, talking about how you can use it. This is the very first time that I am doing something like this, so the list of fubars in this episode is fairly long. For instance, I didn't realize that the Play/Pause bar would appear in the final movie, or thought about closing the IM during recording, etc.

At any rate, I think that this could provide a gentle introuction to Rhino Mocks, and help understand how to use it. The first few minutes are introductions and power point, but from then on, it is all code, so have fun.

You can watch it here.

Oh, and happy mocking.



Would you mind checking the download? It doesn't seem to work.


Same for me...


Wow atleast hide the detailed error page !!

Ayende Rahien

Please try now, it works.

@Leo, sorry about the error, I turned detailed errors on so I could figure out issues with the site.

Adam Tybor

Very nice! I can't wait to see more.

If you continue to do these one suggestion would be to try and include, like you did with Do() and LastCall.Constraints, practical examples of how to take advantage of all magic in RhinoMocks.

As always, nice work.

Chris Vickerson

I do appologize in advance if this information is in this first webcast - I'll watch it later tonight. I've been contemplating using RhinoMocks for quite some time - to finally learn how to incorporate mocking into our process of developing. When I approach others I work with I always get hammered with reasons not to use mock objects. One that keeps coming up is how to mock frameworks such as Windows Workflow Foundation. Would you consider covering the topic of mocking large existing frameworks (eg. ASP .Net or WWF)?


Your download is broken.

Exception Details: NHibernate.QueryException: in expected: f [from Feed f where f.Section.Id = :sectionId]

Ayende Rahien


I did some work a while ago about mocking WCF, you can search the blog on that

ASP.Net itself is not mockable/testable easily, and that is a big draw back as far as I am concerned.

I am talking about it in the screencast, but in general it is a bad thing to mock stuff that you don't controol/own.

The reason is that you usually does a lot of low granularity work with it, which is a PITA to mock.

Adapters are usually the answer for this case.

Ayende Rahien


Please try now, it is working.


You mention early on that you consider testing webservices / database calls to be integration testing. A lot of what I (and I would imagine pleanty of other people) do centers around getting the stored procs / views set up and ensuring that the right data is being returned, and for those of us not using any kind of OR/M, ensuring that we can do the CRUD from our applications. What would be your suggestion on how to approach this?


Which tool we should use to view? I only can hear... Thanks!


Download works like a charm, screencast is really good. Maybe the next time you should post at what time in the screencast you start coding, so I can jump just there ;-)

One thing I noticed: You always go back to the unit test code after you have changed something and have to run the test again. Are you doing that intentionally for the sake of the screencast or are you unware of Testdrivens "Repeat Test Run" command. I know it took me a couple of month until I discovered it. Know I have a keyboard shortcut for it

Ayende Rahien


You need to install the TSCC plugin (you can find the download link at the download page) and watch it in Windows Media Player

Doug Rohm

I can't get it to download either. The links in the post go to the same page.. I also have the plugin installed so it can't be that...


Adam Tybor


Checkout Rhino Commons, it has some nice text fixture stubs in ForTesting that allows you to use SqlCe and SqlLite to do quick "integration testing".

While CRUD testing is important the ORM handles this for you. The only persistence stuff I test is ensuring things like lazy loading and cascades are being handled properly. SqlCe works perfect for that. For the heavier integration tests we let our CI server handle that. Rarely do we find that integration tests fail if all unit tests are passing.


Ayende Rahien

What do you mean, you can't download it?

The link in the post goes to the download page, and the link to actually download the link to actually download the file is in the bottom of the screen.


The confusion is about the text "You can watch it here" where "here" is a link.

Naturally, we click "here", but that's just a link to the same page. :)

Ayende Rahien

Oh, that is just the post text, actually. sorry about being confusing

Robert Taylor

I really like the video - you did an excelent job of showing how to use RhinoMocks in a (near) real-world scenario. You mentioned how it is common for developers to forget to call ReplayAll() and i think i have a solution to that problem: take advantage of the "using" statement in the language by implementing a couple of new APIs and IDisposable...

using System;

using MbUnit.Framework;

using Rhino.Mocks.Constraints;

namespace Rhino.Mocks.Demo



public class RhinoMocks101Fixture


private MockRepository mockRepository;

private ISmsSender smsSender;

private IUserRepository userRepository;

private User user;

private LoginController loginController;


public void TestInitialize()


  mockRepository = new MockRepository();

  smsSender = mockRepository.CreateMock<ISmsSender>();

  userRepository = mockRepository.CreateMock<IUserRepository>();

  user = CreateUser();

  loginController = new LoginController(smsSender, this.userRepository);



public void WillSendSMSWhenUserRequestNewPassword()


  //nested scopes are not allowed; exception will be thrown

  //calling any mocked API outside of a scope will throw an exception

  using (this.mockRepository.RecordScope())



    smsSender.SendSms(null, null);

    LastCall.Constraints(Is.Equal(this.user.Phone), Text.StartsWith("New passord:"));


  using (this.mockRepository.PlaybackScope())



  } //disposing of the PlaybackScope will call VerifyAll()

  Assert.AreNotEqual("old", this.user.Password, "expected the password to change");





Great screencast! Btw, what font do you use in visual studio?

Christopher Bennage

Ayende has published an excellent sceencast introduction to Rhino Mocks . If you are at least somewhat

Ayende Rahien

I am aware of the Repeat Test Run, but I keep forgetting about it.

It is great when I am in the code, and I can just run the test again and again until I get it right.

In fact, if I am not mistaken, this is there because of a feature requst I made.

Ayende Rahien


Rhino Mocks had using() scope for verification at the beginning, but it was removed because people kept running into issues with it.

The most common issue was that if an exception was thrown when the mocks was in an invalid state, the using's dispose kicked in, attempted to verify, failed, and then threw a different exception, masking the real issue.



Comment preview

Comments have been closed on this topic.


  1. The worker pattern - 12 hours from now

There are posts all the way to May 30, 2016


  1. The design of RavenDB 4.0 (14):
    26 May 2016 - The client side
  2. RavenDB 3.5 whirl wind tour (14):
    25 May 2016 - Got anything to declare, ya smuggler?
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats