示例#1
0
        private static void HandleFilter()
        {
            List <DesignPattern.Filter.Person> list_person = new List <DesignPattern.Filter.Person>()
            {
                new DesignPattern.Filter.Person()
                {
                    age  = 19,
                    name = "cheng",
                    sex  = 0,
                },
                new DesignPattern.Filter.Person()
                {
                    age  = 18,
                    name = "xheng",
                    sex  = 0,
                },
                new DesignPattern.Filter.Person()
                {
                    age  = 19,
                    name = "xie",
                    sex  = 0,
                },
                new DesignPattern.Filter.Person()
                {
                    age  = 19,
                    name = "cheng",
                    sex  = 1,
                },
            };

            //NameFilter namefilter = new NameFilter();
            //list_person = namefilter.Filter(list_person);
            //AndFilter andfilter = new AndFilter(new List<IFilter>()
            //{
            //     new NameFilter(),
            //     new AgeFilter()
            //});
            //list_person = andfilter.Filter(list_person);
            OrFilter orfilter = new OrFilter(new List <IFilter>()
            {
                new NameFilter(),
                new AgeFilter()
            });

            list_person = orfilter.Filter(list_person);
        }
示例#2
0
        public void Should_or_multiple_tags()
        {
            var eventsInQueue = new Queue <GherkinEvent>();

            eventsInQueue.Enqueue(new FeatureEvent(new Feature("title"), e => { }));
            eventsInQueue.Enqueue(new TagEvent("@tag1", e => { }));
            eventsInQueue.Enqueue(new ScenarioEvent(new Scenario("title", ""), e => { }));
            eventsInQueue.Enqueue(new StepEvent("step", e => { }));
            eventsInQueue.Enqueue(new TagEvent("@tag2", e => { }));
            eventsInQueue.Enqueue(new ScenarioEvent(new Scenario("title", ""), e => { }));
            eventsInQueue.Enqueue(new StepEvent("step", e => { }));
            eventsInQueue.Enqueue(new EofEvent(e => { }));
            var events         = GroupEventsByTag.GroupByTag(eventsInQueue);
            var filter         = new OrFilter(new[] { "@tag1", "@tag2" });
            var filteredEvents = filter.Filter(events).ToList();

            CollectionAssert.AreEqual(events, filteredEvents);
        }
示例#3
0
        public void Should_filter_events_by_exclude_tag_with_or()
        {
            var eventsInQueue = new Queue <GherkinEvent>();

            eventsInQueue.Enqueue(new FeatureEvent(new Feature("title"), e => { }));
            eventsInQueue.Enqueue(new TagEvent("@tag1", e => { }));
            eventsInQueue.Enqueue(new ScenarioEvent(new Scenario("title", ""), e => { }));
            eventsInQueue.Enqueue(new StepEvent("step", e => { }));
            eventsInQueue.Enqueue(new TagEvent("@tag2", e => { }));
            eventsInQueue.Enqueue(new ScenarioEvent(new Scenario("title", ""), e => { }));
            eventsInQueue.Enqueue(new StepEvent("step", e => { }));
            eventsInQueue.Enqueue(new EofEvent(e => { }));
            var events         = GroupEventsByTag.GroupByTag(eventsInQueue);
            var filter         = new OrFilter(new[] { "~@tag1" });
            var filteredEvents = filter.Filter(events).ToList();

            Assert.AreEqual(4, filteredEvents.Count);
            Assert.IsFalse(filteredEvents.Any(_ => _.Tags.Any(t => t == "@tag1")));
        }