Example #1
0
    public async Task SendFile_Feature_ThrowsWhenCanceled()
    {
        var context     = new DefaultHttpContext();
        var fakeFeature = new FakeResponseBodyFeature();

        context.Features.Set <IHttpResponseBodyFeature>(fakeFeature);
        var response = context.Response;

        await Assert.ThrowsAsync <OperationCanceledException>(
            () => response.SendFileAsync("testfile1kb.txt", 1, 3, new CancellationToken(canceled: true)));
    }
Example #2
0
    public async Task SendFile_Feature_AbortsSilentlyWhenRequestCanceled()
    {
        var context     = new DefaultHttpContext();
        var fakeFeature = new FakeResponseBodyFeature();

        context.Features.Set <IHttpResponseBodyFeature>(fakeFeature);
        var token = new CancellationToken(canceled: true);

        context.RequestAborted = token;
        var response = context.Response;

        await response.SendFileAsync("testfile1kb.txt", 1, 3, CancellationToken.None);

        Assert.Equal(token, fakeFeature.Token);
    }
Example #3
0
    public async Task SendFileWorks()
    {
        var context     = new DefaultHttpContext();
        var response    = context.Response;
        var fakeFeature = new FakeResponseBodyFeature();

        context.Features.Set <IHttpResponseBodyFeature>(fakeFeature);

        await response.SendFileAsync("bob", 1, 3, CancellationToken.None);

        Assert.Equal("bob", fakeFeature.Name);
        Assert.Equal(1, fakeFeature.Offset);
        Assert.Equal(3, fakeFeature.Length);
        Assert.Equal(CancellationToken.None, fakeFeature.Token);
    }