How to unit test exception filter in web API ASP.Net core. Don't want to mock the onException method. I have mocked ControllerContext like below in my unit tests. Class libraries which are called from the Web API throw custom exceptions which are caught by exception filters and I want to unit test that. Today I get "Value does not fall within the expected range" error.
public static ControllerContext GetMockControllerContext(
this Controller controller,
RouteData routeData)
{
var actionContext = new ActionContext
{
HttpContext = new DefaultHttpContext
{
User = controller.GetMockUserContext()
},
RouteData = routeData,
ActionDescriptor = new ControllerActionDescriptor()
};
return new ControllerContext(actionContext);
}