【发布时间】:2014-02-04 20:29:35
【问题描述】:
我试图在一个模拟接口上设置一个期望,该接口从它的一个方法返回一个函数。不幸的是,在投射第二个返回类型时,它看起来像 rhino 模拟窒息,或者至少这是我从异常中得到的。异常是从 Expect 调用中引发的。
public interface IFuncTest
{
Func<int> Generate(int num);
}
[Test]
public void MyTest()
{
var myMock = MockRepository.GenerateStrictMock<IFuncTest>();
// first expectation will succeed
myMock.Expect(mm => mm.Generate(42)).Return(() => 6)
// second expectation will throw inside the lambda passed to Expect
myMock.Expect(mm => mm.Generate(4000)).Return(() => 9)
}
期望的顺序无关紧要。
异常文本:
Unable to cast object of type 'Castle.Proxies.ProxyDelegate_Func`1_1Proxy5f00ec19448d4e4c96f5d6df12f2c87d' to type 'System.Func`1[System.Int32]'.
at Castle.Proxies.IFuncTest`1Proxy2cc837d117f745dfb24033b9bf7cb0f4.IFuncTest`1.Generate(Int32 tee)
at Tests.Tests.<MyTest>b__9(IFuncTest`1 mm) in Tests\Tests.cs:line 167
at Rhino.Mocks.RhinoMocksExtensions.Expect[T,R](T mock, Function`2 action)
at Tests.Tests.MyTest() in Tests\Tests.cs:line 167
关于为什么会出现这种情况或如何解决它的任何想法?
【问题讨论】:
-
您似乎遇到了与此处所述相同的问题:github.com/ayende/rhino-mocks/issues/6
-
有意思,好像还是不行?我尝试在github.com/alaendle/rhino-mocks/commit/… 中运行测试,但测试失败。我不知道诺比是否从他所说的中找到了解决方案。
-
更多搜索结果:stackoverflow.com/questions/10076819/… 但没有修复
标签: c# unit-testing mocking rhino-mocks