コード例 #1
0
        public void NewServer_ReceivesConnectionRequest_NothingHappens()
        {
            var networkLayer = new ServerTestNetworkLinkLayer();
            var server       = new TestPollingServer(networkLayer);

            networkLayer.Receive(new BinaryClientFrameEncoder().Encode(this.initConnectionFrame));
            Assert.AreEqual(0, server.SessionCount);
        }
コード例 #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));
        }
コード例 #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));
        }