public void TestTunnelEmit() { using (var mock = helper.CreateWebRequestProviderMock()) { mock.SetupResponseBody(new { code = 0 }.ToJson()); Tunnel tunnel = Tunnel.GetById("tunnel1"); tunnel.Emit("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(1, firstPacket.tunnelIds.Length); Assert.AreEqual("tunnel1", firstPacket.tunnelIds[0]); 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); } }
public void TestTunnelEmitWithInvalidTunnels() { using (var mock = helper.CreateWebRequestProviderMock()) { mock.SetupResponseBody(new { code = 0, data = new { invalidTunnelIds = new string[] { "tunnel1" } }.ToJson() }.ToJson()); Tunnel tunnel = Tunnel.GetById("tunnel1"); var result = tunnel.Emit("test-type", "test-message"); Assert.IsTrue(result.HasTunnelInvalidInfo); Assert.AreEqual("tunnel1", result.TunnelIvalidInfos.First().TunnelId); } }