Exemplo n.º 1
0
        public async Task StopDisconnectsClient()
        {
            using (var testServer = new TestServer())
            {
                await testServer.BindAsync();

                using (var client = testServer.ConnectTo())
                {
                    await testServer.UnbindAsync();

                    await testServer.StopAsync();

                    // receive returns EOF
                    byte[] receiveBuffer = new byte[10];
                    var    received      = client.Receive(new ArraySegment <byte>(receiveBuffer));
                    Assert.Equal(0, received);

                    // send returns EPIPE
                    var exception = Assert.Throws <IOException>(() =>
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            byte[] sendBuffer = new byte[] { 1, 2, 3 };
                            client.Send(new ArraySegment <byte>(sendBuffer));
                        }
                    });
                    Assert.Equal(PosixResult.EPIPE, exception.HResult);
                }
            }
        }
Exemplo n.º 2
0
        public async Task Unbind()
        {
            using (var testServer = new TestServer())
            {
                await testServer.BindAsync();

                await testServer.UnbindAsync();

                var exception = Assert.Throws <IOException>(() => testServer.ConnectTo());
                Assert.Equal(PosixResult.ECONNREFUSED, exception.HResult);
            }
        }
Exemplo n.º 3
0
        public async Task MultiThread()
        {
            using (var testServer = new TestServer(new TestServerOptions()
            {
                ThreadCount = 2
            }))
            {
                await testServer.BindAsync();

                await testServer.UnbindAsync();

                await testServer.StopAsync();
            }
        }