'MSTest: Unit Testing HttpContext.SignoutAsync for the logout

Simply passing Mock HttpContext to the controller context while unit testing logout functionality will throw following error HttpContext.Signout + value can not be null (Parameter 'provider')

var mockHttpContext = new Mock<HttpContext>();

       

//set the controller HttpContext

_controller.ControllerContext.HttpContext = mockHttpContext.Object;

// Now call the Logout action method and Test result



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source