Why do Rhino Stubs allow me to set expectations on them?

不想你离开。 提交于 2019-12-10 22:57:42

问题


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?


回答1:


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...)



来源:https://stackoverflow.com/questions/37305338/why-do-rhino-stubs-allow-me-to-set-expectations-on-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!