【发布时间】:2013-07-29 21:43:40
【问题描述】:
我想断言没有发送任何东西,也就是没有调用_dispatcher.Dispatch。
interface 被伪造/嘲笑:
interface IDispatcher
{
void Dispatch<T>(T command,
Stuff stuff = null,
TimeSpan? timeout = null,
int? retries = null) where T : Command;
}
在测试体中:
_dispatcher = A.Fake<IDispatcher>();
// do stuff
A.CallTo(() => _dispatcher.Dispatch(A<Command>.Ignored,
A<Stuff>.Ignored,
A<TimeSpan?>.Ignored,
A<int?>.Ignored)).MustNotHaveHappened();
当发送了一些东西时,这个测试通过。
有什么想法吗?我是否错误地使用了 FakeItEasy?
【问题讨论】:
-
您很可能设置了错误的 CallTo()。例如:您确定要将 A
._ 而不是 A ._ 作为第二个参数吗? -
你试过反过来吗? .MustHaveHappened() 是否在发送某些东西时工作?我猜不会。
-
你确定你真的在打电话给
Dispatch<T>吗?另外,DispatchWork和Dispatch<T>是两种不同的方法。 -
@D.R.更新了问题。那是一个错字。
-
@PoweredByOrange 更新了问题——错字。
标签: c# .net unit-testing xunit fakeiteasy