Esempio n. 1
0
        public override async Task <bool> Execute(ILogger logger, TestParameters testParameters)
        {
            logger.Log(LoggingLevel.Information, "            Executing test case (" + _name + ")...");

            JObject resolvedDesiredState = (JObject)testParameters.ResolveParameters(_desiredState);

            await _deviceController.UpdateDesired(resolvedDesiredState.ToString());

            logger.Log(LoggingLevel.Information, "              Analyzing results...");

            Debug.WriteLine("---- Final Result:");
            Debug.WriteLine(_actualReportedState.ToString());

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

            Debug.WriteLine("---- Expected Present Result:");
            if (_expectedPresentReportedState != null)
            {
                Debug.WriteLine(_expectedPresentReportedState.ToString());
                result &= TestCaseHelpers.VerifyPropertiesPresent("deviceTwin", _expectedPresentReportedState, _actualReportedState, errorList);
            }

            Debug.WriteLine("---- Expected Absent Result:");
            if (_expectedAbsentReportedState != null)
            {
                Debug.WriteLine(_expectedAbsentReportedState.ToString());
                result &= TestCaseHelpers.VerifyPropertiesAbsent(_expectedAbsentReportedState, _actualReportedState, errorList);
            }

            ReportResult(logger, result, errorList);

            return(result);
        }
        public override async Task <bool> Execute(ILogger logger, TestParameters testParameters)
        {
            logger.Log(LoggingLevel.Information, "            Executing test case (" + _name + ")...");

            JObject resolvedParameters = (JObject)testParameters.ResolveParameters(_parameters);

            MethodResponse response = await _deviceController.InvokeDirectMethod(_methodName, resolvedParameters.ToString());

            string resultString = response.Result != null?Encoding.UTF8.GetString(response.Result) : "";

            int resultCode = response.Status;

            logger.Log(LoggingLevel.Information, "              Analyzing results...");

            Debug.WriteLine("Final Result:");
            Debug.WriteLine("resultString: " + resultString);
            Debug.WriteLine("resultCode  : " + resultCode);

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

            if (_expectedReturnCode != response.Status)
            {
                string msg = "Unexpected return code: Expected [" + _expectedReturnCode + "], Actual [" + response.Status + "]";
                errorList.Add(msg);
                Debug.WriteLine(msg);
                result = false;
            }
            else
            {
                JObject actualReturnJson = (JObject)JsonConvert.DeserializeObject(resultString);
                if (_expectedReturnJson != null)
                {
                    result &= TestCaseHelpers.VerifyPropertiesPresent("returnValue", _expectedReturnJson, actualReturnJson, errorList);
                }

                Debug.WriteLine("---- Expected Present Result:");
                if (_expectedPresentReportedState != null)
                {
                    Debug.WriteLine(_expectedPresentReportedState.ToString());
                    result &= TestCaseHelpers.VerifyPropertiesPresent("deviceTwin", _expectedPresentReportedState, _actualReportedState, errorList);
                }

                Debug.WriteLine("---- Expected Absent Result:");
                if (_expectedAbsentReportedState != null)
                {
                    Debug.WriteLine(_expectedAbsentReportedState.ToString());
                    result &= TestCaseHelpers.VerifyPropertiesAbsent(_expectedAbsentReportedState, _actualReportedState, errorList);
                }
            }

            base.ReportResult(logger, result, errorList);

            return(result);
        }
        public override async Task <bool> Execute(ILogger logger, TestParameters testParameters)
        {
            logger.Log(LoggingLevel.Information, "            Executing test case (" + _name + ")...");

            JObject resolvedInput = (JObject)testParameters.ResolveParameters(_input);

            WindowsUpdateRingState state = RingStateFromJson(logger, resolvedInput);

            await _app.DMClient.SetWindowsUpdateRingAsync(state);

            logger.Log(LoggingLevel.Information, "              Analyzing results...");

            Debug.WriteLine("Final Result:");
            Debug.WriteLine("Actual Result: " + _actualReportedState.ToString());

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

            Debug.WriteLine("---- Expected Present Result:");
            if (_expectedPresentReportedState != null)
            {
                Debug.WriteLine(_expectedPresentReportedState.ToString());
                result &= TestCaseHelpers.VerifyPropertiesPresent("returnValue", _expectedPresentReportedState, _actualReportedState, errorList);
            }

            Debug.WriteLine("---- Expected Absent Result:");
            if (_expectedAbsentReportedState != null)
            {
                Debug.WriteLine(_expectedAbsentReportedState.ToString());
                result &= TestCaseHelpers.VerifyPropertiesAbsent(_expectedAbsentReportedState, _actualReportedState, errorList);
            }

            ReportResult(logger, result, errorList);

            return(result);
        }