Ejemplo n.º 1
0
        static public FilterGroup New(Type type, string referencePropertyName, string referenceType, Guid referencedEntityID, string propertyName, object propertyValue)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            FilterGroup group = DataAccess.Data.CreateFilterGroup();

            PropertyFilter propertyFilter = DataAccess.Data.CreatePropertyFilter();

            propertyFilter.AddType(type);
            propertyFilter.PropertyName  = propertyName;
            propertyFilter.PropertyValue = propertyValue;

            group.Add(propertyFilter);

            ReferenceFilter referenceFilter = DataAccess.Data.CreateReferenceFilter();

            referenceFilter.AddType(type);
            referenceFilter.ReferencedEntityID = referencedEntityID;
            referenceFilter.PropertyName       = referencePropertyName;
            referenceFilter.ReferenceType      = EntityState.GetType(referenceType);

            group.Add(referenceFilter);

            return(group);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the provided filter values to the filter group.
        /// </summary>
        /// <param name="filterValues"></param>
        public FilterGroup(Type type, IDictionary<string, object> filterValues)
        {
            Operator = FilterGroupOperator.And;

            foreach (string key in filterValues.Keys)
            {
                PropertyFilter filter = new PropertyFilter(type, key, filterValues[key]);
                if (filter != null)
                    Add(filter);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the provided filter values to the filter group.
        /// </summary>
        /// <param name="filterValues"></param>
        public FilterGroup(Type type, IDictionary <string, object> filterValues)
        {
            Operator = FilterGroupOperator.And;

            foreach (string key in filterValues.Keys)
            {
                PropertyFilter filter = new PropertyFilter(type, key, filterValues[key]);
                if (filter != null)
                {
                    Add(filter);
                }
            }
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
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");
        }