Ejemplo n.º 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.");
            }
        }
Ejemplo n.º 2
0
        public override async Task Execute(ILogger logger, TestParameters testParameters)
        {
            JObject resolvedDesiredState = (JObject)testParameters.ResolveParameters(_desiredState);
            JToken  desiredNode          = resolvedDesiredState[Constants.JsonPropertiesRoot][Constants.JsonDesiredRoot];

            if (desiredNode is JObject)
            {
                JObject desiredJObject = (JObject)desiredNode;
                await testParameters.IoTCloudServices.IoTHubManager.UpdateDesiredObject(testParameters.IoTHubDeviceId, desiredJObject);
            }
            else
            {
                throw new Exception("DeviceTwin Test Case: Unexpected format!");
            }

            logger.Log(LogLevel.Information, IndentInner + "Waiting " + _readBackPause + " seconds for the device twin to be updated...");
            await Task.Delay(_readBackPause * 1000);

            DeviceData deviceData = await testParameters.IoTCloudServices.IoTHubManager.GetDeviceData(testParameters.IoTHubDeviceId);

            JObject desiredProperties  = (JObject)JsonConvert.DeserializeObject(deviceData.desiredPropertiesJson);
            JObject reportedProperties = (JObject)JsonConvert.DeserializeObject(deviceData.reportedPropertiesJson);

            JObject expectedWindowsReported = (JObject)_expectedPresentReportedState[Constants.JsonPropertiesRoot][Constants.JsonReportedRoot];

            List <string> errorList = new List <string>();
            bool          result    = true;

            if (expectedWindowsReported != null)
            {
                if (!TestCaseHelpers.VerifyPropertiesPresent(Constants.JsonDeviceTwin, expectedWindowsReported, reportedProperties, errorList))
                {
                    logger.Log(LogLevel.Verbose, "---- Final Result:");
                    logger.Log(LogLevel.Verbose, reportedProperties.ToString());
                    logger.Log(LogLevel.Verbose, "---- Expected Present Result:");
                    logger.Log(LogLevel.Verbose, expectedWindowsReported.ToString());
                    result = false;
                }
            }

            if (_expectedAbsentReportedState != null)
            {
                JObject expectedAbsentReported = (JObject)_expectedAbsentReportedState[Constants.JsonPropertiesRoot][Constants.JsonReportedRoot];
                if (expectedAbsentReported != null)
                {
                    if (!TestCaseHelpers.VerifyPropertiesAbsent(expectedAbsentReported, reportedProperties, errorList))
                    {
                        logger.Log(LogLevel.Verbose, "---- Final Result:");
                        logger.Log(LogLevel.Verbose, reportedProperties.ToString());
                        logger.Log(LogLevel.Verbose, "---- Expected Absent Result:");
                        logger.Log(LogLevel.Verbose, expectedAbsentReported.ToString());
                        result = false;
                    }
                }
            }

            ReportResult(logger, result, errorList);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 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);
        }