Beispiel #1
0
        public void ReceiveSensorList()
        {
            string       payload  = "{\"available_sensors\":[{\"temperature\":\"double\"}, {\"humidity\":\"int\"}]}";
            DataStream   stream   = new DataStream();
            DataReceiver receiver = new DataReceiver();

            receiver.OnPayloadReceived((object received_payload, string attribute, string label) =>
            {
                JArray received = (JArray)received_payload;
                foreach (JObject obj in received)
                {
                    Console.WriteLine(obj);
                    Console.WriteLine(obj.GetType());

                    //Assert.IsTrue(obj.ContainsKey("temperature"));
                    //Assert.IsTrue(obj.ContainsKey("humidity"));

                    //Assert.AreEqual(obj["temperature"], "double");
                    //Assert.AreEqual(obj["humidity"], "int");

                    foreach (var elem in obj)
                    {
                        Console.WriteLine(elem.Key);
                        Console.WriteLine(elem.Value);
                    }
                }
            });

            receiver.Subscribe(stream, "available_sensors", "JArray");

            stream.Parse(payload);
            stream.DeliverSubscriptions();
        }
Beispiel #2
0
        public void MultipleSubscribersOnSameKey()
        {
            DataStream   stream    = new DataStream();
            DataReceiver receiver  = new DataReceiver();
            DataReceiver receiver2 = new DataReceiver();

            receiver.OnPayloadReceived((object payload, string attribute, string label) =>
            {
                Assert.AreEqual(5, payload);
                Assert.AreEqual(typeof(int), payload.GetType());
                Console.WriteLine(payload.GetType());
            });

            receiver2.OnPayloadReceived((object payload, string attribute, string label) =>
            {
                Assert.AreEqual(5, payload);
                Assert.AreEqual(typeof(int), payload.GetType());
                Console.WriteLine(payload.GetType());
            });

            receiver.Subscribe(stream, "int", "int");
            receiver2.Subscribe(stream, "int", "int");

            stream.Parse(JSON);
            stream.DeliverSubscriptions();
        }
Beispiel #3
0
        public void MultipleSubscriptionOnDifferentKeys()
        {
            DataStream   stream    = new DataStream();
            DataReceiver receiver  = new DataReceiver();
            DataReceiver receiver2 = new DataReceiver();

            receiver.OnPayloadReceived((object p, string attribute, string label) =>
            {
                JObject payload = (JObject)p;
                JObject actual  = new JObject();
                actual.Add("int", 2);
                actual.Add("string", "value");

                foreach (var item in actual)
                {
                    Assert.IsTrue(payload.ContainsKey(item.Key));
                    Assert.AreEqual(payload.GetValue(item.Key), item.Value);
                }
                Console.WriteLine(payload.GetType());
            });

            receiver2.OnPayloadReceived((object payload, string attribute, string label) =>
            {
                Assert.AreEqual(5, payload);
                Assert.AreEqual(typeof(int), payload.GetType());
                Console.WriteLine(payload.GetType());
            });

            receiver.Subscribe(stream, "hashtable", "JObject");
            receiver2.Subscribe(stream, "int", "int");

            stream.Parse(JSON);
            stream.DeliverSubscriptions();
        }
Beispiel #4
0
        public void ReceiveJObject()
        {
            DataStream   stream   = new DataStream();
            DataReceiver receiver = new DataReceiver();

            receiver.OnPayloadReceived((object p, string attribute, string label) =>
            {
                JObject payload = (JObject)p;
                JObject actual  = new JObject
                {
                    { "int", 2 },
                    { "string", "value" }
                };

                foreach (var item in actual)
                {
                    Assert.IsTrue(payload.ContainsKey(item.Key));
                    Assert.AreEqual(payload.GetValue(item.Key), item.Value);
                }
                Console.WriteLine(payload.GetType());
            });

            receiver.Subscribe(stream, "hashtable", "JObject");

            stream.Parse(JSON);
            stream.DeliverSubscriptions();
        }
Beispiel #5
0
        public void ReceiveLong()
        {
            DataStream   stream   = new DataStream();
            DataReceiver receiver = new DataReceiver();

            receiver.OnPayloadReceived((object payload, string attribute, string label) =>
            {
                Assert.AreEqual(5L, payload);
                Assert.AreEqual(typeof(long), payload.GetType());
                Console.WriteLine(payload.GetType());
            });

            receiver.Subscribe(stream, "long", "long");

            stream.Parse(JSON);
            stream.DeliverSubscriptions();
        }
Beispiel #6
0
        public void OneSubscriberMultipleKeys()
        {
            string       payload  = "{\"a\":1, \"b\":2}";
            DataStream   stream   = new DataStream();
            DataReceiver receiver = new DataReceiver();

            receiver.Subscribe(stream, "a", "int");
            receiver.Subscribe(stream, "b", "int");

            receiver.OnPayloadReceived((object actual, string attribute, string label) =>
            {
                if (attribute == "a")
                {
                    Assert.AreEqual(1, actual);
                }
                else if (attribute == "b")
                {
                    Assert.AreEqual(2, actual);
                }
            });

            stream.Parse(payload);
            stream.DeliverSubscriptions();
        }
Beispiel #7
0
        public void ReceiveJArray()
        {
            DataStream   stream   = new DataStream();
            DataReceiver receiver = new DataReceiver();

            receiver.OnPayloadReceived((object payload, string attribute, string label) => {
                JArray expected = new JArray {
                    "one", "two", "three"
                };
                JArray actual = (JArray)payload;

                for (int i = 0; i < expected.Count; i++)
                {
                    Assert.AreEqual(expected[i], actual[i]);
                }
                Console.Write("Datatype: ");
                Console.WriteLine(payload.GetType());
            });

            receiver.Subscribe(stream, "genericlist", "JArray");

            stream.Parse(JSON);
            stream.DeliverSubscriptions();
        }