im unit testing my home controller. This test worked fine until I added a new feature which saves images.
The method that’s causing the issue is this below.
It is sometimes handy to just mock the call to server.MapPath. This solution works for me using moq. I only mock the base path to the application.
_contextMock = new Mock();
_contextMock.Setup(x => x.Server.MapPath("~")).Returns(@"c:\yourPath\App");
_controller = new YourController();
_controller.ControllerContext = new ControllerContext(_contextMock.Object, new RouteData(), _controller);
In your controller you can now user Server.MapPath("~").