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