Tuesday, July 22, 2008 11:50 PM
I decided, I'd try out Preview 4 tonight. In honest to goodness TDD form, I wrote the following test:
13 [TestFixture]
14 public class EmployeeControllerTests
15 { 16 [Test]
17 public void List_Should_Render_View_Of_Employees()
18 { 19 var controller = new EmployeeController();
20 var result = controller.List() as ViewResult;
21 Assert.IsNotNull(result);
22 Assert.AreEqual("List", result.ViewName); 23 }
24 }
The code for the controller is:
9 public class EmployeeController : Controller
10 { 11 public ActionResult List()
12 { 13 return View();
14 }
15 }
The test fails. The name of the view is null (assertion on line 22 of the test method). Why in the name of all that is ScottGu would this basic test fail? In the actual view, when rendered through the view engine, the view name is "List" as expected (that's the job of the parameter-less call to the controller's View method).
Testing of the controller in isolation is still not fully baked. There still seems to be some disconnect in one of the fundamental goals of the framework: make it easy for Morts like me to write testable code.