Mock ASP.Net User in WebForms Application

I have a legacy application in which I am trying to create some testing.

I have several tests that require HttpContext.Current.User

Is there a way to mock this or is it just a user login on the fly?

0


a source to share


2 answers


HttpContext.User

has a type IPrincipal

. You can mock him by assigning any object to him IPrincipal

, including any object CustomPrincipal

.



+1


a source


I am not now how long you can refactor your legacy application. If you have .NET 3.5, you can use the HttpContextWrapper class, which is part of the System.Web.Abstraction assembly.



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

+1


a source







All Articles