public void CreatedAtRoute_WithNoArgs_ResultHasCorrectValues()
    {
        // Act
        var result = TypedResults.CreatedAtRoute();

        // Assert
        Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
        Assert.Null(result.RouteName);
        Assert.Equal(new RouteValueDictionary(), result.RouteValues);
    }
    public void CreatedAtRoute_WithRouteName_ResultHasCorrectValues()
    {
        // Arrange
        var routeName = "routeName";

        // Act
        var result = TypedResults.CreatedAtRoute(routeName, default(object));

        // Assert
        Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
        Assert.Equal(routeName, result.RouteName);
        Assert.Equal(new RouteValueDictionary(), result.RouteValues);
    }
    public void CreatedAtRoute_WithRouteNameAndValue_ResultHasCorrectValues()
    {
        // Arrange
        var routeName = "routeName";
        var value     = new { };

        // Act
        var result = TypedResults.CreatedAtRoute(value, routeName, null);

        // Assert
        Assert.Equal(StatusCodes.Status201Created, result.StatusCode);
        Assert.Equal(routeName, result.RouteName);
        Assert.Equal(new RouteValueDictionary(), result.RouteValues);
        Assert.Equal(value, result.Value);
    }
Beispiel #4
0
 /// <summary>
 /// Produces a <see cref="StatusCodes.Status201Created"/> response.
 /// </summary>
 /// <param name="routeName">The name of the route to use for generating the URL.</param>
 /// <param name="routeValues">The route data to use for generating the URL.</param>
 /// <param name="value">The value to be included in the HTTP response body.</param>
 /// <returns>The created <see cref="IResult"/> for the response.</returns>
 public static IResult CreatedAtRoute(string?routeName = null, object?routeValues = null, object?value = null)
 => value is null?TypedResults.CreatedAtRoute(routeName, routeValues) : TypedResults.CreatedAtRoute(value, routeName, routeValues);
Beispiel #5
0
    /// <summary>
    /// Produces a <see cref="StatusCodes.Status201Created"/> response.
    /// </summary>
    /// <param name="routeName">The name of the route to use for generating the URL.</param>
    /// <param name="routeValues">The route data to use for generating the URL.</param>
    /// <param name="value">The value to be included in the HTTP response body.</param>
    /// <returns>The created <see cref="IResult"/> for the response.</returns>
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
    public static IResult CreatedAtRoute <TValue>(string?routeName = null, object?routeValues = null, TValue?value = default)
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
    => value is null?TypedResults.CreatedAtRoute(routeName, routeValues) : TypedResults.CreatedAtRoute(value, routeName, routeValues);