Oren Eini

CEO of RavenDB

a NoSQL Open Source Document Database

Get in touch with me:

oren@ravendb.net +972 52-548-6969

Posts: 7,640
|
Comments: 51,260
Privacy Policy · Terms
filter by tags archive
time to read 2 min | 380 words

A brand new release of Rhino Mocks, with a twist.

Jeff emailed me a patch yesterday, that enabled the mocking of delegates. This is not something that I would've ever considered, to tell you the truth, but the idea (and the code) were sound, and I can certainly see uses for this. Consider all the possibilities for near-functional programming that .Net 2.0 opens for us, and you'll see what I'm excited about.

Here is an example of using this new functionality:

[Test]
public void GenericDelegate()
{
  Action<int> action = mocks.CreateMock<Action<int>>();
  for (int i = 0; i < 10; i++)
  {
    action(i);
  }
  mocks.ReplayAll();
  ForEachFromZeroToNine(action);
  mocks.VerifyAll();
}
private void ForEachFromZeroToNine(Action<int> act)
{
  for (int i = 0; i < 10; i++)
  {
    act(i);
  }
}

The other big change is removing IDisposable from the MockRepository. This is a breaking change for somet people, but it is a must. The problem is that the #1 problem that we have with new users of Rhino Mocks is exceptions masking. Removing the IDisposable means that it takes a bit longer to setup the mock repository, but I hope it will also encourage the recommended use of putting the setup & verification in the [SetUp] and [TearDown] methods.

Another change that I made was a bug fix for SetupResult not respecting IgnoreParameters(), which drove me crazy for a while. I’ve updated the documentation and the API docs to reflect the changes . As usualy, you can download or get the source.

time to read 1 min | 93 words

Yes, I know that I said that I'm not going to post today. But Jeff fixed a problem with Partial Mocks (couldn't call a method that had parameters). It's 0:45AM, and I'm releasing software... I think that I could be arrested for this. :-)

As usual,  you can download it, or access the source directly.

Thanks Jeff, and it really is turning into a daily build project :-D

time to read 1 min | 110 words

This time I actually did nothing for this release. Jeff Brown added support for Out & Ref parameters for Dynamic Proxy, and all I had left to do is hit the build button a couple of times and upload the stuff to the server.

This closes the next to last big problem with Rhino Mocks. The very last one has to do with generic methods, which I hope to be able to fix this week.

 You know the drill, you can download it, or access the source directly.

time to read 21 min | 4165 words

Here are a couple of interesting statistics about Rhino Mocks that I pulled from Cuyahoga. For this table, I merged the results of Rhino Mocks for .Net 2.0 and for .Net 1.1. You can see that the distribution of releases is pretty standard, a flurry of releases, pause, a flurry of release, etc. Rhino Mocks 2.4 is the most popular download, it was the version that added .Net 2.0 features.

Rhino Mocks 1.0 was based on EasyMock.Net, I abandoned the code base after it proved to be too hard to maintain and since it used remoting proxies under the cover, which weren't always compatible with the types being mocked.

Title # of downloads Date published
Rhino Mocks 2.5.2 0 22/11/2005
Rhino Mocks 2.5.1 28 20/11/2005
Rhino Mocks 2.5.0 9 19/11/2005
Rhino Mocks 2.4.2 144 22/10/2005
Rhino Mocks 2.4.1 71 12/10/2005
Rhino Mocks 2.4 272 26/8/2005
Rhino Mocks 2.3.5 42 25/8/2005
Rhino Mocks 2.3.4 87 19/8/2005
Rhino Mocks 2.3.3 150 18/8/2005
Rhino Mocks 2.3.1 76 17/8/2005
Rhino Mocks 2.3 102 16/8/2005
Rhino Mocks 2.2 127 12/8/2005
Rhino Mocks 2.1 67 11/8/2005
Rhino Mocks 2.0.7 113 31/7/2005
Rhino Mocks 2.0.6 57 30/7/2005
Rhino Mocks 2.0.5 63 29/7/2005
Rhino Mocks 2.0.4 85 19/7/2005
Rhino Mocks 2.0.3 57 18/7/2005
Rhino Mocks 2.0.2 109 15/7/2005
Rhino Mocks 2.0.1 75 13/7/2005
Rhino Mocks 2.0 113 2/7/2005

 

