Beispiel #1
0
        public void APILearnSwaggerMetroTest()
        {
            //Arrange
            SwaggerParser wsdlParser = new SwaggerParser();
            ObservableList <ApplicationAPIModel> AAMSList = new ObservableList <ApplicationAPIModel>();

            //Act
            string path = TestResources.GetTestResourcesFile(@"AutoPilot\Swagger\swagger.json");

            wsdlParser.ParseDocument(path, AAMSList);


            //Assert
            Assert.AreEqual(AAMSList.Count, 22, "Is API's equal to 6");
            Assert.AreEqual(AAMSList[0].EndpointURL, "https://petstore.swagger.io/v2/pet", "Is EndpointURL equal");
            Assert.AreEqual(String.IsNullOrEmpty(AAMSList[0].RequestBody), false, "Is body not empty equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters.Count, 8, "are parameters are equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[0].PlaceHolder, "<ID>", "are parameters are equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[1].PlaceHolder, "<ID1>", "are parameters are equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[2].PlaceHolder, "<NAME>", "are parameters are equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[3].PlaceHolder, "<NAME1>", "are parameters are equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[4].PlaceHolder, "<PHOTOURLS[0]>", "Is parameter name equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[5].PlaceHolder, "<ID2>", "Is parameter name equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[6].PlaceHolder, "<NAME2>", "Is parameter name equal");
            Assert.AreEqual(AAMSList[0].AppModelParameters[7].PlaceHolder, "<STATUS>", "Is parameter name equal");
        }
        private async Task <bool> ShowSwaggerOperations()
        {
            AddAPIModelWizard.ProcessStarted();
            bool          parseSuccess = true;
            SwaggerParser SwaggerPar   = new SwaggerParser();
            ObservableList <ApplicationAPIModel> AAMTempList      = new ObservableList <ApplicationAPIModel>();
            ObservableList <ApplicationAPIModel> AAMCompletedList = new ObservableList <ApplicationAPIModel>();


            foreach (TemplateFile XTF in AddAPIModelWizard.XTFList)
            {
                try
                {
                    AAMTempList = await Task.Run(() => SwaggerPar.ParseDocument(XTF.FilePath));

                    AAMCompletedList = AAMTempList;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Details:" + Environment.NewLine + ex.Message, "Failed to Parse the Swagger File" + 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 Swagger file " + XTF.FilePath);
                    parseSuccess = false;
                }
            }

            AddAPIModelWizard.AAMList         = AAMCompletedList;
            xApisSelectionGrid.DataSourceList = AddAPIModelWizard.AAMList;
            // AddAPIModelWizard.FinishEnabled = false;
            AddAPIModelWizard.ProcessEnded();

            return(parseSuccess);
        }
        private async Task <bool> ShowSwaggerOperations()
        {
            AddAPIModelWizard.ProcessStarted();
            bool          parseSuccess = true;
            SwaggerParser SwaggerPar   = new SwaggerParser();
            ObservableList <ApplicationAPIModel> AAMTempList      = new ObservableList <ApplicationAPIModel>();
            ObservableList <ApplicationAPIModel> AAMCompletedList = new ObservableList <ApplicationAPIModel>();



            try
            {
                AAMTempList = await Task.Run(() => SwaggerPar.ParseDocument(AddAPIModelWizard.URL));

                AAMCompletedList = AAMTempList;
            }
            catch (Exception ex)
            {
                Reporter.ToUser(eUserMsgKeys.ParsingError, "Failed to Parse the Swagger File" + AddAPIModelWizard.URL);
                GingerCoreNET.ReporterLib.Reporter.ToLog(GingerCoreNET.ReporterLib.eLogLevel.ERROR, "Error Details: " + ex.Message + " Failed to Parse the Swagger file " + AddAPIModelWizard.URL);
                parseSuccess = false;
            }


            AddAPIModelWizard.AAMList         = AAMCompletedList;
            xApisSelectionGrid.DataSourceList = AddAPIModelWizard.AAMList;
            // AddAPIModelWizard.FinishEnabled = false;
            AddAPIModelWizard.ProcessEnded();

            return(parseSuccess);
        }
 private bool CheckForSwaggerParser(string fileName)
 {
     try
     {
         SwaggerParser swaggerParser = new SwaggerParser();
         ObservableList <ApplicationAPIModel> swaggerList = new ObservableList <ApplicationAPIModel>();
         swaggerList = swaggerParser.ParseDocument(fileName, swaggerList);
         if (swaggerList == null || swaggerList.Count == 0)
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         Reporter.ToLog(eLogLevel.WARN, ex.Message, ex);
         return(false);
     }
 }
Beispiel #5
0
        public void SwaggerParseCheckHeaderAndParamsCount()
        {
            //Arrange
            SwaggerParser parserForBillingAccount         = new SwaggerParser();
            string        createPaymentProfileFileName    = TestResources.GetTestResourcesFile(@"Swagger" + Path.DirectorySeparatorChar + "petstore_swagger.json");
            ObservableList <ApplicationAPIModel> requests = new ObservableList <ApplicationAPIModel>();

            //Act
            requests = parserForBillingAccount.ParseDocument(createPaymentProfileFileName, requests);
            ApplicationAPIModel RequestToTest = requests.Where(x => x.Name == @"Deletes a pet").ElementAt(0);

            //Assert
            Assert.AreEqual(1, RequestToTest.HttpHeaders.Count());


            RequestToTest = requests.Where(x => x.Name == @"Find purchase order by ID").ElementAt(0);
            Assert.AreEqual(6, RequestToTest.ReturnValues.Count(), "SwaggerCheckResponseParameterCount");


            RequestToTest = requests.Where(x => x.Name == @"Place an order for a pet").ElementAt(0);
            string requestBody = @"{" + Environment.NewLine + "\"id\": <ID>," + Environment.NewLine + "\"petId\": <PETID>," + Environment.NewLine + "\"quantity\": <QUANTITY>," + Environment.NewLine + "\"shipDate\": \"<SHIPDATE>\"," + Environment.NewLine + "\"status\": \"<STATUS>\"," + Environment.NewLine + "\"complete\": <COMPLETE>" + Environment.NewLine + "}";

            Assert.AreEqual(requestBody.Replace(" ", ""), RequestToTest.RequestBody.Replace(" ", ""), "CheckResponseBody");
        }
        private async Task <bool> ShowSwaggerOperations()
        {
            AddAPIModelWizard.ProcessStarted();
            bool          parseSuccess = true;
            SwaggerParser SwaggerPar   = new SwaggerParser();

            AddAPIModelWizard.LearnedAPIModelsList = new ObservableList <ApplicationAPIModel>();
            xApisSelectionGrid.DataSourceList      = AddAPIModelWizard.LearnedAPIModelsList;


            try
            {
                await Task.Run(() => SwaggerPar.ParseDocument(AddAPIModelWizard.URL, AddAPIModelWizard.LearnedAPIModelsList));
            }
            catch (Exception ex)
            {
                Reporter.ToUser(eUserMsgKey.ParsingError, "Failed to Parse the Swagger File" + AddAPIModelWizard.URL);
                Reporter.ToLog(eLogLevel.ERROR, "Error Details: " + ex.Message + " Failed to Parse the Swagger file " + AddAPIModelWizard.URL);
                parseSuccess = false;
            }
            AddAPIModelWizard.ProcessEnded();

            return(parseSuccess);
        }