In my controller’s action I am doing:
string a = Url.Action(...);
I’m using nunit and Moq (and Mvc 2)
How could I stub the call to Url.Action to return some string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t mock concrete classes that don’t have a default Constructor with Moq (I’m assuming that Url is an instance of
UrlHelper). You have two options here:(1) Check out Moles as an alternative/supplementary mocking framework
(2) Write a wrapper class for UrlHelper methods that implements an interface and you can then mock the wrapper for clients.