Example #1
0
    public void ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull()
    {
        // Arrange
        var         result      = new ForbidHttpResult();
        HttpContext httpContext = null;

        // Act & Assert
        Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext));
    }
Example #2
0
    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();
    }
Example #3
0
    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();
    }