views:

1597

answers:

2

... absolutely nothing?

What part of the puzzle does it fill for ASP.NET WebForms and ASP.NET MVC respectively?

Can you somehow create a ASP.NET * base-application which uses System.Web.Abstractions so it can be used in both kinds of ASP.NET-web applications?

In that case, how did they retro-fit the classes in System.Web.Abstractions back into ASP.NET WebForms?

You can't new up objects from the namespace, so it can't be used for mocking, can it?

Update: Sorry for not being clear on that I know the problem with testing of HttpContext and other build-it ASP.NET-objects. But thanks for good explanations anyway.

+8  A: 

It is indeed for mocking. - HttpContext is a sealed class and cannot be (easily) mocked. HttpContextBase is not sealed and I believe it's methods are virtual, making mocking much easier.

While you can't new-up an instance of HttpContextBase (say, for use in WebForms), you can get an instance via:

var ctx = new HttpContextWrapper(HttpContext.Current);
Troy
+10  A: 

The namespace contains types that are designed to wrap ASP.NET's core classes (such as HttpSessionState).

What, you want to know why?

Many of these core ASP.NET classes are sealed or static, making it impossible to break dependencies between them and your code. THAT means you can't mock these core dependencies, making it much harder to test your ASP.NET code. So, instead of directly manipulating the HttpResponse directly in code, you manipulate it via the HttpResponseWrapper, which, during test time, you can stub or mock out to control how the HttpResponse object behaves.

If you've ever thought about creating these wrappers, or have implemented one or two of them before, you'd know that there's lots of work wrapped up in that namespace, and I, for one, am glad they did it.

Will