All of the code samples have now been consolidated and moved to my blog at http://house9.blogspot.com/. Many google searches still point here so I am leaving this blog operational.

Saturday, February 16, 2008

Rhino.Mocks - the basics

Started using Rhino.Mocks recently (Awesome!!!) - just wanted to list a few of the basics; the official Rhino Mocks Documentation is very good and available here. These examples are a bit rough, they have not been compiled; there may be typos.

using
using Rhino.Mocks;


The mock repository


Mock a call to the db


Ignore any arguments


mock a method that returns void


Handle multiple calls to the same method


Partial Mock

5 comments:

ben.biddington said...

Hi,

Does you first example (The mock repository) work with v.3.5?

I get the error:

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).

House 9 said...

I have not tried it on 3.5 of .net but I believe it should work. Is it possible you are making multiple calls to the same mocked method? you might need a .Repeat.Any();

Anonymous said...

In 3.5 CreateMock is deprecated and should be changed to StrictMock. Might want to try that,

Anonymous said...

IProduct product = new Product("003092", "Sierra Nevada", 6.49);

Lär ju gå bra att instansiera ett interface, nötter...

House 9 said...

Had an issue with comment moderation
-------------------------------------

New Day posted this about a month ago

For the Equals method I get the same error as ben.biddington. I am using .NET 2.0
The error occurs on the line with Expect.Call so it does not proceed any further down the test.

Error
"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)."

Custom Search
< ... back