I have an MVC6 controller with the following line of code:
string link = Url.Action("Profile", "Account");
When I unit test this controller, that line fails with an error:
Value cannot be null.
Parameter name: helper
I don't really want to mock the Url.Action response plus I don't think I can because it's an extension method (static method). I want it to run and return like it would in a web environment.
What do I need to do when instantiating the controller in my unit test so that I the line above will execute as expected?
I see that I can do something like this in my unit test:
controller.Url = new UrlHelper(new ActionContextAccessor(), new DefaultActionSelector(...));
But I can't figure out what is needed to setup the ActionContextAccessor and/or the DefaultActionSelector (which requires more types that I'm not sure where to obtain or how to instantiate).
Has anyone already done this?
Thanks, Kevin