protected void Page_Load(object sender, EventArgs e)
{
this.LoadImportantActionsToPage();
}
All I want to do is write a unit test that tests that LoadImportantActionsToPage, which is private is called from Page_Load. I have no liberty to use MVC or MVP but I need to test it somehow.
Perhaps mocking th page?
Can it be done and could someone please give me an example as I can’t find any on the web.
You’ve got no chance with WebForms, as far as I’m concerned, particularly when it comes to mocking things like the HttpContext and ‘web’ stuff. With MVC you do have the capability to do this, with a little prior knowledge and understanding.
Switch to MVC3, adopt Ninject, StructureMap or Castle for IoC and constructor DI and use a mocking framework like Rhino Mocks or Moq, then you’ll be able to write testable code and create worthwhile tests.
A quick google revealed a working example: http://buildstarted.com/2010/08/24/dependency-injection-with-ninject-moq-and-unit-testing/
Good luck