Exemple #1
0
        //Helper methods

        /**
         * Checks is the devce proerties list contains newly addded
         * property key.
         */
        private void AssertKeyExistsInPropertyList(string devicePropertyKey)
        {
            var response = PropertyRequest.Get();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            JObject propertyList = JObject.Parse(response.Content);
            JArray  properties   = (JArray)propertyList["Items"];

            devicePropertyKey = "Tags." + devicePropertyKey;
            string property = (properties.FirstOrDefault(x => x.ToString() == devicePropertyKey)).ToString();

            Assert.True(!(string.IsNullOrEmpty(property)));
        }
Exemple #2
0
            /**
             * Gets job status using job id.
             */
            private static JObject GetJobStatus(HttpRequestWrapper Request, string JobId)
            {
                IHttpResponse jobStatusResponse = Request.Get(JobId, null);

                Assert.Equal(HttpStatusCode.OK, jobStatusResponse.StatusCode);
                return(JObject.Parse(jobStatusResponse.Content));
            }
Exemple #3
0
            /**
             * checks if the device was created by fetching (Get) it from the backend.
             * This is to ensure if device was saved and replicated in the DB.
             */
            internal static void CheckIfDeviceExists(HttpRequestWrapper Request, JObject createCallDevice)
            {
                string  createdDeviceId   = createCallDevice["Id"].ToString();
                var     fetchCallResponse = Request.Get(createdDeviceId, null);
                JObject fetchCallDevice   = JObject.Parse(fetchCallResponse.Content);

                // Asserts --- if device is created.
                Assert.True(fetchCallDevice.HasValues);
                Assert.True(JToken.DeepEquals(fetchCallDevice, createCallDevice));
            }
Exemple #4
0
        // This piece of code may be required in future. Hence, it is not erased.
        // private void PutSimulatedDevices(JObject devices)
        // {
        //    IHttpResponse response = Request.Put(devices);
        //    if (HttpStatusCode.OK != response.StatusCode)
        //    {
        //        throw new Exception("Create simulated device failure. Request to device simulation service failed with " + response.StatusCode + " status code.");
        //    }
        // }

        public JObject GetSimulatedDevices()
        {
            IHttpResponse response = Request.Get();

            if (HttpStatusCode.OK != response.StatusCode)
            {
                throw new Exception("Couldn't fetch simulated devices. Request to device simulation service failed with " + response.StatusCode + " status code.");
            }
            return(JObject.Parse(response.Content));
        }
Exemple #5
0
            /**
             * Check if tags on device are updated
             */
            internal static void CheckIfDeviceIsTagged(string tagsTemplate, string taggedDeviceId)
            {
                // Initailise Request to call "/devices" endpoint.
                HttpRequestWrapper Request = new HttpRequestWrapper(Constants.IOT_HUB_ADDRESS, Constants.Urls.DEVICE_PATH);

                // Act
                var     fetchCallResponse = Request.Get(taggedDeviceId, null);
                JObject fetchCallDevice   = JObject.Parse(fetchCallResponse.Content);
                var     tags       = JObject.Parse(tagsTemplate)["Tags"];
                var     deviceTags = fetchCallDevice["Tags"];

                // Asserts --- if device tags are updated correctly.
                Assert.True(JToken.DeepEquals(tags, deviceTags));
            }
Exemple #6
0
            /**
             * Check if device is Reconfigured
             */
            internal static void CheckIfDeviceIsReconfigured(string configTemplate, IHttpResponse tagCallresponse)
            {
                JObject configCallDevice = JObject.Parse(tagCallresponse.Content);
                string  createdDeviceId  = configCallDevice["Id"].ToString();
                // Initailise Request to call "/devices" endpoint.
                HttpRequestWrapper Request = new HttpRequestWrapper(Constants.IOT_HUB_ADDRESS, Constants.Urls.DEVICE_PATH);

                // Act
                var     fetchCallResponse   = Request.Get(createdDeviceId, null);
                JObject fetchCallDevice     = JObject.Parse(fetchCallResponse.Content);
                var     configTemplateModel = JObject.Parse(configTemplate)["UpdateTwin"]["Properties"]["Model"];
                var     deviceConfigModel   = fetchCallDevice["Properties"]["Desired"]["Model"];

                // Asserts --- if device tags are updated correctly.
                Assert.True(JToken.DeepEquals(configTemplateModel, deviceConfigModel));
            }