I use this helper method to turn the PartialViewResult into a string and return it as Json - http://www.atlanticbt.com/blog/asp-net-mvc-using-ajax-json-and-partialviews/
My problem is that I use Moq to mock the controller, and whenever I run the unit test, which uses this RenderPartialViewToString () method, I get the link "Object not installed to object instance". error in ControllerContext.
private ProgramsController GetController() { var mockHttpContext = new Mock<ControllerContext>(); mockHttpContext.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("test"); mockHttpContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
This returns the proxy controller, and maybe this is the reason I got this error. Any idea how to check this?
Many thanks.
unit-testing asp.net-mvc moq asp.net-mvc-2
Saxman
source share