Using Rhino Mocks 3.6, given the code below I would expect the AssertWasCalled assertion to pass, but it does not. Instead there is the failed assertion message:
“Rhino.Mocks.Exceptions.ExpectationViolationException:
IBar.set_Model(7); Expected #1, Actual #0.”
Trying IgnoreArguments() does not change the result, but changing the IBar property to a method and asserting the method is called with the argument does work.
What am I missing here?
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
public interface IFoo { }
public interface IBar { int Model { get; set; } }
public class Bar : IBar { public int Model { get; set; } }
public class Foo : IFoo
{
public void MyMethod(IBar bar)
{
bar.Model = 7;
}
}
[TestClass]
public class TestFoo
{
[TestMethod]
public void MyMethod()
{
var foo = new Foo();
var mockBar = MockRepository.GenerateStub<IBar>();
foo.MyMethod(mockBar);
mockBar.AssertWasCalled(b => b.Model = 7);
}
}
If you are stubbing your bar object, then you should make assertion on value of property
If you want to test expectation, you should generate mock instead of stub
Difference between stubs and mocks: