Beispiel #1
0
    public async Task MultipleFramesSentAsSingleResponse()
    {
        using (StartVerifiableLog())
        {
            var pair       = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
            var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
            var context    = new DefaultHttpContext();

            var poll = new LongPollingServerTransport(CancellationToken.None, connection.Application.Input, LoggerFactory);
            var ms   = new MemoryStream();
            context.Response.Body = ms;

            await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello"));

            await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes(" "));

            await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("World"));

            connection.Transport.Output.Complete();

            await poll.ProcessRequestAsync(context, context.RequestAborted).DefaultTimeout();

            Assert.Equal(200, context.Response.StatusCode);

            var payload = ms.ToArray();
            Assert.Equal("Hello World", Encoding.UTF8.GetString(payload));
        }
    }
Beispiel #2
0
    public async Task Set204StatusCodeWhenChannelComplete()
    {
        using (StartVerifiableLog())
        {
            var pair       = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
            var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);

            var context = new DefaultHttpContext();

            var poll = new LongPollingServerTransport(CancellationToken.None, connection.Application.Input, LoggerFactory);

            connection.Transport.Output.Complete();

            await poll.ProcessRequestAsync(context, context.RequestAborted).DefaultTimeout();

            Assert.Equal(204, context.Response.StatusCode);
        }
    }
Beispiel #3
0
    public async Task Set200StatusCodeWhenTimeoutTokenFires()
    {
        using (StartVerifiableLog())
        {
            var pair       = DuplexPipe.CreateConnectionPair(PipeOptions.Default, PipeOptions.Default);
            var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application);
            var context    = new DefaultHttpContext();

            var timeoutToken = new CancellationToken(true);
            var poll         = new LongPollingServerTransport(timeoutToken, connection.Application.Input, LoggerFactory);

            using (var cts = CancellationTokenSource.CreateLinkedTokenSource(timeoutToken, context.RequestAborted))
            {
                await poll.ProcessRequestAsync(context, cts.Token).DefaultTimeout();

                Assert.Equal(0, context.Response.ContentLength);
                Assert.Equal(200, context.Response.StatusCode);
            }
        }
    }