/** * 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)); }
// Helper method to verify if job was successful. /** * Assert job type and job status for completion. */ internal static void AssertJobwasCompletedSuccessfully(int jobType, HttpRequestWrapper request, JObject job) { // Check if job was submitted successfully. Assert.True((Constants.Jobs.JOB_QUEUED == job["Status"].ToObject <int>()) || (Constants.Jobs.JOB_IN_PROGRESS == job["Status"].ToObject <int>())); Assert.Equal <int>(jobType, job["Type"].ToObject <int>()); // Get Job status by polling. This is to verify if job was successful. var tagJobStatus = GetJobStatusWithReTry(request, job["JobId"].ToString()); // Assert to see if last try yielded correct status. Assert.Equal <int>(Constants.Jobs.JOB_COMPLETED, tagJobStatus["Status"].ToObject <int>()); Assert.Equal <int>(jobType, tagJobStatus["Type"].ToObject <int>()); // TODO: Verify Result Statistics from the response JSON. }
// Helper methods for fetching (and retrying) the current Job Status. /** * Monitor job status using polling (re-try) mechanism */ internal static JObject GetJobStatusWithReTry(HttpRequestWrapper Request, string jobId) { var jobStatus = GetJobStatus(Request, jobId); for (int trials = 0; trials < Constants.Jobs.MAX_TRIALS; trials++) { if (Constants.Jobs.JOB_COMPLETED == jobStatus["Status"].ToObject <int>()) { break; } Thread.Sleep(Constants.Jobs.WAIT); jobStatus = GetJobStatus(Request, jobId); } return(jobStatus); }
/** * 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)); }
public DevicePropertiesTest() { this.Request = new HttpRequestWrapper(Constants.IOT_HUB_ADDRESS, Constants.Urls.DEVICE_PATH); this.PropertyRequest = new HttpRequestWrapper(Constants.IOT_HUB_ADDRESS, Constants.Urls.DEVICE_PROPERTIES_PATH); this.CreateDevice(); }