【发布时间】:2017-02-27 16:01:26
【问题描述】:
我想检查是否使用正确的错误列表调用了以下方法。
void ShowErrorCollection(string description, List<string> errors);
我的 fake it easy 配置看起来像这样,我正在尝试将给定列表保存到 lokal 字段:
A.CallTo(() => dataPresenter.ShowErrorCollection(A<string>.Ignored, A<List<string>>.Ignored))
.Invokes((string _, List<string> givenErrors) => this.errors = givenErrors);
那行不通。错误集合始终为空,我没有得到集合。我做错了什么?
编辑:
这似乎是我的代码中的一个错误。我写了以下测试,它是绿色的:
[Test]
public void name()
{
var errorHandler = A.Fake<IErrorHandler>();
A.CallTo(() => errorHandler.ShowErrorCollection(A<string>.Ignored, A<List<string>>.Ignored))
.Invokes((string _, List<string> givenErrors) => this.errors = givenErrors);
errorHandler.ShowErrorCollection("bla", new List<string>() {"Hallo"});
this.errors.Should().NotBeEmpty();
this.errors.First().Should().Be("Hallo");
}
【问题讨论】:
-
你能告诉我们你的单元测试吗?
-
您的问题解决了吗?
-
是的,我做到了。这是我的代码中的错误。
标签: c# mocking fakeiteasy