4

In the solution explorer I have two separate projects , one is the main project and other is the unit test project , Now the method to be tested is in the main project ,so is the web.config.

There is a TestMethod in the Unit test project, this method calls the in the main project , and also takes one parameter which has the web.config location it uses that to get the value based on some key. I have tried to copy this in the app.config in the unit test project in both cases I am getting the error

The application relative virtual path '~/UnitTestProjectAppsPortal/App.config' cannot be made absolute, because the path to the application is not known.

The method to be tested has to remain in the main project and the TestMethod in the UnitTest Project will pass the web.config location as a parameter to it.

Now what should be done to remove this exception.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
ROHIT
  • 51
  • 1
  • 1
  • 4
  • You have to prepare your own VirtualPathProvider derived class where you can resolve "~" to proper root (if any...). Before start tests just register it with HostingEnvironment.RegisterVirtualPathProvider(). – Adriano Repetti Sep 04 '15 at 12:38
  • can you provide some sample code pls – ROHIT Sep 04 '15 at 16:07
  • This SO answer shows how to implement your own provider for testing. https://stackoverflow.com/questions/17170889/unit-testing-method-converting-mvc-view-to-string-using-view-render-method – AlignedDev Nov 09 '17 at 17:07

0 Answers0