示例#1
0
        public void TestPokeNewValues()
        {
            MockTcpListener listener = new MockTcpListener() {
                Port = 36001
            };
            listener.BeginListener();

            MockTcpClient client = new MockTcpClient() {
                LastPacketReceived = new MockPacket() {
                    Packet = {
                        Stamp = DateTime.Now
                    }
                },
                LastPacketSent = new MockPacket() {
                    Packet = {
                        Stamp = DateTime.Now
                    }
                }
            };

            client.Setup(new ClientSetup() {
                Hostname = "localhost",
                Port = 36001
            });

            AutoResetEvent connectionWait = new AutoResetEvent(false);

            client.ConnectionStateChanged += (sender, state) => {
                if (state == ConnectionState.ConnectionReady) {
                    connectionWait.Set();
                }
            };

            client.Connect();

            Assert.IsTrue(connectionWait.WaitOne(1000));

            client.ConnectionState = ConnectionState.ConnectionLoggedIn;

            client.Poke();

            Assert.AreEqual(ConnectionState.ConnectionLoggedIn, client.ConnectionState);
        }
示例#2
0
        /// <summary>
        /// Creates a listener, connects a client and ensures the connection is established. Just allows for easier
        /// tests with this drudgery taken care of.
        /// </summary>
        /// <param name="port"></param>
        /// <param name="listener"></param>
        /// <param name="client"></param>
        protected void CreateAndConnect(ushort port, out MockTcpListener listener, out MockTcpClient client)
        {
            listener = new MockTcpListener() {
                Port = port
            };

            listener.BeginListener();

            client = new MockTcpClient();

            client.Setup(new ClientSetup() {
                Hostname = "localhost",
                Port = port
            });

            client.Connect();

            AutoResetEvent connectionWait = new AutoResetEvent(false);

            Action<IClient, ConnectionState> connectionStateChangeHandler = (client1, state) => {
                if (state == ConnectionState.ConnectionReady) {
                    connectionWait.Set();
                }
            };

            client.ConnectionStateChanged += connectionStateChangeHandler;

            if (client.ConnectionState == ConnectionState.ConnectionReady) {
                connectionWait.Set();
            }

            connectionWait.WaitOne(1000);

            client.ConnectionState = ConnectionState.ConnectionLoggedIn;

            // Clean up before we give back control to the test.
            client.ConnectionStateChanged -= connectionStateChangeHandler;
        }
示例#3
0
        public void TestPokeNulledValues()
        {
            MockTcpListener listener = new MockTcpListener() {
                Port = 36000
            };
            listener.BeginListener();

            MockTcpClient client = new MockTcpClient() {
                ConnectionState = ConnectionState.ConnectionLoggedIn
            };

            client.Setup(new ClientSetup() {
                Hostname = "localhost",
                Port = 36000
            });

            AutoResetEvent connectionWait = new AutoResetEvent(false);

            client.ConnectionStateChanged += (sender, state) => {
                if (state == ConnectionState.ConnectionReady) {
                    connectionWait.Set();
                }
            };

            client.Connect();

            Assert.IsTrue(connectionWait.WaitOne(1000));

            client.ConnectionState = ConnectionState.ConnectionLoggedIn;

            client.Poke();

            Assert.AreEqual(ConnectionState.ConnectionDisconnected, client.ConnectionState);
        }