예제 #1
0
        public void ShouldUpgradeOldMatchingRulesToNew()
        {
            var oldMatchingRules = new Dictionary <string, Matcher>()
            {
                { "$.body", new Matcher {
                      MatcherType = MatcherType.type
                  } },
                { "$.body.name", new Matcher {
                      MatcherType = MatcherType.regex, Regex = "\\w+"
                  } },
                { "$.headers.content-type", new Matcher {
                      MatcherType = MatcherType.type
                  } }
            };

            var newMatchingRules = new MatchingRuleCollection(oldMatchingRules);

            Assert.AreEqual(2, newMatchingRules.Body.Count);
            Assert.AreEqual(1, newMatchingRules.Body.First().Value.Matchers.Count);
            Assert.AreEqual(MatcherType.type, newMatchingRules.Body["$"].Matchers.First().MatcherType);
            Assert.AreEqual("\\w+", newMatchingRules.Body["$.name"].Matchers.First().Regex);
            Assert.AreEqual(MatcherType.regex, newMatchingRules.Body["$.name"].Matchers.First().MatcherType);

            Assert.AreEqual(1, newMatchingRules.Header.Count);
            Assert.AreEqual(MatcherType.type, newMatchingRules.Header["content-type"].Matchers.First().MatcherType);
        }
        public void ShouldNotFindForChildToken()
        {
            var token      = JToken.FromObject(new { name = "test" });
            var collection = new MatchingRuleCollection {
                Body = new Dictionary <string, MatcherList> {
                    { "$.name", _typeMatcherList }
                }
            };

            var isFound = collection.TryGetApplicableMatcherListForToken(token.Root, out var applicableMatcherList);

            Assert.IsFalse(isFound);
        }
        public void ShouldNotFindWhenEqualityMatcherListIsApplicable()
        {
            var token      = JToken.FromObject(new { name = "test" });
            var collection = new MatchingRuleCollection {
                Body = new Dictionary <string, MatcherList> {
                    { "$", _typeMatcherList }, { "$.name", _equalityMatcherList }
                }
            };

            var isFound = collection.TryGetApplicableMatcherListForToken(token.Children().First(), out var applicableMatcherList);

            Assert.IsFalse(isFound);
        }
        public void ShouldFindForParentToken()
        {
            var token      = JToken.FromObject(new { name = "test" });
            var collection = new MatchingRuleCollection {
                Body = new Dictionary <string, MatcherList> {
                    { "$", _typeMatcherList }
                }
            };

            var isFound = collection.TryGetApplicableMatcherListForToken(token.Children().First(), out var applicableMatcherList);

            Assert.IsTrue(isFound);
            Assert.AreEqual(_typeMatcherList, applicableMatcherList);
        }
        public void ShouldIgnoreStarWhenMoreSpecificOptionExists()
        {
            var token      = JToken.FromObject(new { name = "test" });
            var collection = new MatchingRuleCollection {
                Body = new Dictionary <string, MatcherList> {
                    { "$.*", _typeMatcherList }, { "$.name", _integerMatcherList }
                }
            };

            var isFound = collection.TryGetApplicableMatcherListForToken(token.Children().First(), out var applicableMatcherList);

            Assert.IsTrue(isFound);
            Assert.AreEqual(_integerMatcherList, applicableMatcherList);
        }
        public void ShouldFindWithStarAnywhereInPath()
        {
            var token      = JToken.FromObject(new { thing = new { name = "test" } });
            var collection = new MatchingRuleCollection {
                Body = new Dictionary <string, MatcherList> {
                    { "$.*.name", _typeMatcherList }
                }
            };

            var isFound = collection.TryGetApplicableMatcherListForToken(token.SelectToken("thing.name"), out var applicableMatcherList);

            Assert.IsTrue(isFound);
            Assert.AreEqual(_typeMatcherList, applicableMatcherList);
        }
예제 #7
0
        internal Response(V2.Response responseV2)
        {
            if (responseV2 == null)
            {
                throw new System.ArgumentNullException(nameof(responseV2));
            }

            Status  = responseV2.Status;
            Headers = responseV2.Headers;
            Body    = responseV2.Body;
            if (responseV2.MatchingRules != null)
            {
                MatchingRules = new MatchingRuleCollection(responseV2.MatchingRules);
            }
        }