【发布时间】:2015-10-03 19:55:34
【问题描述】:
在 Visual Studio 2013 Community Edition 中使用 NUnit 2.6.4 和 FakeItEasy 1.25.2 对 C# 代码进行单元测试
以下测试片段按预期执行
[Test]
public void test_whatIsUpWithStreamRead()
{
Stream fakeStream = A.Fake<Stream>();
byte[] buffer = new byte[16];
int numBytesRead = fakeStream.Read(buffer, 0, 16);
Assert.AreEqual(0, numBytesRead);
}
但是,一旦我用 CallTo/Returns() 或 ReturnsLazily() 语句装饰我的假货...
[Test]
public void test_whatIsUpWithStreamRead()
{
Stream fakeStream = A.Fake<Stream>();
A.CallTo(() => fakeStream.Read(A<byte[]>.Ignored, A<int>.Ignored, A<int>.Ignored)).Returns(1);
byte[] buffer = new byte[16];
int numBytesRead = fakeStream.Read(buffer, 0, 16);
Assert.AreEqual(1, numBytesRead);
}
fakeStream.Read() 抛出 System.InvalidOperationException 并显示以下消息:
“指定的 out 和 ref 参数值的数量与调用中的 out 和 ref 参数的数量不匹配。”
来自FakeItEasy.Configuration.BuildableCallRule.ApplyOutAndRefParametersValueProducer(IInterceptedFakeObjectCall fakeObjectCall),这对我来说似乎很奇怪,因为Stream.Read() 没有任何输出/引用参数。
这是我应该在https://github.com/FakeItEasy 报告的错误,还是我遗漏了什么?
谢谢
【问题讨论】:
-
我不确定你是否看到了更新,但我们相信这个问题会在 FakeItEasy 1.25.3 中得到解决。
标签: c# fakeiteasy