Filter() 공개 메소드

public Filter ( object item ) : bool
item object
리턴 bool
예제 #1
0
        public void Converts_Value_With_Culture()
        {
            // double with comma + culture
            var filter = new PropertyFilter <MyFilteredItem>("MyDouble", PredicateOperator.IsEqual, "10,5", CultureInfo.GetCultureInfo("fr"));

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyDouble = 20.9
            }));
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyDouble = 10.5
            }));
        }
예제 #2
0
        public void StartsWith_With_String()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyString", PredicateOperator.StartsWith, "item");

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyString = "Value A"
            }));
            // Assert.AreEqual(false, filter.Filter(new MyFilteredItem())); // passes null TODO: handle nulls
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyString = "Item B"
            }));
        }
예제 #3
0
        public void EndsWith_With_String_With_Case_Sensitive()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyString", PredicateOperator.EndsWith, "b", isCaseSensitive: true);

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyString = "Value A"
            }));
            // Assert.AreEqual(false, filter.Filter(new MyFilteredItem())); // passes null TODO: handle nulls
            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyString = "Item B"
            }));
        }
예제 #4
0
        public void IsEqual_With_String()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyString", PredicateOperator.IsEqual, "Value B");

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyString = "Value A"
            }));
            Assert.AreEqual(false, filter.Filter(new MyFilteredItem())); // passes null
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyString = "Value B"
            }));
        }
예제 #5
0
        public void Contains_Case_Sensitive_With_String()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyString", PredicateOperator.Contains, "b", isCaseSensitive: true);

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyString = "Value A"
            }));
            // Assert.AreEqual(false, filter.Filter(new MyFilteredItem())); // passes null
            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyString = "Value B"
            }));
        }
예제 #6
0
        public void IsGreaterOrEqual_With_Int()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyInt", PredicateOperator.IsGreaterThanOrEqualTo, 10);

            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyInt = 20
            }));
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyInt = 10
            }));
            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyInt = 5
            }));
        }
예제 #7
0
        public void IsEqual_With_Date_As_String_Culture()
        {
            var date         = new DateTime(2019, 07, 18);
            var dateAsString = date.ToString(CultureInfo.GetCultureInfo("fr")); // 18/07/2019 00:00:00

            var filter = new PropertyFilter <MyFilteredItem>("MyDate", PredicateOperator.IsEqual, dateAsString, CultureInfo.GetCultureInfo("fr"));

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyDate = DateTime.Now
            }));
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyDate = new DateTime(2019, 07, 18)
            }));
        }
예제 #8
0
        public void IsEqual_With_List()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyStrings.Count", PredicateOperator.IsEqual, 2);

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyStrings = new List <string> {
                    "A"
                }
            }));
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyStrings = new List <string> {
                    "A", "B"
                }
            }));
        }
예제 #9
0
        public void Converts_Inner_Object_Value()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyInner.MyInnerInt", PredicateOperator.IsEqual, "10");

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyInner = new SubFilteredItem {
                    MyInnerInt = 20
                }
            }));
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyInner = new SubFilteredItem {
                    MyInnerInt = 10
                }
            }));
        }
예제 #10
0
        public void IsEqual_With_Inner_Object()
        {
            var filter = new PropertyFilter <MyFilteredItem>("MyInner.MyInnerString", PredicateOperator.IsEqual, "B");

            Assert.AreEqual(false, filter.Filter(new MyFilteredItem {
                MyInner = new SubFilteredItem {
                    MyInnerString = "A"
                }
            }));
            Assert.AreEqual(true, filter.Filter(new MyFilteredItem {
                MyInner = new SubFilteredItem {
                    MyInnerString = "B"
                }
            }));
        }