예제 #1
0
        public override async Task Execute(ILogger logger, TestParameters testParameters)
        {
            JObject resolvedParameters = (JObject)testParameters.ResolveParameters(_parameters);

            DeviceMethodReturnValue returnValue = await testParameters.IoTCloudServices.IoTHubManager.InvokeDirectMethod(
                testParameters.IoTHubDeviceId,
                _methodName,
                resolvedParameters.ToString());

            if (returnValue.Status != _expectedReturnCode)
            {
                LogMismatch(logger, _expectedReturnCode.ToString(), returnValue.Status.ToString());
                ReportResult(logger, false, "Unexpected direct method return value.");
            }

            JToken actualReturnJson = JValue.Parse(returnValue.Payload);

            List <string> errorList = new List <string>();

            if (!TestCaseHelpers.VerifyPropertiesPresent("returnPayload", _expectedReturnJson, actualReturnJson, errorList))
            {
                logger.Log(LogLevel.Verbose, "---- Final Result:");
                logger.Log(LogLevel.Verbose, returnValue.Payload.ToString());
                logger.Log(LogLevel.Verbose, "---- Expected Present Result:");
                logger.Log(LogLevel.Verbose, _expectedReturnJson.ToString());
                ReportResult(logger, false, "Unexpected direct method return payload.");
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }