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); }
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); }
public static DirectMethodTestCase FromJson(ILogger logger, JObject testCaseJson) { DirectMethodTestCase testCase = new DirectMethodTestCase(); TestCase.FromJson(logger, testCaseJson, testCase); testCase._methodName = JsonHelpers.GetString(testCaseJson, Constants.JsonDirectMethodName); // Input testCase._parameters = JsonHelpers.GetObject(testCaseJson, Constants.TCJsonInput); // Output JObject output = JsonHelpers.GetObject(testCaseJson, Constants.TCJsonOutput); // Output - DeviceTwin JObject deviceTwin = null; if (JsonHelpers.TryGetObject(output, Constants.TCJsonMethodDeviceTwin, out deviceTwin)) { if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputPresent, out testCase._expectedPresentReportedState)) { testCase._expectedPresentReportedState = (JObject)testCase._expectedPresentReportedState.DeepClone(); } if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputAbsent, out testCase._expectedAbsentReportedState)) { testCase._expectedAbsentReportedState = (JObject)testCase._expectedAbsentReportedState.DeepClone(); } } // Output - Direct Method Return JsonHelpers.TryGetToken(output, Constants.TCJsonMethodReturnJson, out testCase._expectedReturnJson); JsonHelpers.TryGetLong(output, Constants.TCJsonMethodReturnCode, out testCase._expectedReturnCode); return(testCase); }
public static DirectMethodTestCase 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); } string methodName; if (!JsonHelpers.TryGetString(testCaseJson, Constants.JsonDirectMethodName, out methodName)) { ReportError(logger, "Missing " + Constants.JsonDirectMethodName); return(null); } JObject input; if (!JsonHelpers.TryGetObject(testCaseJson, Constants.TCJsonInput, out input)) { ReportError(logger, "Missing " + Constants.TCJsonInput); return(null); } JObject output; JObject expectedPresentReportedState = null; JObject expectedAbsentReportedState = null; JObject returnJson = null; JValue returnCode = null; if (!JsonHelpers.TryGetObject(testCaseJson, Constants.TCJsonOutput, out output)) { ReportError(logger, "Missing " + Constants.TCJsonOutput); return(null); } int delay = 0; if (!JsonHelpers.TryGetInt(output, Constants.TCJsonDelay, out delay)) { delay = DefaultDelay; } JObject deviceTwin = null; if (JsonHelpers.TryGetObject(output, Constants.TCJsonMethodDeviceTwin, out deviceTwin)) { if (JsonHelpers.TryGetObject(deviceTwin, Constants.TCJsonOutputPresent, out expectedPresentReportedState)) { expectedPresentReportedState = (JObject)expectedPresentReportedState.DeepClone(); } if (JsonHelpers.TryGetObject(deviceTwin, Constants.TCJsonOutputAbsent, out expectedAbsentReportedState)) { expectedAbsentReportedState = (JObject)expectedAbsentReportedState.DeepClone(); } } JsonHelpers.TryGetObject(output, Constants.TCJsonMethodReturnJson, out returnJson); JsonHelpers.TryGetValue(output, Constants.TCJsonMethodReturnCode, out returnCode); DirectMethodTestCase testCase = new DirectMethodTestCase(); testCase._name = name; testCase._description = description; testCase._delay = delay; testCase._methodName = methodName; testCase._parameters = input; testCase._expectedPresentReportedState = expectedPresentReportedState; testCase._expectedAbsentReportedState = expectedAbsentReportedState; testCase._expectedReturnJson = returnJson; testCase._expectedReturnCode = (int)returnCode; return(testCase); }