Esempio n. 1
0
        public static bool CanAccepted <T>(T value, T[] acceptedArray, T[] rejectedArray)
        {
            var matcher = new ContainsMatcher <T>();

            if (rejectedArray != null && rejectedArray.Contains(value, matcher))
            {
                return(false);
            }
            if (acceptedArray != null && acceptedArray.Contains(value, matcher))
            {
                return(true);
            }

            if (acceptedArray == null && rejectedArray != null)
            {
                return(true);
            }
            if (acceptedArray != null && rejectedArray == null)
            {
                return(false);
            }

            if (acceptedArray == null && rejectedArray == null)
            {
                return(true);
            }
            if (acceptedArray != null && rejectedArray != null)
            {
                return(false);
            }
            return(false);
        }
Esempio n. 2
0
        public void Matches_should_detect_item_via_collection_Contains_unless_a_comparer_is_specified()
        {
            var subj       = new ContainsMatcher <string>("c", StringComparer.OrdinalIgnoreCase);
            var collection = new PCollectionWithContains();

            Assert.True(subj.Matches(collection), "should ignore case");
            Assert.Equal(0, collection.ContainsCallCount, "should not be invoked");
        }
Esempio n. 3
0
        public void Matches_should_detect_item_via_collection_Contains()
        {
            var subj       = new ContainsMatcher <string>("C");
            var collection = new PCollectionWithContains();

            Assert.True(subj.Matches(collection));
            Assert.Equal(1, collection.ContainsCallCount);
        }
        public void BuilderWithSingleMatcherShouldReturnUnderlyingMatcher()
        {
            var singleMatcher = new ContainsMatcher("abc");
            var matcher       = new KeyMatchBuilder()
                                .Add(singleMatcher)
                                .Build();

            matcher.ShouldNotBeNull();
            matcher.ShouldBeOfType <ContainsMatcher>();
            matcher.ShouldBe(singleMatcher);
        }
Esempio n. 5
0
        public void ContainsMatcher_StringConstructor_SetsPattern()
        {
            //arrange
            string   regex           = "abc";
            IMatcher containsMatcher = new ContainsMatcher(regex);

            //act
            var pattern = containsMatcher.Pattern;

            //assert
            Assert.NotNull(containsMatcher);
            Assert.NotNull(pattern);
            Assert.Equal(regex, pattern);
        }
Esempio n. 6
0
        public void IsMatch_NonMatchingCondition_ReturnsFalse()
        {
            //arrange
            string   regex           = "abc";
            IMatcher containsMatcher = new ContainsMatcher(regex);

            //act
            MatchResult matchResult = containsMatcher.IsMatch("next time won't you sing with me");
            bool        isMatch     = matchResult.IsMatch;

            //assert
            Assert.NotNull(containsMatcher);
            Assert.NotNull(matchResult);
            Assert.False(isMatch);
        }
Esempio n. 7
0
        public void IsMatch_MatchingCondition_ReturnsTrue()
        {
            //arrange
            string   regex           = "abc";
            IMatcher containsMatcher = new ContainsMatcher(regex);

            //act
            MatchResult matchResult = containsMatcher.IsMatch("now I know my abcs");
            bool        isMatch     = matchResult.IsMatch;

            //assert
            Assert.NotNull(containsMatcher);
            Assert.NotNull(matchResult);
            Assert.True(isMatch);
        }
Esempio n. 8
0
        private static List <MatchResult> Score(string title, string filterText)
        {
            var startsWithMatcher            = new StartsWithMatcher();
            var containsMatcher              = new ContainsMatcher();
            var significantCharactersMatcher = new SignificantCharactersMatcher();
            var individualCharactersMatcher  = new IndividualCharactersMatcher();

            var results = new List <MatchResult>
            {
                startsWithMatcher.Evaluate(title, filterText),
                significantCharactersMatcher.Evaluate(title, filterText),
                containsMatcher.Evaluate(title, filterText),
                individualCharactersMatcher.Evaluate(title, filterText)
            };

            return(results);
        }
        public void BuilderWithMultipleMatchersShouldReturnAggregateMatcher()
        {
            var matcherOne = new ContainsMatcher("abc");
            var matcherTwo = new RegexMatcher("def");
            var matcher    = new KeyMatchBuilder()
                             .Add(new IMatcher[]
            {
                matcherOne,
                matcherTwo,
            })
                             .Build();

            matcher.ShouldNotBeNull();
            matcher.ShouldBeOfType <AggregateMatcher>();

            dynamic         aggregateMatcher = new Jailbreak <AggregateMatcher>((AggregateMatcher)matcher);
            List <IMatcher> matchers         = aggregateMatcher._matchers;

            matchers.Count.ShouldBe(2);
            matchers.ShouldContain(m => m.GetType() == typeof(ContainsMatcher));
            matchers.ShouldContain(m => m.GetType() == typeof(RegexMatcher));
        }
        private static MatchResult Evaluate(string input, string pattern)
        {
            var containsMatcher = new ContainsMatcher();

            return(containsMatcher.Evaluate(input, pattern));
        }
Esempio n. 11
0
        public void Matches_should_detect_item_failure()
        {
            var subj = new ContainsMatcher <string>("z");

            Assert.False(subj.Matches(new [] { "a", "b", "c" }));
        }
Esempio n. 12
0
        public void Matches_should_detect_item_nominal()
        {
            var subj = new ContainsMatcher <string>("C", StringComparer.OrdinalIgnoreCase);

            Assert.True(subj.Matches(new [] { "a", "b", "c" }));
        }