Exemplo n.º 1
0
        public void ReadyClient_WhenConnecting_SendAnEmptyClientId()
        {
            var networkLayer = new ClientTestNetworkLinkLayer();

            var client = new TestPollingClient(networkLayer);

            client.ConnectAsync();

            Assert.AreEqual(1, networkLayer.SentBytes.Count);

            var sentFrameBytes = networkLayer.SentBytes[0];
            var sentFrame      = new GenericSerializer <ClientDataFrame>().Deserialze(sentFrameBytes);

            Assert.IsNotNull(sentFrame);
            Assert.IsTrue(sentFrame.SequenceId != 0);
            Assert.AreEqual(0, sentFrame.ClientId);
            Assert.IsNull(sentFrame.Payload);
        }
Exemplo n.º 2
0
        public void StartedServer_ReceivesEmptyClientId_ShouldResponseWithAClientId()
        {
            var networkLayer = new ServerTestNetworkLinkLayer();
            var server       = new TestPollingServer(networkLayer);

            server.Start();

            ConnectionHelper.WaitForClientSession(server, networkLayer, this.initConnectionFrame);

            networkLayer.Receive(new BinaryClientFrameEncoder().Encode(initConnectionFrame));

            Assert.IsTrue(networkLayer.SentBytes.Any(), "There should be at least one captured frame");

            var sentFrameBytes = networkLayer.SentBytes[0];
            var sentFrame      = new GenericSerializer <ServerDataFrame>().Deserialze(sentFrameBytes);

            Assert.IsNotNull(sentFrame);
            Assert.IsTrue(sentFrame.SequenceId != 0);
            Assert.IsNotNull(sentFrame.Payload);
            Assert.AreNotEqual(0, BitConverter.ToInt32(sentFrame.Payload, 0));
        }
Exemplo n.º 3
0
        public void EstablishedSession_ReceivesData_ShouldTriggerEventOnSession()
        {
            var networkLayer = new ServerTestNetworkLinkLayer();
            var server       = new TestPollingServer(networkLayer);

            var serverOnFrameReceived = new List <ClientDataFrame>();

            server.Start();

            var session = ConnectionHelper.WaitForClientSession(server, networkLayer, this.initConnectionFrame);

            session.FrameReceived += (sender, args) => serverOnFrameReceived.Add(args.Frame);

            // Find out the ClientId
            Assert.IsTrue(networkLayer.SentBytes.Any(), "There should be at least one captured frame");

            var sentFrameBytes = networkLayer.SentBytes[0];
            var sentFrame      = new GenericSerializer <ServerDataFrame>().Deserialze(sentFrameBytes);

            Assert.IsNotNull(sentFrame);
            Assert.IsTrue(sentFrame.SequenceId != 0);
            Assert.IsNotNull(sentFrame.Payload);
            Assert.AreNotEqual(0, BitConverter.ToInt32(sentFrame.Payload, 0));

            var clientId    = BitConverter.ToInt32(sentFrame.Payload, 0);
            var clientFrame = new ClientDataFrame()
            {
                ClientId   = clientId,
                SequenceId = initConnectionFrame.SequenceId + 1,
                Payload    = Encoding.UTF8.GetBytes("Hello World")
            };

            networkLayer.Receive(new GenericSerializer <ClientDataFrame>().Serialize(clientFrame));

            Assert.AreEqual(1, serverOnFrameReceived.Count);
            Assert.AreEqual("Hello World", Encoding.UTF8.GetString(serverOnFrameReceived[0].Payload));
        }