【问题标题】:FakeItEasy - cannot fake ApplyAppPathModifier from HttpResponseFakeItEasy - 不能从 HttpResponse 伪造 ApplyAppPathModifier
【发布时间】:2014-05-21 13:11:39
【问题描述】:

在我的项目中,我们想模拟 UrlHelper 来测试控制器的操作。我找到了允许我这样做的代码,不幸的是它是用最小起订量编写的:link

有一条线,我不知道在 FIE 中可以热替换:

response.Setup(s => s.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s);

这会引发 System.NotImplementedException:

A.CallTo(() => response.ApplyAppPathModifier(A<string>.Ignored)).CallsBaseMethod();

这会从 Url.Action 返回空字符串:

A.CallTo(() => response.ApplyAppPathModifier(A<string>.Ignored)).Returns("");

当我从代码中删除该行时,Url.Action 也会返回空字符串。

我不想使用 2 个不同的模拟库,但我看不出有任何替换它的可能性。使用 Moq 的 MvcMockHelpers 没有问题。

【问题讨论】:

    标签: mocking moq fakeiteasy


    【解决方案1】:

    根据documentationReturnsLazily 会做同样的事情:

    A.CallTo(() => response.ApplyAppPathModifier(A<string>.Ignored))
     .ReturnsLazily((string s) => s);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      相关资源
      最近更新 更多