We have a class
FooRequirementHandler which inherits from and implements
AuthorizationHandler<FooRequirement> - For details on what these handlers actually do see Custom Authorization Policy in this filters post.
We now have a
protected access modifier to contend with. If we create an instance of
FooRequirementHandler and try call
HandleRequirementAsync the pre-compiler will protest with it being inaccessible due to its protection level. This is to be expected.
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, FooRequirement requirement)
In the test create a class that inherits from
FooRequirementHandler to expose the behavior.
A protected member is accessible within its class and by derived class instances.
In the unit test you can then use
ExposedFooRequirementHandler as the class under test.
var classUnderTest = new ExposedFooRequirementHandler(someInterfaceMock.Object);