Пример #1
0
    public void ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull()
    {
        // Arrange
        var         result      = new RedirectHttpResult("url");
        HttpContext httpContext = null;

        // Act & Assert
        Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext));
    }
Пример #2
0
    public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlPermanentAndPreserveMethod()
    {
        // Arrange
        var url = "/test/url";

        // Act
        var result = new RedirectHttpResult(url, acceptLocalUrlOnly: true, permanent: true, preserveMethod: true);

        // Assert
        Assert.True(result.PreserveMethod);
        Assert.True(result.Permanent);
        Assert.Same(url, result.Url);
    }
Пример #3
0
    public async Task Execute_Throws_ForNonLocalUrl(
        string appRoot,
        string contentPath)
    {
        // Arrange
        var httpContext = GetHttpContext(appRoot);
        var result      = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true, false, false);

        // Act & Assert
        var exception = await Assert.ThrowsAsync <InvalidOperationException>(() => result.ExecuteAsync(httpContext));

        Assert.Equal(
            "The supplied URL is not local. A URL with an absolute path is considered local if it does not " +
            "have a host/authority part. URLs using virtual paths ('~/') are also local.",
            exception.Message);
    }
Пример #4
0
    public async Task Execute_ReturnsExpectedValues()
    {
        // Arrange
        var appRoot      = "/";
        var contentPath  = "~/Home/About";
        var expectedPath = "/Home/About";

        var httpContext = GetHttpContext(appRoot);
        var result      = new RedirectHttpResult(contentPath, acceptLocalUrlOnly: true, false, false);

        // Act
        await result.ExecuteAsync(httpContext);

        // Assert
        Assert.Equal(expectedPath, httpContext.Response.Headers.Location.ToString());
        Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode);
    }
Пример #5
0
    protected override Task ExecuteAsync(HttpContext httpContext, string contentPath)
    {
        var redirectResult = new RedirectHttpResult(contentPath, false, false);

        return(redirectResult.ExecuteAsync(httpContext));
    }