Thanks to user 0100110010101.
This worked for me, and here I had a problem writing test code for the code below:
var currentUrl = Request.Url.AbsoluteUri;
And here are the lines that solved the problem
HomeController controller = new HomeController(); //Mock Request.Url.AbsoluteUri HttpRequest httpRequest = new HttpRequest("", "http://mySomething", ""); StringWriter stringWriter = new StringWriter(); HttpResponse httpResponse = new HttpResponse(stringWriter); HttpContext httpContextMock = new HttpContext(httpRequest, httpResponse); controller.ControllerContext = new ControllerContext(new HttpContextWrapper(httpContextMock), new RouteData(), controller);
May be useful for others.
Chandan Kumar Jun 30 '15 at 12:02 2015-06-30 12:02
source share