Mocking with rhino mocks follow up

by May 23, 2008 01:11 AM

This is just a quick follow up to my Mocking with Rhino Mocks post.

You can see the entire thread here, but the essence of it is this.

DynamicMock creates a mock where all unexpected calls are ignored with no error. So, if we were to create a dynamic mock and then set an expectation that a method on it is called twice, there would be a requirement for two calls, but a third cal would just be ignored rather than cause an error.

If we absolutely want the behavior of an exact number of calls, then use CreateMock instead of DynamicMock. Nice and simple solution :)

Tags: ,

Mocking with Rhino Mocks

by May 16, 2008 10:29 PM

Ok, myself and a couple of colleagues spent a ton of time today scratching our heads because of an odd behavior in Rhino Mocks. Basically, we set an expectation, set the expectation to repeat only once, and then were surprised to see a passing test when we knew the actual code was calling the expectation too many times. So we created the below example. The test in the example should fail, but it passes.

using NUnit.Framework;
using Rhino.Mocks;
namespace UnitTests
{
public interface IMyTestInterface
{
void MyTestMethod();
}
[TestFixture]
public class RepeatTests
{
[Test]
public void Test()
{
var mockery = new MockRepository();
var myMock = mockery.DynamicMock<IMyTestInterface>();
using (mockery.Record())
{
myMock.MyTestMethod();
LastCall.Repeat.Once();
}
using (mockery.Playback())
{
myMock.MyTestMethod();
myMock.MyTestMethod();
}
}
}
}

Now to do some searching and querying to figure out what we're doing wrong.

Tags: ,