My controller using following line to assign url to the session
this.Session["MyUrl"] = Request.Url.ToString(); on unit test project side I setup controller like this
var fakeHttpContext = new Mock<HttpContextBase>(); var controllerContext = new Mock<ControllerContext>(); controllerContext.Setup(t => t.HttpContext).Returns(fakeHttpContext.Object); this.controller.ControllerContext = controllerContext.Object; controllerContext.SetupGet(x => x.HttpContext.Request.Url).Returns(new Uri("/Home/Details", UriKind.Relative)); on this last line I'm trying to setup Request.Url in order to pass the value I expect on the controller side.
All I'm getting as a result on Request.Url is '/Home/Details'.
Do I need to mock whole Url object inside request in order to get this to work?
Update: I setup session object in httpcontext setup
fakeHttpContext.Setup(x => x.Session["MyUrl"]).Returns("/Home/Details"); but still experiencing the same issue.
/Home/Detailsin your mock. What value do you expect to get in the controller?new Uri("http://example.com/Home/Details").