2

This question is very similar to 674458 but I really want to use the AutoMockContainer in my unit tests. I cannot figure out how to setup up my context.

Has anyone been able to unit test a controller that calls Url.Action using the AutoMockContainer?

Community
  • 1
  • 1
JohnRudolfLewis
  • 1,692
  • 1
  • 18
  • 33
  • Your controller shouldn't be calling Url.Action at all, IMHO. That's for views. – Craig Stuntz May 28 '09 at 18:27
  • 4
    @Craig, Normaly, you are right. But consier for a moment a controller method that returns a JsonResult, that among other things, includes a url of another ajax method that the browser is supposed to call. – JohnRudolfLewis May 29 '09 at 04:33
  • I think I would probably do this either by subtyping JsonResult or writing custom serialization for the model I pass to Json. – Craig Stuntz May 29 '09 at 18:43
  • And what if you want to send an email that has a link to the website? How do you test this link? – VinnyG Nov 29 '10 at 02:56
  • It's a perfectly valid question, there are many reasons for wanting to do this. Have a look at this: http://codeswordsman.wordpress.com/2011/07/22/unit-testing-controllers-that-call-url-action-and-verify-correct-url/#comment-31 – Nick Mar 08 '13 at 15:37

0 Answers0