public void LocalRedirect_WithUrl_ResultHasCorrectValues()
    {
        // Arrange
        var localUrl = "test/path";

        // Act
        var result = TypedResults.LocalRedirect(localUrl);

        // Assert
        Assert.Equal(localUrl, result.Url);
        Assert.True(result.AcceptLocalUrlOnly);
        Assert.False(result.Permanent);
        Assert.False(result.PreserveMethod);
    }
    public void LocalRedirect_WithNonLocalUrlAndPermanentTrueAndPreserveTrue_ResultHasCorrectValues()
    {
        // Arrange
        var localUrl       = "https://example.com/non-local-url/example";
        var permanent      = true;
        var preserveMethod = true;

        // Act
        var result = TypedResults.LocalRedirect(localUrl, permanent, preserveMethod);

        // Assert
        Assert.Equal(localUrl, result.Url);
        Assert.True(result.AcceptLocalUrlOnly);
        Assert.True(result.Permanent);
        Assert.True(result.PreserveMethod);
    }
    public void LocalRedirect_WithUrlAndPermanentTrueAndPreserveTrue_ResultHasCorrectValues()
    {
        // Arrange
        var localUrl       = "test/path";
        var permanent      = true;
        var preserveMethod = true;

        // Act
        var result = TypedResults.LocalRedirect(localUrl, permanent, preserveMethod);

        // Assert
        Assert.Equal(localUrl, result.Url);
        Assert.True(result.AcceptLocalUrlOnly);
        Assert.True(result.Permanent);
        Assert.True(result.PreserveMethod);
    }
Exemple #4
0
 /// <summary>
 /// Redirects to the specified <paramref name="localUrl"/>.
 /// <list type="bullet">
 /// <item>When <paramref name="permanent"/> and <paramref name="preserveMethod"/> are set, sets the <see cref="StatusCodes.Status308PermanentRedirect"/> status code.</item>
 /// <item>When <paramref name="preserveMethod"/> is set, sets the <see cref="StatusCodes.Status307TemporaryRedirect"/> status code.</item>
 /// <item>When <paramref name="permanent"/> is set, sets the <see cref="StatusCodes.Status301MovedPermanently"/> status code.</item>
 /// <item>Otherwise, configures <see cref="StatusCodes.Status302Found"/>.</item>
 /// </list>
 /// </summary>
 /// <param name="localUrl">The local URL to redirect to.</param>
 /// <param name="permanent">Specifies whether the redirect should be permanent (301) or temporary (302).</param>
 /// <param name="preserveMethod">If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the initial request method.</param>
 /// <returns>The created <see cref="IResult"/> for the response.</returns>
 public static IResult LocalRedirect(string localUrl, bool permanent = false, bool preserveMethod = false)
 => TypedResults.LocalRedirect(localUrl, permanent, preserveMethod);
 public void LocalRedirect_WithEmptyStringUrl_ThrowsArgException()
 {
     Assert.Throws <ArgumentException>("localUrl", () => TypedResults.LocalRedirect(string.Empty));
 }
 public void LocalRedirect_WithNullStringUrl_ThrowsArgException()
 {
     Assert.Throws <ArgumentException>("localUrl", () => TypedResults.LocalRedirect(default(string)));
 }