Example #1
0
        public void ShouldBeAbleToConnectAndReconnectSynchronously()
        {
            using var client = new TcpClientAdapter();

            Assert.IsFalse(client.Connected);

            client.Connect("localhost", Port);

            Assert.IsTrue(client.Connected);

            client.Connect("localhost", Port);

            Assert.IsTrue(client.Connected);
        }
Example #2
0
        public void ShouldProvideConnectionStatus()
        {
            using var client = new TcpClientAdapter();

            client.Connect("localhost", Port);

            Assert.IsTrue(client.Connected);

            this.listener.Stop();

            try
            {
                // Since Connected only reports as of the last operation, we must send or receive data to
                // get the state as of now.
                client.GetStream().Write(new byte[0], 0, 0);

                // To deal with reconnection in real scenarios, the resulting IOException should be caught and
                // then attempt a retry with the exact same client.
            }
            catch (IOException)
            {
                //
            }

            Assert.IsFalse(client.Connected);

            this.listener.Start();
        }
Example #3
0
        public void ShouldProvideAccessToInternalNetworkStream()
        {
            using var client = new TcpClientAdapter();

            client.Connect("localhost", Port);

            Assert.IsNotNull(client.GetStream());
        }