Ejemplo n.º 1
0
        public void APILearnJSONParseWithArrayTest()
        {
            //Arrange
            var jsonString = @"{
                                'cars': {
                                    'Nissan': [
                                        {'model':'Sentra', 'doors':4},
                                        {'model':'Maxima', 'doors':4},
                                        {'model':'Skyline', 'doors':2}
                                    ],
                                    'Ford': [
                                        {'model':'Taurus', 'doors':4},
                                        {'model':'Escort', 'doors':4}
                                    ],
		                            'NewCar':[ ],
                                    'NewCar2':['item1','item2']
                                    }
                                  }";

            //Act
            object[] jsonNodeList = JSONTemplateParser.GenerateBodyANdModelParameters(jsonString);


            //Assert
            Assert.AreEqual(2, jsonNodeList.Length);
        }
Ejemplo n.º 2
0
        private ObservableList <AppModelParameter> GenerateJsonBody(ApplicationAPIModel aAM, JsonSchema4 operation)
        {
            string SampleBody = JsonSchemaTools.JsonSchemaFaker(operation);

            object[] BodyandModelParameters = JSONTemplateParser.GenerateBodyANdModelParameters(SampleBody);
            aAM.RequestBody = (string)BodyandModelParameters[0];
            return((ObservableList <AppModelParameter>)BodyandModelParameters[1]);
        }
Ejemplo n.º 3
0
        private ObservableList <AppModelParameter> GenerateXMLBody(ApplicationAPIModel aAM, JsonSchema4 operation)
        {
            string SampleBody = JsonSchemaTools.JsonSchemaFaker(operation, true);
            string XMlName    = operation.HasReference? XMlName = operation.Reference.Xml.Name: XMlName = operation.Xml.Name;



            SampleBody = "{\"" + XMlName + "\":" + SampleBody + "}";
            string s2       = SampleBody;
            string xmlbody  = JsonConvert.DeserializeXmlNode(SampleBody).OuterXml;
            string temppath = System.IO.Path.GetTempFileName();

            File.WriteAllText(temppath, xmlbody);
            XMLTemplateParser   XTp = new XMLTemplateParser();
            ApplicationAPIModel aam = XTp.ParseDocument(temppath).ElementAt(0);

            object[] BodyandModelParameters = JSONTemplateParser.GenerateBodyANdModelParameters(SampleBody);
            aAM.RequestBody     = aam.RequestBody;
            aAM.RequestBodyType = ApplicationAPIUtils.eRequestBodyType.FreeText;
            aam.ContentType     = ApplicationAPIUtils.eContentType.XML;
            return(aam.AppModelParameters);
        }