Reputation: 21308
Trying to run some integration tests and using DefaultHttpContext in my unit and integration tests. Is there a way to call SignInAsync() on DefaultHttpContext?
var claims = new List<Claim>();
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{
AllowRefresh = true,
IsPersistent = true,
IssuedUtc = DateTime.UtcNow
};
await _controller.HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
Running above throws an exception when using DefaultHttpContext for some reason:
System.ArgumentNullException : Value cannot be null. (Parameter 'provider') at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
Upvotes: 0
Views: 573