Exemplo n.º 1
0
        public void TestRoomBroadcastWithInvalidTunnels()
        {
            using (var mock = helper.CreateWebRequestProviderMock())
            {
                mock.SetupResponseBody(new
                {
                    code = 0,
                    data = new
                    {
                        invalidTunnelIds = new string[] { "tunnel1", "tunnel2" }
                    }.ToJson()
                }.ToJson());

                TunnelRoom room = new TunnelRoom();

                room.AddTunnel(Tunnel.GetById("tunnel1"));
                room.AddTunnel(Tunnel.GetById("tunnel2"));
                room.AddTunnel(Tunnel.GetById("tunnel3"));
                var result = room.Broadcast("test-type", "test-message");

                Assert.IsTrue(result.HasTunnelInvalidInfo);
                Assert.AreEqual(2, result.TunnelIvalidInfos.Count());
                Assert.AreEqual(2, result.TunnelIvalidInfos.Count(x => x.TunnelId == "tunnel1" || x.TunnelId == "tunnel2"));
            }
        }
Exemplo n.º 2
0
        public void TestRoomBroadcast()
        {
            using (var mock = helper.CreateWebRequestProviderMock())
            {
                mock.SetupResponseBody(new { code = 0 }.ToJson());

                TunnelRoom room = new TunnelRoom();
                Assert.AreEqual(0, room.TunnelCount);

                room.AddTunnel(Tunnel.GetById("tunnel1"));
                room.AddTunnel(Tunnel.GetById("tunnel2"));
                Assert.AreEqual(2, room.TunnelCount);

                room.RemoveTunnelById("tunnel1");
                Assert.AreEqual(1, room.TunnelCount);

                room.AddTunnel(Tunnel.GetById("tunnel3"));
                room.Broadcast("test-type", "test-message");


                var packets = helper.ResolvePackets(mock.GetRequestContent());

                // emit 1 packet
                Assert.AreEqual(1, packets.Length);
                var firstPacket = packets[0];

                // the first packet should be a message packet
                Assert.AreEqual(2, firstPacket.tunnelIds.Length);
                Assert.AreEqual("tunnel2", firstPacket.tunnelIds[0]);
                Assert.AreEqual("tunnel3", firstPacket.tunnelIds[1]);
                Assert.AreEqual("message", firstPacket.type);

                // the message are encoded correctly
                var message = new { type = "", content = "" }.ParseFromJson(firstPacket.content);
                Assert.AreEqual("test-type", message.type);
                Assert.AreEqual("test-message", message.content);
            }
        }