Ricardo Sanchez
Ricardo Sanchez

Reputation: 6289

How can I make an ASP.NET MVC site as unit testable as an ASP.NET Web Forms site?

also, what day is today and why do I have an ugly unicorn as my avatar ;-)

Upvotes: 3

Views: 154

Answers (2)

hollystyles
hollystyles

Reputation: 5039

You have a unicorn because today is April Fools Day and Jeff is a sucker for that kind of thing.

Some would say an MVC site is more testable than a ASP.NET Forms one. You make it testable by adding tests I guess.

Upvotes: 1

tvanfosson
tvanfosson

Reputation: 532645

First, you have to use sealed classes and singletons everywhere -- none of these wrapper classes with virtual methods that can be mocked out or anything. Next, and this is important, you have to use Reponse.Write instead of returning views. It also helps to serialize the contents of all of the form parameters, encrypt them, and store them in a hidden input on the page -- then always check the new parameters against the old ones to see which things changed. Using this way you can generate these things called "events" -- they're just like button clicks and selects on Windows Forms. These are much easier to understand and simulate in your unit tests.

Upvotes: 6

Related Questions