Mocking with Rhino Mocks

Friday, 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: .net, tdd
Comments (1)
Rob Rob 5/19/2008 12:31 AM

Just to follow up, I posted to the Rhino Mock news group and got that everything is working as advertised. You can follow along here:

http://groups.google.com/group/RhinoMocks/browse_thread/thread/b4718f2b3a000943