Example #1
0
        public static DeviceTwinTestCase FromJson(ILogger logger, JObject testCaseJson)
        {
            DeviceTwinTestCase testCase = new DeviceTwinTestCase();

            TestCase.FromJson(logger, testCaseJson, testCase);

            // Input
            testCase._desiredState = JsonHelpers.GetObject(testCaseJson, Constants.TCJsonInput);

            // Output
            JObject output = JsonHelpers.GetObject(testCaseJson, Constants.TCJsonOutput);

            JObject expectedPresentReportedState = JsonHelpers.GetObject(output, Constants.TCJsonOutputPresent);

            testCase._expectedPresentReportedState = (JObject)expectedPresentReportedState.DeepClone();

            JObject expectedAbsentReportedState;

            if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputAbsent, out expectedAbsentReportedState))
            {
                testCase._expectedAbsentReportedState = (JObject)expectedAbsentReportedState.DeepClone();
            }

            return(testCase);
        }
        private static TestCase TestCaseFromJson(ILogger logger, JObject testCaseJson)
        {
            string type;

            if (!JsonHelpers.TryGetString(testCaseJson, Constants.TCJsonType, out type))
            {
                throw new Exception("Test case json is missing required property `" + Constants.TCJsonType + "`.");
            }

            TestCase testCase = null;

            switch (type)
            {
            case Constants.TCJsonTypeInteractionDeviceTwin:
                testCase = DeviceTwinTestCase.FromJson(logger, testCaseJson);
                break;

            case Constants.TCJsonTypeInteractionDirectMethod:
                testCase = DirectMethodTestCase.FromJson(logger, testCaseJson);
                break;

            default:
                throw new Exception("Test case json type is unknown `" + type + "`.");
            }

            return(testCase);
        }
        public static DeviceTwinTestCase FromJson(ILogger logger, JObject testCaseJson)
        {
            string name;

            if (!JsonHelpers.TryGetString(testCaseJson, Constants.TCJsonName, out name))
            {
                ReportError(logger, "Missing " + Constants.TCJsonName);
                return(null);
            }

            string description;

            if (!JsonHelpers.TryGetString(testCaseJson, Constants.TCJsonDescription, out description))
            {
                ReportError(logger, "Missing " + Constants.TCJsonDescription);
                return(null);
            }

            JObject input;

            if (!JsonHelpers.TryGetObject(testCaseJson, Constants.TCJsonInput, out input))
            {
                ReportError(logger, "Missing " + Constants.TCJsonInput);
                return(null);
            }

            JObject output;

            if (!JsonHelpers.TryGetObject(testCaseJson, Constants.TCJsonOutput, out output))
            {
                ReportError(logger, "Missing " + Constants.TCJsonOutput);
                return(null);
            }

            JObject expectedPresentReportedState = null;

            if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputPresent, out expectedPresentReportedState))
            {
                expectedPresentReportedState = (JObject)expectedPresentReportedState.DeepClone();
            }

            JObject expectedAbsentReportedState = null;

            if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputAbsent, out expectedAbsentReportedState))
            {
                expectedAbsentReportedState = (JObject)expectedAbsentReportedState.DeepClone();
            }

            DeviceTwinTestCase testCase = new DeviceTwinTestCase();

            testCase._name         = name;
            testCase._description  = description;
            testCase._desiredState = input;
            testCase._expectedPresentReportedState = expectedPresentReportedState;
            testCase._expectedAbsentReportedState  = expectedAbsentReportedState;
            return(testCase);
        }
Example #4
0
        private static TestCase TestCaseFromJson(ILogger logger, JObject testCaseJson)
        {
            string type;

            if (!JsonHelpers.TryGetString(testCaseJson, Constants.TCJsonType, out type))
            {
                return(null);
            }

            TestCase testCase = null;

            switch (type)
            {
            case Constants.TCJsonInteractionDeviceTwin:
                testCase = DeviceTwinTestCase.FromJson(logger, testCaseJson);
                break;

            case Constants.TCJsonInteractionDirectMethod:
                testCase = DirectMethodTestCase.FromJson(logger, testCaseJson);
                break;

            case Constants.TCJsonInteractionDotNetApi:
            {
                string dotNetApiName;
                if (JsonHelpers.TryGetString(testCaseJson, Constants.TCJsonDotNetApiName, out dotNetApiName))
                {
                    switch (dotNetApiName)
                    {
                    case Constants.TCJsonSetWindowsUpdateRingAsync:
                        // testCase = SetWindowsUpdateRingAsyncTestCase.FromJson(testCaseJson);
                        break;
                    }
                }
            }
            break;
            }

            return(testCase);
        }