Ejemplo n.º 1
0
    public void ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull()
    {
        // Arrange
        var         result      = new Created <object>("location", null);
        HttpContext httpContext = null;

        // Act & Assert
        Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext));
    }
Ejemplo n.º 2
0
    public async Task CreatedResult_ReturnsStatusCode_SetsLocationHeader()
    {
        // Arrange
        var location    = "/test/";
        var httpContext = GetHttpContext();
        var result      = new Created <string>(location, "testInput");

        // Act
        await result.ExecuteAsync(httpContext);

        // Assert
        Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
        Assert.Equal(location, httpContext.Response.Headers["Location"]);
    }
Ejemplo n.º 3
0
    public async Task CreatedResult_OverwritesLocationHeader()
    {
        // Arrange
        var location    = "/test/";
        var httpContext = GetHttpContext();

        httpContext.Response.Headers["Location"] = "/different/location/";
        var result = new Created(location);

        // Act
        await result.ExecuteAsync(httpContext);

        // Assert
        Assert.Equal(StatusCodes.Status201Created, httpContext.Response.StatusCode);
        Assert.Equal(location, httpContext.Response.Headers["Location"]);
    }
Ejemplo n.º 4
0
    public async Task CreatedResult_ExecuteResultAsync_FormatsData()
    {
        // Arrange
        var location    = "/test/";
        var httpContext = GetHttpContext();
        var stream      = new MemoryStream();

        httpContext.Response.Body = stream;
        httpContext.Response.Headers["Location"] = "/different/location/";
        var result = new Created <string>(location, "testInput");

        // Act
        await result.ExecuteAsync(httpContext);

        // Assert
        var response = Encoding.UTF8.GetString(stream.ToArray());

        Assert.Equal("\"testInput\"", response);
    }