I went with this solution:
Stubbing a property twice with rhino mocks
but even when I change both of my Stubs to .Expect, the first Expect is winning out:
Here's the recreation in mono:
using System;
using NUnit.Framework; using Rhino.Mocks;
namespace FirstMonoClassLibrary { [TestFixture] public class TestingRhinoMocks { Sut _systemUnderTest; IFoo _dependency;
[SetUp]
public void Setup()
{
_dependency = MockRepository.GenerateMock<IFoo>();
_dependency.Expect(x => x.GetValue()).Return(1);
_systemUnderTest = new Sut(_dependency);
}
[Test]
public void Test()
{
_dependency.Stub(x => x.GetValue()).Return(2);
var value = _systemUnderTest.GetValueFromDependency();
Assert.AreEqual(2, value); // Fails says it's 1
}
}
public interface IFoo
{
int GetValue();
}
public class Sut
{
private readonly IFoo _foo;
public Sut(IFoo foo)
{
_foo = foo;
}
public int GetValueFromDependency()
{
return _foo.GetValue();
}
}
}