public void ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull() { // Arrange var result = new ForbidHttpResult(); HttpContext httpContext = null; // Act & Assert Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext)); }
public async Task ExecuteResultAsync_InvokesForbidAsyncWithAuthProperties(AuthenticationProperties expected) { // Arrange var auth = new Mock <IAuthenticationService>(); auth .Setup(c => c.ForbidAsync(It.IsAny <HttpContext>(), null, expected)) .Returns(Task.CompletedTask) .Verifiable(); var result = new ForbidHttpResult(expected); var httpContext = GetHttpContext(auth.Object); // Act await result.ExecuteAsync(httpContext); // Assert auth.Verify(); }
public async Task ExecuteResultAsync_InvokesForbidAsyncOnAllConfiguredSchemes() { // Arrange var authProperties = new AuthenticationProperties(); var auth = new Mock <IAuthenticationService>(); auth .Setup(c => c.ForbidAsync(It.IsAny <HttpContext>(), "Scheme1", authProperties)) .Returns(Task.CompletedTask) .Verifiable(); auth .Setup(c => c.ForbidAsync(It.IsAny <HttpContext>(), "Scheme2", authProperties)) .Returns(Task.CompletedTask) .Verifiable(); var httpContext = GetHttpContext(auth.Object); var result = new ForbidHttpResult(new[] { "Scheme1", "Scheme2" }, authProperties); var routeData = new RouteData(); // Act await result.ExecuteAsync(httpContext); // Assert auth.Verify(); }