time to read 1 min | 166 words

Can someone please tell me why I almost always make Rhino Releases in bunches? The second I make a release, another thing pop up and I have to make another one.

Rhino Mocks 2.5 is barely out the door, and here I've another great feature.

Partial Mocks:

Partial mock is a mock object whose default action is to call the original method. Why is this useful?

It's useful because you may want to test an abstract method, and you don't want to write a class with a default implementation just for the tests. You can even set expectations on the methods that the class implement, so you can use it if you want to test that a method calls another method in the class.

 As usual, you can download it, or access the source directly.

I updated the API documentation

time to read 2 min | 349 words

I'm not really sure why, but of late, there has been a lot of traffic in the Rhino Mocks mailing list. Most of it about new features that people requested, and including some really good patches (thanks to Brian and Geert).

Here is a list of the new features:

  • You can now move a mock object back to record mode, this allows you to specify the interactions between the object in small steps every time.
  • You can now mock internal classes (.Net 2 only, and require your to specify: InternalsVisibleTo)
  • Rhino Mocks understand nullables, and act accordingly (before it would treat them as value types, and wouldn't accept/retun null for them).
  • Automatic handling of properties - you can now just say that you want a property to behave like a property, and it just work. It doesn't require implementing anything, so you can do that on interfaces as well. It even works with indexed properties.
  • Added a Do() handler that allows you to pass a delegate to control what will happen when a method match expectation. In essense, you can now use a delegate to decide what to do when a method is called (chagne the return value, throw, etc).

Bug fixes:

  • Rhino Mocks (and Dynamic Proxy) can now handle overloaded indexed properties properly. (try to say that ten times fast).
  • Disabled the trace output that was driving some people nuts.

I'm going to update the API documentation and the documentation about it soon.

As usual, you can download it, or access the source directly.

time to read 4 min | 653 words

Okay, so I've a new release out (any time I push out a release, I just know that I'll have to have a new one ready in a short time).

So, what is the story here?

Some time ago I added the ability to easily create stub objects and dynamic mocks. So you could do something like this:

IList list = mocks.DynamicMock<IList>();
SetupResult.For(list.Count).Return(5);
mocks.ReplayAll();
//use list, list.Count will always return 5, anything else will return 0 or null

This works fine and I use it daily in my current project, but it's a problem where you get cases where you have a property on your mocked object, let's take this code:

public int SetId(Something something)
{
  something.Prop = // Get the id
  return something.Prop;
}

Now, what do you need in order to connect the setter and getter in this case? Well, before 2.4.2 you needed to know about the value beforehand, which was not always possible. Here is how you do it on 2.4.2, however:

[Test]
public void TestSetId()
{
   Something something = mocks.DynamicMock<Something>();
   SetupResult.For(something.Prop).CallOriginalMethod(); // for the getter
   SetupResult.For(something.Prop = 0).CallOrigianlMethod(); // for the setter
   Assert.AreEqual(5, objUnderTest.SetId(Something));
}

What do we have here? We create the mock object, and then we setup two calls, one for the property getter and another for the setter (the syntax may be a little weird for the setter, but it's actually the best syntax that we could think of). We tell Rhino that when it get a call to get_Prop, it should just call the original method on the object, and the same for set_Prop. That is a nice way to do it, I think.

Caveats:

  • There is no either/or with this, it doesn't attempt to match arguments to see if it should call the original method or not, it just does.
  • You can't set repeats or exceptions or return values, any call for this method will go to the original object.
  • You can't use it on interfaces or abstract methods, since there isn't a method there to pass it to.

FUTURE POSTS

No future posts left, oh my!

RECENT SERIES

  1. API Design (10):
    29 Jan 2026 - Don't try to guess
  2. Recording (20):
    05 Dec 2025 - Build AI that understands your business
  3. Webinar (8):
    16 Sep 2025 - Building AI Agents in RavenDB
  4. RavenDB 7.1 (7):
    11 Jul 2025 - The Gen AI release
  5. Production postmorterm (2):
    11 Jun 2025 - The rookie server's untimely promotion
View all series

Syndication

Main feed ... ...
Comments feed   ... ...