public async Task ExecuteResultAsync(ActionContext context)
        {
            var createdResult = new CreatedAtRouteResult(_routeName, _result.Result);

            createdResult.StatusCode = StatusCodes.Status201Created;

            await createdResult.ExecuteResultAsync(context);
        }
Ejemplo n.º 2
0
    public async Task CreatedAtRouteResult_ReturnsStatusCode_SetsLocationHeader(object values)
    {
        // Arrange
        var expectedUrl   = "testAction";
        var httpContext   = GetHttpContext();
        var actionContext = GetActionContext(httpContext);
        var urlHelper     = GetMockUrlHelper(expectedUrl);

        // Act
        var result = new CreatedAtRouteResult(routeName: null, routeValues: values, value: null);

        result.UrlHelper = urlHelper;
        await result.ExecuteResultAsync(actionContext);

        // Assert
        Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
        Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
    }
Ejemplo n.º 3
0
    public async Task CreatedAtRouteResult_ThrowsOnNullUrl()
    {
        // Arrange
        var httpContext   = GetHttpContext();
        var actionContext = GetActionContext(httpContext);
        var urlHelper     = GetMockUrlHelper(returnValue: null);

        var result = new CreatedAtRouteResult(
            routeName: null,
            routeValues: new Dictionary <string, object>(),
            value: null);

        result.UrlHelper = urlHelper;

        // Act & Assert
        await ExceptionAssert.ThrowsAsync <InvalidOperationException>(
            async() => await result.ExecuteResultAsync(actionContext),
            "No route matches the supplied values.");
    }