• Not Answered

Unit Testing HttpContext overwrites behavior of ISitecorecontext

In my test class i mocked the sitecore context like below to get items from my fake database:

ISitecoreContext _sitecoreContext = new SitecoreContext();

After this I tried to switch the logged in user as below :

using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", true))
// Do something

Eveything is working fine until I needed to set the value of HttpContext.Current which I added before the instantiation of sitecore context object

HttpContext.Current = new HttpContext(
new HttpRequest("", "http://tempuri.org", ""),
new HttpResponse(new StringWriter())

Now when I tried to debug my code, the line that switched another user is throwing an error

Value cannot be null, parameter name : folder

Why is it happening? Does the httpcontext overwrites the context of isitecorecontext?

1 Reply