RhinoMock 说:“类型与返回类型不匹配”
我写了这样的课程:
public class A
{
public virtual int LowLimit { get; set; }
internal virtual bool CheckLimit(int measurement)
{
return LowLimit <= measurement;
}
}
并对它进行了测试:
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();
它失败了: System.InvalidOperationException:类型“System.Boolean”与方法“A.get_LowLimit();”的返回类型“System.Int32”不匹配
但是当我将 CheckLimit 方法的内部关键字替换为 public 时,它工作正常。 为什么它会有这样的行为?
I've written such 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用外部库 (StrictMock),则它无法访问您的任何内部方法。
看起来 StrictMock 实现正在尝试使用 A 的 CheckLimit,但因为它找不到实现,可能使用它自己的实现,该实现使用 A 的 LowLimit。
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.