Ejemplo n.º 1
0
        public void SuccessPathWithSingleQuotes()
        {
            string json = "{\n" +
                          "  \"firstName\": \"John\",\n" +
                          "  \"lastName\" : \"doe\",\n" +
                          "  \"age\"      : 26,\n" +
                          "  \"address\"  : {\n" +
                          "    \"streetAddress\": \"naist street\",\n" +
                          "    \"city\"         : \"Nara\",\n" +
                          "    \"postalCode\"   : \"630-0192\"\n" +
                          "  },\n" +
                          "  \"phoneNumbers\": [\n" +
                          "    {\n" +
                          "      \"type\"  : \"iPhone\",\n" +
                          "      \"number\": \"0123-4567-8888\"\n" +
                          "    },\n" +
                          "    {\n" +
                          "      \"type\"  : \"home\",\n" +
                          "      \"number\": \"0123-4567-8910\"\n" +
                          "    }\n" +
                          "  ]\n" +
                          "}";

            var rule   = JObject.Parse(json);
            var path   = "\"$.phoneNumbers[?(@.type=='iPhone')].type\"";
            var actual = JsonComparer.PathEqual(path, rule);

            Assert.True(actual);
        }
Ejemplo n.º 2
0
        public void SuccessPathExistsJsonComparison()
        {
            var rule   = JObject.Parse("{'x': {'a': 'c'}, 'xy': {'a': 'd', 'b': {'a': 'b'}}}");
            var path   = "\"$..x\"";
            var actual = JsonComparer.PathEqual(path, rule);

            Assert.True(actual);
        }
Ejemplo n.º 3
0
        public void FailurePathDoesNotExistJsonComparison()
        {
            var rule   = JObject.Parse("{'x': {'a': 'c'}, 'xy': {'a': 'd', 'b': {'a': 'b'}}}");
            var path   = "\"$..y\"";
            var actual = JsonComparer.PathEqual(path, rule);

            Assert.False(actual);
        }
Ejemplo n.º 4
0
        public void FailurePathExistsButIsNotInDoubleQuotesJsonComparison()
        {
            var rule   = JObject.Parse("{'x': {'a': 'c'}, 'xy': {'a': 'd', 'b': {'a': 'b'}}}");
            var path   = "$..x";
            var actual = JsonComparer.PathEqual(path, rule);

            Assert.False(actual);
        }
Ejemplo n.º 5
0
        private bool ExecuteComparer(Assert assert)
        {
            switch (assert.Rule)
            {
            case ComparerType.REGEX:
                return(RegexComparer.Compare(assert.Actual, assert.Expect));

            case ComparerType.TEXTCONTAINS:
                return(TextComparer.Contains(assert.Actual, assert.Expect));

            case ComparerType.TEXTSTARTSWITH:
                return(TextComparer.StartsWith(assert.Actual, assert.Expect));

            case ComparerType.TEXTENDSWITH:
                return(TextComparer.EndsWith(assert.Actual, assert.Expect));

            case ComparerType.TEXTEQUALS:
                return(TextComparer.Equals(assert.Actual, assert.Expect));

            case ComparerType.ACCEPTALL:
                return(true);

            case ComparerType.JSONCONTAINS:
                return(JsonComparer.DeepContains(assert.Expect, assert.Actual));

            case ComparerType.JSONEQUALITY:
                return(JsonComparer.DeepEqual(assert.Expect, assert.Actual));

            case ComparerType.JSONSCHEMA:
                return(JsonComparer.MatchesSchema(assert.Actual, assert.Expect));

            case ComparerType.JSONPATH:
                return(JsonComparer.PathEqual(assert.Expect, assert.Actual));

            default:
                return(false);
            }
        }