views:

56

answers:

2

I have a legacy app that I am trying to build some testing into.

I have some tests that require the HttpContext.Current.User

Is there a way to mock this, or simply login a user on the fly?

A: 

HttpContext.User is of type IPrincipal. You can mock it by assigning to it any IPrincipal object, including any CustomPrincipal object.

Justice
A: 

I don't now how much you can refactor your legacy application. If you have .NET 3.5, you can use HttpContextWrapper class that is part of System.Web.Abstraction assembly.

You can read more and see an example how to Stub/Mock HttpContext.

Vadim