I have a controller action that uses a static variable on Global.asax which is filled in by Application_Start....
here is the simple sample code
string url = VirtualPathUtility.Combine(MvcApplication.BaseU, "/geturl");
But of course in a Test when i am testing my controller the MvcApplication.BaseU is NULL
as its not called and filled in by Application_Start from the global.asax
What is the best option for doing this c开发者_C百科orrectly?
Any ideas really helpful
I have a controller action that uses a static variable on Global.asax which is filled in by Application_Start
That's bad. You could refactor your code so that your controller takes this value as constructor parameter (constructor injection) and then configure your DI framework to pass the proper value. Now in your unit test it is a simple matter of passing a mocked value for the test.
精彩评论