1

In my project we want to mock UrlHelper to test controller's actions. I found code that allows me to do it, unfortunately it's written in Moq: link

There is a line, which i don't know hot to replace in FIE:

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

This throws System.NotImplementedException:

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

This returns empty string from Url.Action:

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

When I remove that line from code, Url.Action also returns empty string.

I don't want to use 2 different mock libraries, but I don't see any possibility to replace it. MvcMockHelpers which uses Moq works without problem.

1 Answers1

4

According to the documentation, ReturnsLazily will do the equivalent:

A.CallTo(() => response.ApplyAppPathModifier(A<string>.Ignored))
 .ReturnsLazily((string s) => s);
Blair Conrad
  • 233,004
  • 25
  • 132
  • 111
Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88