public void JSONTemplateCreateBillingArrangement() { //Arrange JSONTemplateParser jSONTemplateParser = new JSONTemplateParser(); string createBillingArrangementFileName = TestResources.GetTestResourcesFile(@"AutoPilot\JSONTemplates\login.json"); //Act ObservableList <ApplicationAPIModel> createPaymentProfileModels = new ObservableList <ApplicationAPIModel>(); jSONTemplateParser.ParseDocument(createBillingArrangementFileName, createPaymentProfileModels); TemplateFile TempleteFile = new TemplateFile() { FilePath = createBillingArrangementFileName }; createPaymentProfileModels[0].OptionalValuesTemplates.Add(TempleteFile); Dictionary <Tuple <string, string>, List <string> > OptionalValuesPerParameterDict = new Dictionary <Tuple <string, string>, List <string> >(); ImportOptionalValuesForParameters ImportOptionalValues = new ImportOptionalValuesForParameters(); ImportOptionalValues.ShowMessage = false; ImportOptionalValues.GetAllOptionalValuesFromExamplesFiles(createPaymentProfileModels[0], OptionalValuesPerParameterDict); ImportOptionalValues.PopulateOptionalValuesForAPIParameters(createPaymentProfileModels[0], OptionalValuesPerParameterDict); //Assert Assert.AreEqual(createPaymentProfileModels.Count, 1, "APIModels count"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters.Count, 2, "AppModelParameters count"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters[0].PlaceHolder, "<USER>", "PlaceHolder name check"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters[1].PlaceHolder, "<PASSWORD>", "PlaceHolder name check"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters[0].OptionalValuesList.Count, 1, "AppModelParameters count"); Assert.AreEqual(createPaymentProfileModels[0].AppModelParameters[0].OptionalValuesList[0].Value, "restOwner", "OptionalValue check"); }
private async Task <bool> ShowJsonTemplatesOperations() { bool parseSuccess = true; JSONTemplateParser JsonTemplate = new JSONTemplateParser(); ObservableList <ApplicationAPIModel> AAMTempList = new ObservableList <ApplicationAPIModel>(); ObservableList <ApplicationAPIModel> AAMCompletedList = new ObservableList <ApplicationAPIModel>(); foreach (TemplateFile XTF in AddAPIModelWizard.XTFList) { try { AAMTempList = await Task.Run(() => JsonTemplate.ParseDocument(XTF.FilePath, AAMCompletedList, AddAPIModelWizard.AvoidDuplicatesNodes)); if (!string.IsNullOrEmpty(XTF.MatchingResponseFilePath)) { AAMTempList.Last().ReturnValues = await Task.Run(() => APIConfigurationsDocumentParserBase.ParseResponseSampleIntoReturnValuesPerFileType(XTF.MatchingResponseFilePath)); } } catch (Exception ex) { Reporter.ToUser(eUserMsgKey.ParsingError, "Failed to Parse the JSon" + XTF.FilePath); Reporter.ToLog(eLogLevel.ERROR, "Error Details: " + ex.Message + " Failed to Parse the JSon " + XTF.FilePath); parseSuccess = false; } } AddAPIModelWizard.AAMList = AAMCompletedList; xApisSelectionGrid.DataSourceList = AddAPIModelWizard.AAMList; return(parseSuccess); }
private async Task <bool> ShowJsonTemplatesOperations() { bool parseSuccess = true; JSONTemplateParser JsonTemplate = new JSONTemplateParser(); ObservableList <ApplicationAPIModel> AAMTempList = new ObservableList <ApplicationAPIModel>(); ObservableList <ApplicationAPIModel> AAMCompletedList = new ObservableList <ApplicationAPIModel>(); foreach (TemplateFile XTF in AddAPIModelWizard.XTFList) { try { AAMTempList = await Task.Run(() => JsonTemplate.ParseDocument(XTF.FilePath, AddAPIModelWizard.AvoidDuplicatesNodes)); if (!string.IsNullOrEmpty(XTF.MatchingResponseFilePath)) { AAMTempList[0].ReturnValues = await Task.Run(() => APIConfigurationsDocumentParserBase.ParseResponseSampleIntoReturnValuesPerFileType(XTF.MatchingResponseFilePath)); } AAMCompletedList.Add(AAMTempList[0]); } catch (Exception ex) { MessageBox.Show("Error Details:" + Environment.NewLine + ex.Message, "Failed to Parse the JSon" + XTF.FilePath, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error, System.Windows.MessageBoxResult.None); GingerCoreNET.ReporterLib.Reporter.ToLog(GingerCoreNET.ReporterLib.eLogLevel.ERROR, "Error Details: " + ex.Message + " Failed to Parse the JSon " + XTF.FilePath); parseSuccess = false; } } AddAPIModelWizard.AAMList = AAMCompletedList; xApisSelectionGrid.DataSourceList = AddAPIModelWizard.AAMList; // AddAPIModelWizard.FinishEnabled = false; return(parseSuccess); }
private bool CheckForJsonParser(string fileName) { try { JSONTemplateParser jsonParser = new JSONTemplateParser(); ObservableList <ApplicationAPIModel> jsonList = new ObservableList <ApplicationAPIModel>(); jsonList = jsonParser.ParseDocument(fileName, jsonList); if (jsonList == null || jsonList.Count == 0) { return(false); } return(true); } catch (Exception ex) { Reporter.ToLog(eLogLevel.WARN, ex.Message, ex); return(false); } }