public static SetWindowsUpdateRingAsyncTestCase FromJson(ILogger logger, JObject testCaseJson) { logger.Log(LoggingLevel.Information, " Parsing test case..."); 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; JObject expectedPresentReportedState = null; JObject expectedAbsentReportedState = null; if (!JsonHelpers.TryGetObject(testCaseJson, Constants.TCJsonOutput, out output)) { ReportError(logger, "Missing " + Constants.TCJsonOutput); return(null); } else { JObject deviceTwin; if (JsonHelpers.TryGetObject(output, Constants.TCJsonInteractionDeviceTwin, out deviceTwin)) { if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputPresent, out expectedPresentReportedState)) { expectedPresentReportedState = (JObject)expectedPresentReportedState.DeepClone(); } if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputAbsent, out expectedAbsentReportedState)) { expectedAbsentReportedState = (JObject)expectedAbsentReportedState.DeepClone(); } } } SetWindowsUpdateRingAsyncTestCase testCase = new SetWindowsUpdateRingAsyncTestCase(); testCase._name = name; testCase._description = description; testCase._input = input; testCase._expectedPresentReportedState = expectedPresentReportedState; testCase._expectedAbsentReportedState = expectedAbsentReportedState; return(testCase); }
public static DirectMethodTestCase FromJson(ILogger logger, JObject testCaseJson) { logger.Log(LoggingLevel.Information, " Parsing test case..."); 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, JsonDirectMethodName, out methodName)) { ReportError(logger, "Missing " + 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); } else { JObject deviceTwin = null; if (JsonHelpers.TryGetObject(output, Constants.TCJsonMethodDeviceTwin, out deviceTwin)) { if (JsonHelpers.TryGetObject(output, Constants.TCJsonOutputPresent, out expectedPresentReportedState)) { expectedPresentReportedState = (JObject)expectedPresentReportedState.DeepClone(); } if (JsonHelpers.TryGetObject(output, 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._methodName = methodName; testCase._parameters = input; testCase._expectedPresentReportedState = expectedPresentReportedState; testCase._expectedAbsentReportedState = expectedAbsentReportedState; testCase._expectedReturnJson = returnJson; testCase._expectedReturnCode = (int)returnCode; return(testCase); }