且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我不能在变量中捕获FakeItEasy期望?

更新时间:2023-10-05 14:31:16

答案在文件中总是放置在A.CallTo中的忽略和

The answer is in the docs at Always place Ignored and That inside A.CallTo:


忽略(和 _ )和那个匹配器必须放在 A.CallTo 调用。这是因为这些特殊约束方法不返回实际的匹配器对象。他们告诉FakeItEasy如何通过被触发的特殊事件匹配参数,然后调用约束方法。 FakeItEasy只侦听 A.CallTo 的上下文中的事件。

The Ignored (and _) and That matchers must be placed within the expression inside the A.CallTo call. This is because these special constraint methods do not return an actual matcher object. They tell FakeItEasy how to match the parameter via a special event that's fired then the constraint method is invoked. FakeItEasy only listens to the events in the context of an A.CallTo.

我很惊讶测试失败,但是。你使用什么版本?从FIE 2.0.0开始,使用那个就像你一样应该抛出一个异常

I'm surprised the "test fails", though. What version are you using? As of FIE 2.0.0, using That as you did should throw an exception like

System.InvalidOperationException : A<T>.Ignored, A<T>._, and A<T>.That
can only be used in the context of a call specification with A.CallTo()