public void ExecuteAsync_RunsExceptionFilter_WhenAuthenticationFilterAuthenticateThrowsException() { // Arrange Exception expectedException = new NotImplementedException(); ApiController controller = new ExceptionlessController(); Mock <IAuthenticationFilter> filterMock = new Mock <IAuthenticationFilter>(); filterMock.Setup(f => f.AuthenticateAsync(It.IsAny <HttpAuthenticationContext>(), It.IsAny <CancellationToken>())).Callback(() => { throw expectedException; }); IAuthenticationFilter filter = filterMock.Object; // Act & Assert TestExceptionFilter(controller, expectedException, (configuration) => { configuration.Filters.Add(filter); }); }
public void ExecuteAsync_RunsExceptionFilter_WhenAuthenticationFilterChallengeThrowsException() { // Arrange Exception expectedException = new NotImplementedException(); ApiController controller = new ExceptionlessController(); Mock<IAuthenticationFilter> filterMock = new Mock<IAuthenticationFilter>(); filterMock.Setup(f => f.AuthenticateAsync(It.IsAny<HttpAuthenticationContext>(), It.IsAny<CancellationToken>())).Returns(() => Task.FromResult<object>(null)); filterMock.Setup(f => f.ChallengeAsync(It.IsAny<HttpAuthenticationChallengeContext>(), It.IsAny<CancellationToken>())).Callback(() => { throw expectedException; }); IAuthenticationFilter filter = filterMock.Object; // Act & Assert TestExceptionFilter(controller, expectedException, (configuration) => { configuration.Filters.Add(filter); }); }
public void ExecuteAsync_RunsExceptionFilter_WhenAuthorizationFilterThrowsException() { // Arrange Exception expectedException = new NotImplementedException(); ApiController controller = new ExceptionlessController(); Mock<IAuthorizationFilter> filterMock = new Mock<IAuthorizationFilter>(); filterMock.Setup(f => f.ExecuteAuthorizationFilterAsync(It.IsAny<HttpActionContext>(), It.IsAny<CancellationToken>(), It.IsAny<Func<Task<HttpResponseMessage>>>())).Callback(() => { throw expectedException; }); IAuthorizationFilter filter = filterMock.Object; // Act & Assert TestExceptionFilter(controller, expectedException, (configuration) => { configuration.Filters.Add(filter); }); }