public async Task DisposeAsyncAfterReplacingTransportClosesConnection()
        {
            var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));

            var connectionCloseTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
            var mockDuplexPipe     = new MockDuplexPipe();

            listenOptions.Use(next =>
            {
                return(async context =>
                {
                    context.Transport = mockDuplexPipe;
                    await context.DisposeAsync();
                    await connectionCloseTcs.Task;
                });
            });

            var serviceContext = new TestServiceContext(LoggerFactory);

            await using (var server = new TestServer(TestApp.EmptyApp, serviceContext, listenOptions))
            {
                using (var connection = server.CreateConnection())
                {
                    await connection.WaitForConnectionClose();

                    connectionCloseTcs.SetResult();
                }
            }

            Assert.False(mockDuplexPipe.WasCompleted);
        }
    public void ExistingPipe_Mock()
    {
        var pipe       = new Pipe();
        var duplexPipe = new MockDuplexPipe {
            Input = pipe.Reader, Output = pipe.Writer
        };
        var options = new MultiplexingStream.ChannelOptions
        {
            ExistingPipe = duplexPipe,
        };

        // We provided an "untrusted" instance of IDuplexPipe, so it would be copied into a trusted type.
        // Only assert that the contents are the same.
        Assert.Same(duplexPipe.Input, options.ExistingPipe.Input);
        Assert.Same(duplexPipe.Output, options.ExistingPipe.Output);

        options.ExistingPipe = null;
        Assert.Null(options.ExistingPipe);
    }
 public MockPipeReader(MockDuplexPipe duplexPipe)
 {
     _duplexPipe = duplexPipe;
 }
 public MockPipeWriter(MockDuplexPipe duplexPipe)
 {
     _duplexPipe = duplexPipe;
 }