Пример #1
0
        public void ClientShouldNotRaiseRasieEventInOrderOfSequenceNumber()
        {
            NetworkTransportMock networkTransport = new NetworkTransportMock();
            JsonSerializer       serializer       = new JsonSerializer();
            ClientConcrete       clientConcrete   = new ClientConcrete(networkTransport, serializer, 10 * 1000);

            List <MyData> dataReceived = new List <MyData>();

            clientConcrete.OnPacketReceived += (packet) =>
            {
                dataReceived.Add((MyData)packet);
            };

            Packet data = ConstructPacket(new MyData
            {
                Name = "John Doe"
            }, 2);

            networkTransport.InvokeDataReceived(serializer.Serilize(data));
            data = ConstructPacket(new MyData
            {
                Name = "Jane Doe"
            }, 1);
            networkTransport.InvokeDataReceived(serializer.Serilize(data));

            Thread.Sleep(2 * 1000);

            Assert.AreEqual(2, dataReceived.Count);
            Assert.AreEqual("Jane Doe", dataReceived[0].Name);
            Assert.AreEqual("John Doe", dataReceived[1].Name);
        }
Пример #2
0
        public void ClientShouldNotRaiseMultipleEventsForDuplicatePacket()
        {
            NetworkTransportMock networkTransport = new NetworkTransportMock();
            JsonSerializer       serializer       = new JsonSerializer();
            ClientConcrete       clientConcrete   = new ClientConcrete(networkTransport, serializer, 10 * 1000);
            MyData myData = new MyData
            {
                Name = "John Doe"
            };

            int dataReceived = 0;

            clientConcrete.OnPacketReceived += (packet) =>
            {
                dataReceived++;
            };

            Packet data = ConstructPacket(myData, 1);

            networkTransport.InvokeDataReceived(serializer.Serilize(data));
            Thread.Sleep(2 * 1000);
            networkTransport.InvokeDataReceived(serializer.Serilize(data));

            Assert.AreEqual(1, dataReceived);
        }
Пример #3
0
        public void ClientShouldSendAckForEveryPacketReceived()
        {
            NetworkTransportMock networkTransport = new NetworkTransportMock();
            JsonSerializer       serializer       = new JsonSerializer();
            ClientConcrete       clientConcrete   = new ClientConcrete(networkTransport, serializer);
            MyData myData = new MyData
            {
                Name = "John Doe"
            };

            clientConcrete.OnPacketReceived += (packet) =>
            {
                // do nothing
            };

            Packet data = ConstructPacket(myData, 1);

            networkTransport.InvokeDataReceived(serializer.Serilize(data));

            Thread.Sleep(2 * 1000);

            Packet ackRecieved = (Packet)serializer.Deserilize(networkTransport.Data);

            Assert.AreEqual(data.PacketHeader.IdempotencyToken, ackRecieved.PacketHeader.IdempotencyToken);
        }
Пример #4
0
        public async Task ClientShouldNotRaiseEventForAckPacket()
        {
            NetworkTransportMock networkTransport = new NetworkTransportMock();
            JsonSerializer       serializer       = new JsonSerializer();
            ClientConcrete       clientConcrete   = new ClientConcrete(networkTransport, serializer);
            MyData myData = new MyData
            {
                Name = "John Doe"
            };

            bool dataReceived = false;

            clientConcrete.OnPacketReceived += (packet) =>
            {
                dataReceived = true;
            };


            await clientConcrete.SendData(myData);

            Packet sentPacket = (Packet)serializer.Deserilize(networkTransport.Data);

            Packet ackPacket = ConstructAckPacket(sentPacket.PacketHeader.SequenceNumber, sentPacket.PacketHeader.IdempotencyToken);

            networkTransport.InvokeDataReceived(serializer.Serilize(ackPacket));

            Thread.Sleep(2 * 1000);

            Assert.IsFalse(dataReceived);
        }
Пример #5
0
        public void ReadShouldReturnCorrectData()
        {
            NetworkTransportMock networkTransport = new NetworkTransportMock();
            JsonSerializer       serializer       = new JsonSerializer();
            ClientConcrete       clientConcrete   = new ClientConcrete(networkTransport, serializer);
            MyData myData = new MyData
            {
                Name = "John Doe"
            };
            MyData myDataRecieved = null;

            clientConcrete.OnPacketReceived += (packet) =>
            {
                myDataRecieved = (MyData)packet;
            };

            networkTransport.InvokeDataReceived(serializer.Serilize(ConstructPacket(myData, 1)));

            Assert.AreEqual(myData.Name, myDataRecieved.Name);
        }