Exemple #1
0
        private static int BrowseAndSubscribeAllSensors(TheThing provider, TheThing targetThing, int maxSubscriptions, int minimumBrowseTags, out TheThing.MsgBrowseSensorsResponse browseResponse,
                                                        out TheThing.MsgSubscribeSensorsResponse sensorSubscriptionResponse,
                                                        out List <TheThing.TheSensorSubscriptionStatus> successfullSubscriptions)
        {
            browseResponse = provider.ProviderBrowseSensorsAsync().Result;
            Assert.IsNotNull(browseResponse, $"Timeout or browse message not implemented by plug-in: {new TheThingReference(provider)}");
            Assert.IsTrue(string.IsNullOrEmpty(browseResponse.Error), $"Browse error: {browseResponse.Error}");
            Assert.GreaterOrEqual(browseResponse.Sensors.Count, minimumBrowseTags);

            var subscribeRequest = new TheThing.MsgSubscribeSensors
            {
                DefaultTargetThing   = provider,
                ReplaceAll           = true,
                SubscriptionRequests = browseResponse.Sensors.Take(maxSubscriptions).Select(s =>
                                                                                            new TheThing.TheSensorSubscription
                {
                    TargetThing    = targetThing,
                    TargetProperty = TheCommonUtils.CListToString(s.DisplayNamePath, "."),
                    SensorId       = s.SensorId,
                    SampleRate     = 1000, // TODO make the test configurable for custom subscription parameters
                    //CustomSubscriptionInfo = new Dictionary<string, object>
                    //{
                    //    { "QueueSize", 50 },
                    //},
                    ExtensionData = s.ExtensionData,
                }
                                                                                            ).ToList(),
            };
            int subscriptionCount = subscribeRequest.SubscriptionRequests.Count;

            sensorSubscriptionResponse = provider.SubscribeSensorsAsync(subscribeRequest).Result;

            Assert.IsNotNull(sensorSubscriptionResponse, "Timeout or subscribe message not implemented by plug-in");
            Assert.IsTrue(string.IsNullOrEmpty(sensorSubscriptionResponse.Error), $"Error from SubscribeSensors: {sensorSubscriptionResponse.Error}. {new TheThingReference(provider)}");
            Assert.AreEqual(sensorSubscriptionResponse.SubscriptionStatus.Count, subscriptionCount);
            foreach (var status in sensorSubscriptionResponse.SubscriptionStatus)
            {
                Assert.True(string.IsNullOrEmpty(status.Error) || status.Error.Contains("BadUserAccessDenied"), $"{status.Subscription.SensorId}: {status.Error}");
            }

            successfullSubscriptions = sensorSubscriptionResponse.SubscriptionStatus.Where(s => string.IsNullOrEmpty(s.Error)).ToList();
            return(subscriptionCount);
        }