Пример #1
0
    public void ExecuteAsync_ThrowsArgumentNullException_WhenHttpContextIsNull()
    {
        // Arrange
        var         result      = new PushStreamHttpResult(s => Task.CompletedTask, "content-type");
        HttpContext httpContext = null;

        // Act & Assert
        Assert.ThrowsAsync <ArgumentNullException>("httpContext", () => result.ExecuteAsync(httpContext));
    }
Пример #2
0
    public void Constructor_SetsContentTypeAndParameters()
    {
        // Arrange
        var stream            = Stream.Null;
        var contentType       = "text/plain; charset=us-ascii; p1=p1-value";
        var expectedMediaType = contentType;
        var callback          = (Stream body) => body.WriteAsync(Encoding.UTF8.GetBytes("Hello World").AsMemory()).AsTask();

        // Act
        var result = new PushStreamHttpResult(callback, contentType);

        // Assert
        Assert.Equal(expectedMediaType, result.ContentType);
    }
Пример #3
0
    public async Task PushStreamResultsExposeTheResponseBody()
    {
        var result = new PushStreamHttpResult(body => body.WriteAsync(Encoding.UTF8.GetBytes("Hello World").AsMemory()).AsTask(), contentType: null);

        var httpContext = new DefaultHttpContext
        {
            RequestServices = new ServiceCollection().AddLogging().BuildServiceProvider()
        };
        var ms = new MemoryStream();

        httpContext.Response.Body = ms;

        await result.ExecuteAsync(httpContext);

        Assert.Equal("Hello World", Encoding.UTF8.GetString(ms.ToArray()));
        Assert.Equal("application/octet-stream", result.ContentType);
    }
Пример #4
0
    public void Constructor_SetsLastModifiedAndEtag()
    {
        // Arrange
        var stream            = Stream.Null;
        var contentType       = "text/plain";
        var expectedMediaType = contentType;
        var lastModified      = new DateTimeOffset();
        var entityTag         = new EntityTagHeaderValue("\"Etag\"");
        var callback          = (Stream body) => body.WriteAsync(Encoding.UTF8.GetBytes("Hello World").AsMemory()).AsTask();

        // Act
        var result = new PushStreamHttpResult(callback, contentType)
        {
            LastModified = lastModified,
            EntityTag    = entityTag,
        };

        // Assert
        Assert.Equal(lastModified, result.LastModified);
        Assert.Equal(entityTag, result.EntityTag);
        Assert.Equal(expectedMediaType, result.ContentType);
    }