开发者

RhinoMock says: "Type doesn't match the return type"

I've written such 开发者_JAVA百科class:

public class A
{
    public virtual int LowLimit { get; set; }

    internal virtual bool CheckLimit(int measurement)
    {
        return LowLimit <= measurement;
    }
}

And a test for it:

MockRepository mocks = new MockRepository();
var limit = mocks.StrictMock<A>();

Expect.Call(limit.CheckLimit(2)).Return(true).Repeat.Once();
mocks.ReplayAll();
limit.CheckLimit(2);
mocks.VerifyAll();

And it fails with: System.InvalidOperationException : Type 'System.Boolean' doesn't match the return type 'System.Int32' for method 'A.get_LowLimit();'

But when I replace internal keyword for CheckLimit method to public, it works ok. Why it is behaiving like that?


If you're using an external library (StrictMock), then it can't access any of your internal methods.

It looks like the StrictMock implementation is trying to use A's CheckLimit, but because it can't find an implementation probably uses its own implementation which uses A's LowLimit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