Example #1
0
        public void CreateTest()
        {
            var TestTcpTestServer = TcpTestServer.Create();

            TestTcpTestServer.RemoteTcpClient.GetStream().WriteStringz("Hello World");
            Assert.AreEqual("Hello World", TestTcpTestServer.LocalTcpClient.GetStream().ReadStringz());

            TestTcpTestServer.LocalTcpClient.GetStream().WriteStringz("Hello World");
            Assert.AreEqual("Hello World", TestTcpTestServer.RemoteTcpClient.GetStream().ReadStringz());
        }
        public void HandleDataReceivedTest()
        {
            var TestTcpTestServer     = TcpTestServer.Create();
            var TestBaseClientHandler = new MockedClientHandler(TestTcpTestServer.RemoteTcpClient);

            TestBaseClientHandler.StartReceivingData();
            TestTcpTestServer.LocalTcpClient.GetStream().WriteBytes(new byte[] { 3, 0, 0, 1, 2, 3 });
            if (!TestBaseClientHandler.HandlePacketEvent.WaitOne(1000))
            {
                Assert.Fail();
            }
            Assert.AreEqual(
                "Packet(Type=Ping, Data=010203)",
                TestBaseClientHandler.ReceivedPacket.ToString()
                );
        }
Example #3
0
        public void HandleDataReceivedTest()
        {
            var ServerManager         = new ServerManager();
            var TestTcpTestServer     = TcpTestServer.Create();
            var TestBaseClientHandler = new ClientHandler(ServerManager, TestTcpTestServer.LocalTcpClient);

            TestBaseClientHandler.StartReceivingData();

            var ClientClientStream = TestTcpTestServer.RemoteTcpClient.GetStream();

            // Client send a GetVersion request.
            var PacketToSend = new Packet(Packet.PacketType.GetVersion);

            PacketToSend.WritePacketTo(ClientClientStream);

            Packet PacketReceived = Packet.FromStream(ClientClientStream);

            // Client receives a GetVersion response from the server.
            Assert.AreEqual(
                ServerManager.Version.ToString(),
                PacketReceived.Stream.ReadStruct <ServerManager.VersionStruct>().ToString()
                );
        }