Exemplo n.º 1
0
        public void Test_FilterGroup_Or()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing a filter group query with the OR operator.", NLog.LogLevel.Debug))
            {
                TestEntity e1 = new TestEntity();
                e1.Name = "Test E1";

                FilterGroup filterGroup = new FilterGroup();
                filterGroup.Operator = FilterGroupOperator.Or;

                PropertyFilter filter1 = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter1.PropertyName = "Name";
                filter1.PropertyValue = e1.Name;
                filter1.AddType(typeof(TestEntity));

                PropertyFilter filter2 = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter2.PropertyName = "Name";
                filter2.PropertyValue = "Another value";
                filter2.AddType(typeof(TestEntity));

                filterGroup.Filters = new BaseFilter[] {filter1, filter2};

                DataAccess.Data.Stores[typeof(TestEntity)].Saver.Save(e1);

                IEntity[] found = (IEntity[])DataAccess.Data.Indexer.GetEntities(filterGroup);

                Assert.IsNotNull(found, "Null value returned.");

                if (found != null)
                    Assert.IsTrue(found.Length > 0, "No results found.");

                DataAccess.Data.Deleter.Delete(e1);
            }
        }
Exemplo n.º 2
0
        public void Test_IsMatch_2SubGroups_True()
        {
            TestArticle article = new TestArticle();
            article.ID = Guid.NewGuid();
            article.Title = "Article1";

            // Outer group
            FilterGroup group = new FilterGroup();
            group.Operator = FilterGroupOperator.And; // BOTH child groups MUST match

            FilterGroup subGroup1 = new MockMatchingFilterGroup();
            FilterGroup subGroup2 = new MockMatchingFilterGroup();

            group.Add(subGroup1);
            group.Add(subGroup2);

            Assert.IsTrue(subGroup1.IsMatch(article), "First sub group doesn't match when it should.");
            Assert.IsTrue(subGroup2.IsMatch(article), "Second sub group doesn't match when it should.");

            Assert.IsTrue(group.IsMatch(article), "Entire group failed to match.");
        }
Exemplo n.º 3
0
        public void Test_FilterGroup_And_Exclusion()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing a filter group query with the AND operator.", NLog.LogLevel.Debug))
            {
                TestEntity e1 = new TestEntity();
                e1.Name = "Test E1";

                FilterGroup filterGroup = new FilterGroup();
                filterGroup.Operator = FilterGroupOperator.And;

                PropertyFilter filter1 = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter1.PropertyName = "Name";
                filter1.PropertyValue = e1.Name;
                filter1.AddType(typeof(TestEntity));

                PropertyFilter filter2 = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter2.PropertyName = "Name";
                filter2.PropertyValue = "Another value";
                filter2.AddType(typeof(TestEntity));

                filterGroup.Filters = new BaseFilter[] {filter1, filter2};

                DataAccess.Data.Saver.Save(e1);

                IEntity[] found = (IEntity[])DataAccess.Data.Indexer.GetEntities(filterGroup);

                Assert.IsNotNull(found, "Null array returned.");

                Collection<TestEntity> foundList = new Collection<TestEntity>(found);

                if (found != null)
                    Assert.AreEqual(0, foundList.Count, "Entity retrieved when it shouldn't have matched.");

                DataAccess.Data.Deleter.Delete(e1);
            }
        }
Exemplo n.º 4
0
        public void Add(FilterGroup group)
        {
            if (group == null)
                throw new ArgumentNullException("group");

            List<FilterGroup> list = (childGroups == null ? new List<FilterGroup>() : new List<FilterGroup>(childGroups));

            list.Add(group);
            childGroups = (FilterGroup[])list.ToArray();
        }
Exemplo n.º 5
0
        public void Test_IsMatch_And_False()
        {
            TestArticle article = new TestArticle();
            article.ID = Guid.NewGuid();
            article.Title = "Article1";

            FilterGroup group = new FilterGroup();

            PropertyFilter filter1 = new PropertyFilter();
            filter1.AddType(typeof(TestArticle));
            filter1.PropertyName = "Title";
            filter1.PropertyValue = article.Title;

            Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should.");

            PropertyFilter filter2 = new PropertyFilter();
            filter2.AddType(typeof(TestArticle));
            filter2.PropertyName = "Title";
            filter2.PropertyValue = "MISMATCH"; // This one should fail

            Assert.IsFalse(filter2.IsMatch(article), "filter2 matched when it should fail.");

            group.Add(filter1);
            group.Add(filter2);

            Assert.IsFalse(group.IsMatch(article), "group matched when it should fail");
        }
Exemplo n.º 6
0
        public void Test_IsMatch_Or_True_BothMatch()
        {
            TestArticle article = new TestArticle();
            article.ID = Guid.NewGuid();
            article.Title = "Article1";

            FilterGroup group = new FilterGroup();
            group.Operator = FilterGroupOperator.Or;

            PropertyFilter filter1 = new PropertyFilter();
            filter1.AddType(typeof(TestArticle));
            filter1.PropertyName = "Title";
            filter1.PropertyValue = article.Title;

            Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should.");

            PropertyFilter filter2 = new PropertyFilter();
            filter2.AddType(typeof(TestArticle));
            filter2.PropertyName = "ID";
            filter2.PropertyValue = article.ID;

            Assert.IsTrue(filter2.IsMatch(article), "filter2 failed to match article when it should.");

            group.Add(filter1);
            group.Add(filter2);

            Assert.IsTrue(group.IsMatch(article), "group failed to match when it should");
        }
Exemplo n.º 7
0
        public void Test_IsMatch_EmptyGroup()
        {
            TestArticle article = new TestArticle();
            article.ID = Guid.NewGuid();
            article.Title = "Article1";

            FilterGroup group = new FilterGroup();

            Assert.IsTrue(group.IsMatch(article), "group failed to match when it should match");
        }