Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD with ASP.NET MVC 1.0

Where can I find a good tutorial on TDD with ASP.NET MVC 1.0? I'd prefer a video tutorial but a text tutorial would be fine as well. I have a new project starting soon and I want to start off on the right foot.

like image 797
Mike Avatar asked Apr 24 '09 02:04

Mike


People also ask

How is TDD implemented in ASP.NET MVC?

Under Installed Templates, open the Visual C# node, select Data, and then select the ADO.NET Entity Data Model template. In the Name box enter, ContactModel and then click Add. The Entity Data Model Wizard window is displayed. Under What should the model contain, select Generate from database and then click Next.

Does MVC support TDD?

One of the greatest advantages of ASP.NET MVC is the support of testability, which enables to Test-Driven Development (TDD) in an easy manner.

What is TDD in asp net?

TDD means writing tests to implement a requirement and continuously iterate through RED GREEN and REFACTOR cycles. Advantages. TDD makes you think with the needed API from the beginning. You need to think about what classes, properties, API's are needed. This will usually lead to great API design.


3 Answers

The Storefront Videos from ASP.NET are a must watch series.

like image 83
bendewey Avatar answered Oct 06 '22 08:10

bendewey


Any tutorial on TDD will be helpful for MVC. I've been doing TDD for sometime and found that it was a natural transition in MVC. There are a few peculiarities that I have found that need to be addressed.

  1. You often need to mock up the HttpContext, which means that you need to assign a ControllerContext to the controller after it's created as that's the only way to inject the mock. The context will be used to provide the Session, Request, and Response objects in the controller (also mock them). New HttpContextBase, HttpSessionStateBase, ... classes make this much easier to do.

  2. Because of (1), invest some time in putting together some helper classes in a separate class library that can be used by all of your test projects. These helper classes should contain methods that provide configurable (or multiple methods to provide specific configurations) of the mocked contexts. This will help keep your tests compact.

  3. Use and assign a ValueProvider for testing methods that accept parameters if you aren't using ModelBinding (with corresponding parameters in the signature) for a controller action. This will allow you to use TryUpdateModel/UpdateModel without adding code to your controller to get data from the Request into those methods.

  4. Use a mocking framework -- if that isn't obvious from above. It will be so much easier to write your tests if you mock out the dependencies. Writing your own mocks, IMO, is not worth it, though I know others don't share that opinion. I guess this isn't unique to MVC, but I thought I'd mention it.

  5. Set up a separate set of tests that use reflection to test that appropriate attributes with appropriate properties are getting set on your methods. MVC makes heavy use of attributes for security and other cross-cutting aspects. These need to be tested as well.

like image 33
tvanfosson Avatar answered Oct 06 '22 09:10

tvanfosson


Check out here. MVC store front is highly recommended.

like image 30
J.W. Avatar answered Oct 06 '22 08:10

J.W.