I have a function in a class library that updates a session variable. ISession
is passed in as a parameter from the controller so the function can change the session var.
I'm wanting to test this function to ensure the session variable is updated correctly.
First however, I'm just trying to get started with a basic unit test with XUnit, but I can't get Session to work
[Fact]
public void CreateSessionVariable()
{
var httpContext = new DefaultHttpContext();
httpContext.Session.SetString("MyVar", "Hi");
Assert.True(httpContext.Session.Get("MyVar") != null);
}
On httpContext.Session.SetString
I get the error:
Session has not been configured for this application or request
I know in an MVC6 app you have to do things like services.AddSession()
and app.UseSession()
but I don't know how to set those for a unit test.
How do I configure Session for use inside a unit test?