Mocking with Rhino Mocks

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.

Print | posted on Friday, May 16, 2008 3:29 PM

Feedback

# re: Mocking with Rhino Mocks

left by Rob at 5/18/2008 5:31 PM Gravatar
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
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: