Esempio n. 1
0
        public async Task TestPresubscriptionRefreshAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();

            Assert.IsEmpty(subscribe.AllLocalSubscriptions);
            var observer1 = (await subscribe.ResourceValuesAsync()).Filter(new ResourceValuesFilter {
                DeviceId = "1", ResourcePaths = new List <string>()
                {
                    "3/0/0", "3/0/1"
                }
            });
            var observer2 = (await subscribe.ResourceValuesAsync()).Filter(new ResourceValuesFilter {
                DeviceId = "2", ResourcePaths = new List <string>()
                {
                    "3/0/0", "3/0/1"
                }
            })
                            .Filter(new ResourceValuesFilter {
                DeviceId = "3", ResourcePaths = new List <string>()
                {
                    "3/0/0", "3/0/1"
                }
            });

            Assert.AreEqual(3, subscribe.AllLocalSubscriptions.Count);

            observer1.Unsubscribe();

            Assert.AreEqual(2, subscribe.AllLocalSubscriptions.Count);
        }
        public async Task TestUnsubscribeAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <DeviceEventData>();
            var observer1 = await subscribe.DeviceEventsAsync();

            observer1.OnNotify += res => items.Add(res);
            var observer2 = await subscribe.DeviceEventsAsync();

            observer2.OnNotify += res => items.Add(res);
            var observer3 = await subscribe.DeviceEventsAsync();

            observer3.OnNotify += res => items.Add(res);
            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(subscribe.DeviceEventObservers.Count, 3);

            Assert.AreEqual(items.Count, 216);

            items.Clear();

            observer1.Unsubscribe();

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(subscribe.DeviceEventObservers.Count, 2);

            Assert.AreEqual(items.Count, 144);
        }
Esempio n. 3
0
        public async Task TestUnsubscribeAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <ResourceValueChange>();
            var observer1 = await subscribe.ResourceValuesAsync();

            observer1.OnNotify += res => items.Add(res);
            var observer2 = await subscribe.ResourceValuesAsync();

            observer2.OnNotify += res => items.Add(res);
            var observer3 = await subscribe.ResourceValuesAsync();

            observer3.OnNotify += res => items.Add(res);
            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(subscribe.ResourceValueObservers.Count, 3);

            Assert.AreEqual(items.Count, 90);

            items.Clear();

            observer1.Unsubscribe();

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(subscribe.ResourceValueObservers.Count, 2);

            Assert.AreEqual(items.Count, 60);
        }
        public async Task TestAllEventsAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <DeviceEventData>();
            var observer  = await subscribe.DeviceEventsAsync();

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(72, items.Count);
        }
        public async Task TestMultipleSpecificAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <DeviceEventData>();
            var observer  = (await subscribe.DeviceEventsAsync()).Filter(f => (f.Id == "1" || f.Id == "2") && (f.Event == DeviceEvent.Registration || f.Event == DeviceEvent.DeRegistration));

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(16, items.Count);
        }
Esempio n. 6
0
        public async Task TestAllNotifications()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <ResourceValueChange>();
            var observer  = await subscribe.ResourceValuesAsync();

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(30, items.Count);
        }
        public async Task TestOneStateAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <DeviceEventData>();
            var observer  = (await subscribe.DeviceEventsAsync()).Filter(f => f.Event == DeviceEvent.Registration);

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(18, items.Count);
            Assert.AreEqual(18, items.Where(d => d.State == DeviceEvent.Registration).ToList().Count);
        }
        public async Task TestMultipleDeviceIdAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <DeviceEventData>();
            var observer  = (await subscribe.DeviceEventsAsync()).Filter(f => f.Id == "1" || f.Id == "2");

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(32, items.Count);
            Assert.AreEqual(32, items.Where(d => d.DeviceId == "1" || d.DeviceId == "2").ToList().Count);
        }
Esempio n. 9
0
        public async Task TestSubscribingToOneDeviceAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <ResourceValueChange>();
            var observer  = (await subscribe.ResourceValuesAsync()).Filter(new ResourceValuesFilter {
                DeviceId = "1"
            });

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(6, items.Count);
        }
Esempio n. 10
0
        public async Task TestSubscribingToAllDevicesAndSpecificPathsWithWildcardAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <ResourceValueChange>();
            var observer  = (await subscribe.ResourceValuesAsync()).Filter(new ResourceValuesFilter {
                DeviceId = "2", ResourcePaths = new List <string>()
                {
                    "/3/*"
                }
            });

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(6, items.Count);
        }
Esempio n. 11
0
        public async Task TestSubscribingToResourcePathAsync()
        {
            var subscribe = new MbedCloudSDK.Connect.Api.Subscribe.Subscribe();
            var items     = new List <ResourceValueChange>();
            var observer  = (await subscribe.ResourceValuesAsync()).Filter(new ResourceValuesFilter {
                ResourcePaths = new List <string>()
                {
                    "/3/0/0"
                }
            });

            observer.OnNotify += res => items.Add(res);

            MockNotification(subscribe);
            MockNotification(subscribe);

            Assert.AreEqual(10, items.Count);
        }
        private void MockNotification(MbedCloudSDK.Connect.Api.Subscribe.Subscribe subscribe)
        {
            var regList = new List <DeviceEventData>()
            {
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "5", State = DeviceEvent.Registration
                },
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "5", State = DeviceEvent.DeRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "5", State = DeviceEvent.RegistrationUpdate
                },
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "1", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "2", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "3", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "4", State = DeviceEvent.ExpiredRegistration
                },
                new DeviceEventData()
                {
                    DeviceId = "5", State = DeviceEvent.ExpiredRegistration
                },
            };

            foreach (var item in regList)
            {
                subscribe.Notify(item);
            }
        }
Esempio n. 13
0
        private void MockNotification(MbedCloudSDK.Connect.Api.Subscribe.Subscribe subscribe)
        {
            var notificationList = new List <NotificationData>()
            {
                new NotificationData()
                {
                    DeviceId = "1", Path = "/3/0/0", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "1", Path = "/3/0/1", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "1", Path = "/3/0/2", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "2", Path = "/3/0/0", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "2", Path = "/3/0/1", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "2", Path = "/3/0/2", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "3", Path = "/3/0/0", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "3", Path = "/3/0/1", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "3", Path = "/3/0/2", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "4", Path = "/3/0/0", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "4", Path = "/3/0/1", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "4", Path = "/3/0/2", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "5", Path = "/3/0/0", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "5", Path = "/3/0/1", Payload = "SGk="
                },
                new NotificationData()
                {
                    DeviceId = "5", Path = "/3/0/2", Payload = "SGk="
                },
            };

            notificationList.ForEach(n =>
            {
                subscribe.Notify(n);
            });
        }