private async Task <bool> Execute(ILogger logger, TestParameters testParameters) { logger.Log(LogLevel.Information, " Executing test cases..."); IoTHubManager client = new IoTHubManager(testParameters.IoTHubConnectionString); bool result = await ClearDeviceTwin(logger, client, testParameters); if (!result) { return(result); } foreach (TestCase testCase in _testCases) { result = await testCase.Execute(logger, client, testParameters); if (!result) { break; } } return(result); }
private async Task <bool> ClearDeviceTwin(ILogger logger, IoTHubManager client, TestParameters testParameters) { logger.Log(LogLevel.Information, "Clearing device: " + testParameters.IoTHubDeviceId); // Clean desired properties... // ToDo: need to read those properties from the scenario information. await client.UpdateDesiredProperty(testParameters.IoTHubDeviceId, Constants.JsonDeviceInfo, null); await client.UpdateDesiredProperty(testParameters.IoTHubDeviceId, Constants.JsonRebootInfo, null); await client.UpdateDesiredProperty(testParameters.IoTHubDeviceId, Constants.JsonTimeInfo, null); await client.UpdateDesiredProperty(testParameters.IoTHubDeviceId, Constants.JsonWindowsTelemetry, null); await client.UpdateDesiredProperty(testParameters.IoTHubDeviceId, Constants.JsonWindowsUpdate, null); // Clean reported properties... DeviceMethodReturnValue ret = await client.InvokeDirectMethod(testParameters.IoTHubDeviceId, Constants.JsonClearReportedCmd, Constants.JsonDirectMethodEmptyParams); if (ret.Status != IoTHubManager.DirectMethodSuccessCode) { logger.Log(LogLevel.Error, "Failed to clear the reported properties. Code: " + ret.Status); return(false); } logger.Log(LogLevel.Information, "Cleared the device twin successfully"); return(true); }
public CloudServices(string iotHubConnectionString, string storageConnectionString) { if (IoTServiceClient == null) { IoTServiceClient = ServiceClient.CreateFromConnectionString(iotHubConnectionString); } if (IoTHubManager == null) { IoTHubManager = new IoTHubManager(iotHubConnectionString); } if (IoTRegistryManager == null) { IoTRegistryManager = RegistryManager.CreateFromConnectionString(iotHubConnectionString); } AzureStorageConnectionString = storageConnectionString; }
public override async Task <bool> Execute(ILogger logger, IoTHubManager client, TestParameters testParameters) { logger.Log(LogLevel.Information, " Executing test case: " + _name); JObject resolvedDesiredState = (JObject)testParameters.ResolveParameters(_desiredState); JToken desiredNode = resolvedDesiredState[Constants.JsonPropertiesRoot][Constants.JsonDesiredRoot]; if (desiredNode is JObject) { JObject desiredJObject = (JObject)desiredNode; await client.UpdateDesiredProperties(testParameters.IoTHubDeviceId, Constants.JsonDesiredRoot, desiredJObject); } else { throw new Exception("Unexpected format!"); } return(await VerifyDeviceTwin(logger, client, testParameters, _delay)); }
private async Task <bool> ClearDeviceTwin(ILogger logger, IoTHubManager client, TestParameters testParameters) { logger.Log(LogLevel.Information, " Clearing device: " + testParameters.IoTHubDeviceId); // Clear reboot info await client.UpdateDesiredProperties(testParameters.IoTHubDeviceId, Constants.JsonRebootInfo, null); // Tell the device to clear its reported properties... DeviceMethodReturnValue ret = await client.InvokeDirectMethod(testParameters.IoTHubDeviceId, Constants.JsonClearReportedCmd, Constants.JsonDirectMethodEmptyParams); if (ret.Status != IoTHubManager.DirectMethodSuccessCode) { logger.Log(LogLevel.Error, "Failed to clear the reported properties. Code: " + ret.Status); return(false); } logger.Log(LogLevel.Information, " Cleared the device twin successfully"); return(true); }
protected async Task <bool> VerifyDeviceTwin(ILogger logger, IoTHubManager client, TestParameters testParameters, int seconds) { logger.Log(LogLevel.Information, " Waiting " + seconds + " seconds for the device twin to be updated..."); await Task.Delay(seconds * 1000); DeviceData deviceData = await client.GetDeviceData(testParameters.IoTHubDeviceId); JObject reportedProperties = (JObject)JsonConvert.DeserializeObject(deviceData.reportedPropertiesJson); logger.Log(LogLevel.Verbose, "---- Final Result:"); logger.Log(LogLevel.Verbose, reportedProperties.ToString()); List <string> errorList = new List <string>(); bool result = true; logger.Log(LogLevel.Verbose, "---- Expected Present Result:"); if (_expectedPresentReportedState != null) { JObject expectedPresentReported = (JObject)_expectedPresentReportedState[Constants.JsonPropertiesRoot][Constants.JsonReportedRoot]; if (expectedPresentReported != null) { logger.Log(LogLevel.Verbose, expectedPresentReported.ToString()); result &= TestCaseHelpers.VerifyPropertiesPresent(Constants.JsonDeviceTwin, expectedPresentReported, reportedProperties, errorList); } } logger.Log(LogLevel.Verbose, "---- Expected Absent Result:"); if (_expectedAbsentReportedState != null) { JObject expectedAbsentReported = (JObject)_expectedAbsentReportedState[Constants.JsonPropertiesRoot][Constants.JsonReportedRoot]; if (expectedAbsentReported != null) { logger.Log(LogLevel.Verbose, expectedAbsentReported.ToString()); result &= TestCaseHelpers.VerifyPropertiesAbsent(expectedAbsentReported, reportedProperties, errorList); } } ReportResult(logger, result, errorList); return(result); }
public override async Task <bool> Execute(ILogger logger, IoTHubManager client, TestParameters testParameters) { logger.Log(LogLevel.Information, " Executing test case: " + _name); JObject resolvedParameters = (JObject)testParameters.ResolveParameters(_parameters); DeviceMethodReturnValue ret = await client.InvokeDirectMethod(testParameters.IoTHubDeviceId, _methodName, resolvedParameters.ToString()); string resultString = ret.Payload; int resultCode = ret.Status; logger.Log(LogLevel.Verbose, " resultString: " + resultString); logger.Log(LogLevel.Verbose, " resultCode : " + resultCode); List <string> errorList = new List <string>(); bool result = true; if (_expectedReturnCode != resultCode) { string msg = "Unexpected return code: Expected [" + _expectedReturnCode + "], Actual [" + resultCode + "]"; errorList.Add(msg); logger.Log(LogLevel.Error, " " + msg); result = false; } else { JObject actualReturnJson = (JObject)JsonConvert.DeserializeObject(resultString); if (_expectedReturnJson != null) { result &= TestCaseHelpers.VerifyPropertiesPresent("returnValue", _expectedReturnJson, actualReturnJson, errorList); } result &= await VerifyDeviceTwin(logger, client, testParameters, _delay); } return(result); }
public abstract Task <bool> Execute(ILogger logger, IoTHubManager client, TestParameters testParameters);
public override async Task <bool> Execute(ILogger logger, IoTHubManager client, TestParameters testParameters) { JObject resolvedDesiredState = (JObject)testParameters.ResolveParameters(_desiredState); JToken desiredNode = resolvedDesiredState[Constants.JsonPropertiesRoot][Constants.JsonDesiredRoot]; if (desiredNode is JObject) { JObject desiredJObject = (JObject)desiredNode; await client.UpdateDesiredObject(testParameters.IoTHubDeviceId, desiredJObject); } else { throw new Exception("Unexpected format!"); } int seconds = 15; logger.Log(LogLevel.Information, "Waiting " + seconds + " seconds for the device twin to be updated..."); await Task.Delay(seconds * 1000); DeviceData deviceData = await client.GetDeviceData(testParameters.IoTHubDeviceId); JObject desiredProperties = (JObject)JsonConvert.DeserializeObject(deviceData.desiredPropertiesJson); JObject reportedProperties = (JObject)JsonConvert.DeserializeObject(deviceData.reportedPropertiesJson); logger.Log(LogLevel.Verbose, "---- Final Result:"); logger.Log(LogLevel.Verbose, reportedProperties.ToString()); JObject expectedWindowsReported = (JObject)_expectedPresentReportedState[Constants.JsonPropertiesRoot][Constants.JsonReportedRoot]; List <string> errorList = new List <string>(); bool result = true; logger.Log(LogLevel.Verbose, "---- Expected Present Result:"); if (expectedWindowsReported != null) { logger.Log(LogLevel.Verbose, expectedWindowsReported.ToString()); result &= TestCaseHelpers.VerifyPropertiesPresent(Constants.JsonDeviceTwin, expectedWindowsReported, reportedProperties, errorList); } else { logger.Log(LogLevel.Verbose, "None."); } logger.Log(LogLevel.Verbose, "---- Expected Absent Result:"); if (_expectedAbsentReportedState != null) { JObject expectedAbsentReported = (JObject)_expectedAbsentReportedState[Constants.JsonPropertiesRoot][Constants.JsonReportedRoot]; if (expectedAbsentReported != null) { logger.Log(LogLevel.Verbose, expectedAbsentReported.ToString()); result &= TestCaseHelpers.VerifyPropertiesAbsent(expectedAbsentReported, reportedProperties, errorList); } } else { logger.Log(LogLevel.Verbose, "None."); } ReportResult(logger, result, errorList); return(result); }
public override Task <bool> Execute(ILogger logger, IoTHubManager client, TestParameters testParameters) { return(Task.FromResult <bool>(true)); }