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

        // Act & Assert
        Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext));
    }
Ejemplo n.º 2
0
    public async Task OkObjectResult_ExecuteAsync_SetsStatusCode()
    {
        // Arrange
        var result      = new Ok <string>("Hello");
        var httpContext = new DefaultHttpContext()
        {
            RequestServices = CreateServices()
        };

        // Act
        await result.ExecuteAsync(httpContext);

        // Assert
        Assert.Equal(StatusCodes.Status200OK, httpContext.Response.StatusCode);
    }
Ejemplo n.º 3
0
    public async Task OkObjectResult_ExecuteAsync_FormatsData()
    {
        // Arrange
        var result      = new Ok <string>("Hello");
        var stream      = new MemoryStream();
        var httpContext = new DefaultHttpContext()
        {
            RequestServices = CreateServices(),
            Response        =
            {
                Body = stream,
            },
        };

        // Act
        await result.ExecuteAsync(httpContext);

        // Assert
        Assert.Equal("\"Hello\"", Encoding.UTF8.GetString(stream.ToArray()));
    }