2

This question clarifies the conceptual differences between mocks and stubs in Rhino: What are the differences between mocks and stubs on Rhino Mocks?

However I'm left confused why Rhino Stub objects provide methods such as .Expect and .VerifyAllExpectations() when these appear to do nothing at all. Why do mock/stub objects seemingly provide the same interface?

It's making me think I've missed something fundamental - or is it just an implementation quirk?

Community
  • 1
  • 1
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

1 Answers1

2

The reason for this behavior is based on IntelliSense limitation(on extension methods) + Rhinomocks design( + bug on the asserts) as I explained here.

The following example shows that the Expect method has nothing more than Stub method on stubs.

public class Foo
{
    public virtual string DoSomthing()
    {
        return String.Empty;
    }
}

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {

        var f = MockRepository.GenerateStub<Foo>();

        f.Expect(x => x.DoSomthing())
         .Return("2");

        f.VerifyAllExpectations();

    }
}

If you'll execute the above example you'll see that the test won't fail(Although DoSomthing was never called...)

Community
  • 1
  • 1
Old Fox
  • 8,629
  • 4
  • 34
  • 52