Invalid call, the last call has been used or no call has been made

橙三吉。 提交于 2019-12-01 02:19:23
George Mauer

Never used PropertyBehavior before, but is this the syntax you're looking for?

form.Stub(x=>x.OKButtonEnabled).PropertyBehavior()

Rhino Mocks works completely through extension methods now. The only static call I every make any more is to MockRepository.GenerateStub.

You mentioned using a stub instead of a mock but before you go changing it I'd note that strangely, I get the Invalid Call exception when I used GenerateStub but not when I use GenerateMock.

View = MockRepository.GenerateStub<IAddressView>();
View.Stub(v => v.Message).PropertyBehavior();

This throws the Invalid call exception and yes, IAddressView.Message does have a getter and setter.

I received this error when I tried to set an expectation on a non-virtual method.

mockedObject.Expect(a => a.NonVirtualMethod()).Returns(null);

The error went away when I made NonVirtualMethod virtual.

I think you have to do MockRepository.ReplyAll() after you set up all expectations and before you start using this mock. So my guess in your case is that you have to move the Expect.Call line before mediator = new AddAddressMediator(form);, and stick the reply all right after that:

[TestInitialize()]
public void MyTestInitialize()
{
    form = MockRepository.GenerateMock<IAddAddressForm>();
    // Make the properties work like a normal property
    Expect.Call(form.OKButtonEnabled).PropertyBehavior();

    //I tried this too.  I still get the exception
    //SetupResult.For(form.OKButtonEnabled).PropertyBehavior();

    MockRepository.ReplyAll();
    mediator = new AddAddressMediator(form);



}

I ran into this issue when I was trying to call an internal property (getter only) on an object in C#. In this case, adding .PropertyBehavior() did not help.

My solution was to extract the logic out of the property and into an internal method which I then injected dependencies into this method (as parameters).

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