Hi,
I have implemented a small web application with the MVC Framework and now I'm trying to test the solution with Unit tests and Rhino.Mocks (I know that is not the TDD approach ...
). Everything is fine, I have test cases for my model and for my controller with mock objects. But how can I test the ViewPage? I have tried to do this and to mock the necessary objects, but I have always this exception:
Test method MVC_Framework_ExampleTests.DetailTest.Page_LoadTest threw exception: System.NullReferenceException:
System.Web.UI.Page.SetIntrinsics(HttpContext context, Boolean allowAsync)
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
System.Web.UI.Page.ProcessRequest(HttpContext context)
System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext)
And this is the content of the test method:
Detail target = new Detail();
using (_mockRepository.Playback())
{
ViewContext testViewContext = new ViewContext(_customerCtrl.ControllerContext, "Detail", string.Empty, TestCustomer, new TempDataDictionary(_customerCtrl.ControllerContext.HttpContext));
target.RenderView(testViewContext);
}
I'm using the extension methods from Scott to fake my controllerContext.
It is possible to test the view and to check if the fields have the correct values from the data model?
Bye,
Marc André