Drop in the Bucket
One coder in the sea of s/w knowledge

ASP.NET MVC Preview 4: A few things left to do

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.


Feedback

# re: ASP.NET MVC Preview 4: A few things left to do

Have you pings anyone on the forums or SHanselman/Haacked about this? 7/25/2008 11:41 PM | Eric

# re: ASP.NET MVC Preview 4: A few things left to do

No, I haven't yet I'm afraid. The forums are probably the best place for this comment, as it's likely "by design" (at least at the momment). Thank you for the comment, I'll do that shortly. 7/29/2008 11:10 PM | Jeff

# re: ASP.NET MVC Preview 4: A few things left to do

Follow up: The forum post has already been made by someone that got confused like me. http://forums.asp.net/p/1286997/2478582.aspx

7/31/2008 12:18 AM | Jeff

Comments have been closed on this topic.