Exemplo n.º 1
0
        private static IMatcher BuildMatcher(Action <IKeyMatchBuilder> builder)
        {
            var keyMatchBuilder = new KeyMatchBuilder();

            builder(keyMatchBuilder);
            return(keyMatchBuilder.Build());
        }
        public void EmptyBuilderBuildsNullMatcher()
        {
            var matcher = new KeyMatchBuilder()
                          .Build();

            matcher.ShouldNotBeNull();
            matcher.ShouldBeOfType <NullMatcher>();
        }
        public void BuilderWithSingleMatcherShouldReturnUnderlyingMatcher()
        {
            var singleMatcher = new ContainsMatcher("abc");
            var matcher       = new KeyMatchBuilder()
                                .Add(singleMatcher)
                                .Build();

            matcher.ShouldNotBeNull();
            matcher.ShouldBeOfType <ContainsMatcher>();
            matcher.ShouldBe(singleMatcher);
        }
        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));
        }