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 })); }
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" })); }
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" })); }
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" })); }
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" })); }
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 })); }
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) })); }
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" } })); }
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 } })); }
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" } })); }