public void complexParseHeader()
 {
     pr = Parser.parseHeader("Simple $unknown_var$ string. It costs $x$\\$ and $ is money.", custom_variables);
     Assert.IsFalse(pr.isSuccess());
     Assert.AreEqual(pr.getResult(), "Simple $unknown_var$ string. It costs 42$ and $ is money.");
     Assert.AreEqual(pr.getErrors().Count, 2); // one error for unknown variable and the other for unescaped dollar char at the end missing it's pair
 }
        public void IpGreaterThanFloat()
        {
            ParserResult pr = parser.parseResponse("{ a : \"#real#ip_gt#5##\", b: \"#real#ip_gt#0##\"  }", "{ b: 1.0 }", null, true);

            Assert.IsNotNull(pr);
            Assert.IsTrue(pr.isSuccess());
        }
 public void deserializeArrayInArray()
 {
     // TEMPLATE:
     //{
     //    "infos": [
     //        [
     //            {
     //                "title": "title 1",
     //                "desciption": "description 1"
     //            },
     //            {
     //                "title": "title 2",
     //                "description": "description 2"
     //            },
     //            {
     //                "title": "title 3",
     //                "description": "description 3"
     //            }
     //        ]
     //    ]
     //}
     //
     pr = parser.generateRequest("{ \"infos\": [ [ { \"title\": \"title 1\", \"desciption\": \"description 1\" }, { \"title\": \"title 2\", \"description\": \"description 2\" }, { \"title\": \"title 3\", \"description\": \"description 3\" } ] ] }", null);
     Assert.IsTrue(pr.isSuccess());
 }
 public void deserializeObjectsInArray()
 {
     // TEMPLATE:
     //{
     //    "menu": {
     //        "id": "file",
     //        "value": "File",
     //        "popup": {
     //            "int": 230,
     //            "double": 309.302,
     //            "null": null,
     //            "menuitem": [
     //                {
     //                    "value": "New",
     //                    "onclick": "CreateNewDoc()"
     //                },
     //                {
     //                    "value": "Open",
     //                    "onclick": "OpenDoc()"
     //                },
     //                {
     //                    "value": "Close",
     //                    "onclick": "CloseDoc()"
     //                }
     //            ]
     //        }
     //    }
     //}
     //
     pr = parser.generateRequest("{ \"menu\" : { \"id\": \"file\", \"value\": \"File\", \"popup\": { \"int\": 230, \"double\": 309.302, \"null\": null, \"menuitem\": [ { \"value\": \"New\", \"onclick\": \"CreateNewDoc()\" }, { \"value\": \"Open\", \"onclick\": \"OpenDoc()\" }, { \"value\": \"Close\", \"onclick\": \"CloseDoc()\" } ] } } }", null);
     Assert.IsTrue(pr.isSuccess());
 }
        public void OperationWithoutType()
        {
            String       template = "{\"foo\": [\"##gt#10##\"}";
            ParserResult pr       = parser.validateResponse(template, null);

            Assert.IsNotNull(pr);
            Assert.IsFalse(pr.isSuccess());
        }
        public void MissingVariable()
        {
            Dictionary <string, string> customVar = new Dictionary <string, string>
            {
                { "a", "10" }
            };
            String       template = "{\"foo\": [\"#integer#ne#b##\"}";
            ParserResult pr       = parser.validateResponse(template, customVar);

            Assert.IsNotNull(pr);
            Assert.IsFalse(pr.isSuccess());
        }
        public void ArrayString()
        {
            Dictionary <string, string> customVar = new Dictionary <string, string>
            {
                { "a", "abc" }
            };
            String       template = "{\"foo\": [\"#string#uv_ne#a##\"] }";
            String       response = "{\"foo\": [\"ab\", \"abcd\"] } ";
            ParserResult pr       = parser.parseResponse(template, response, customVar, true);

            Assert.IsNotNull(pr);
            Assert.IsTrue(pr.isSuccess());
        }
        public void simpleParseHeader()
        {
            pr = Parser.parseHeader("", null);
            Assert.IsTrue(pr.isSuccess());
            Assert.AreEqual(pr.getResult(), "");

            pr = Parser.parseHeader("simple $first$ string", custom_variables);
            Assert.IsTrue(pr.isSuccess());
            Assert.AreEqual(pr.getResult(), "simple second string");

            pr = Parser.parseHeader("\\\\$", custom_variables);
            Assert.IsTrue(pr.isSuccess());
            Assert.AreEqual(pr.getResult(), "\\$");
        }
 public void deserializeJSONWithMissingComma()
 {
     // TEMPLATE:
     //{
     //    "devise": {
     //        "appVersionId": 51,
     //        "locale": "en",
     //        "countryCode": "CZ"
     //        "platform": 1,
     //        "platformVersion": 7000005
     //    }
     //}
     //
     pr = parser.generateRequest("{ \"devise\": { \"appVersionId\": 51, \"locale\": \"en\", \"countryCode\": \"CZ\" \"platform\": 1, \"platformVersion\": 7000005 } }", null);
     Assert.IsFalse(pr.isSuccess());
     Assert.AreEqual(pr.getErrors().Count, 1);
 }
        public void ArrayInteger()
        {
            String result;
            Dictionary <string, string> customVar = new Dictionary <string, string>
            {
                { "a", "3" },
                { "b", "10" }
            };
            String       template = "{\"foo\": [\"#array#uv_ge#a#res#\", \"#integer#uv_ge#b##\"] }";
            String       response = "{\"foo\": [10,20,30] }";
            ParserResult pr       = parser.parseResponse(template, response, customVar, true);

            Assert.IsNotNull(pr);
            Assert.IsTrue(pr.isSuccess());

            Assert.IsTrue(customVar.TryGetValue("res", out result));
            Assert.AreEqual(result, "3");
        }
 public void compareResponseWithExtraKey()
 {
     // TEMPLATE:
     //{
     //    "result": {
     //        "country": {
     //            "termOfUse: ": "http"
     //        }
     //    }
     //}
     //
     // RESPONSE:
     //{
     //    "result": {
     //        "country": {
     //            "termOfUse: ": "http",
     //            "preset": "+420"
     //        }
     //    }
     //}
     //
     pr = parser.parseResponse("{ \"result\" : { \"country\" : { \"termOfUse: \" : \"http\" } } }", "{ \"result\" : { \"country\" : { \"termOfUse: \" : \"http\", \"preset\" : \"+420\" } } }", null, true);
     Assert.IsTrue(pr.isSuccess());
 }