【发布时间】:2016-05-31 02:03:59
【问题描述】:
我有以下测试:
[Fact]
public void StartProgram_CallsZoneProgramStart()
{
var zone = A.Fake<Zone>();
zone.StartProgram();
A.CallTo(() => zone.ZoneProgram.Start(null, A.Dummy<ActionBlock<InterruptInfo>>())).MustHaveHappened(Repeated.Exactly.Once);
}
它正在创建一个ActionBlock<InterruptInfo> 类型的虚拟对象,它被传递到 MustHaveHappened 调用中。 zone.StartProgram 肯定调用了 zone.ZoneProgram.Start 方法,但是 FakeItEasy 看不到这个调用。它返回以下错误消息:
Assertion failed for the following call:
ZoneLighting.ZoneProgramNS.ZoneProgram.Start(<NULL>, ActionBlock\`1 Id=1)
Expected to find it exactly once but found it #0 times among the calls:
1: ZoneLighting.ZoneProgramNS.ZoneProgram.Start(inputStartingValues: Faked ZoneLighting.ZoneProgramNS.InputStartingValues, interruptQueue: ActionBlock`1 Id=2)
2: ZoneLighting.ZoneProgramNS.ZoneProgram.Start(inputStartingValues: <NULL>, interruptQueue: ActionBlock`1 Id=2)
从错误消息中可以看出,正在比较的 ActionBlock 上的 ID 不同(1 和 2),这就是它无法看到调用的原因。我的问题是,为什么虚拟 ActionBlock 的 ID = 1?我认为作为一个虚拟对象,它不应该有任何具体的细节,如 ID 等。这是因为泛型类型不能被虚拟化吗?
我在这里看到了类似的东西:https://github.com/FakeItEasy/FakeItEasy/issues/402
但我无法弄清楚这是否在谈论同一件事。任何帮助将不胜感激。
【问题讨论】:
标签: c# .net mocking xunit.net fakeiteasy