public void Test_IsSatisfiedBy_Recursive() { var foo = new Foo() { Bar = new Bar() { Description = "xag" } }; var goo = new Foo() { Bar = new Bar() { Description = "yyy" } }; var hoo = new Foo() { Bar = new Bar() }; var ioo = new Foo(); var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"] = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"].SubCriteria["Description"] = new EqualitySearchCondition("xag"); Assert.IsTrue(sc.IsSatisfiedBy(foo)); Assert.IsFalse(sc.IsSatisfiedBy(goo)); Assert.IsFalse(sc.IsSatisfiedBy(hoo)); Assert.IsFalse(sc.IsSatisfiedBy(ioo)); Assert.IsFalse(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_MissingProperty() { var foo = new Foo(); var sc = new ConcreteSearchCriteria(); // sc is not satisfied because Foo does not contain a property called Moo, // even though the Moo condition is always true // (this is the current behaviour... should it throw an exception instead?) sc.SubCriteria["Moo"] = new ConstantSearchCondition(true); Assert.IsFalse(sc.IsSatisfiedBy(foo)); // sc is not satisfied because Foo does not contain a property called Moo, // even though the Moo condition is equality with null // (this is the current behaviour... should it throw an exception instead?) sc.SubCriteria["Moo"] = new EqualitySearchCondition(null); Assert.IsFalse(sc.IsSatisfiedBy(foo)); // all properties are "missing" from null, by definition // but in this case, sc is satisfied by null, due to null propagation // (because the Moo condition is equality with null) Assert.IsTrue(sc.IsSatisfiedBy(null)); // all properties are "missing" from null, by definition // in this case, sc is not satisfied by null, due to null propagation // (because the Moo condition is equality with "Bob") sc.SubCriteria["Moo"] = new EqualitySearchCondition("Bob"); Assert.IsFalse(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_Empty() { var sc = new ConcreteSearchCriteria(); Assert.IsTrue(sc.IsEmpty); // an empty criteria can be satisfied by any object, or null Assert.IsTrue(sc.IsSatisfiedBy(new object())); Assert.IsTrue(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_SingleCondition_Null() { var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); Assert.IsFalse(sc.IsSatisfiedBy(null)); // due to null propagation, sc is satisfied // (because null is propagated to Name sub-criteria) sc.SubCriteria["Name"] = new EqualitySearchCondition(null); Assert.IsTrue(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_NullPropagation() { var ioo = new Foo(); var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"] = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"].SubCriteria["Description"] = new EqualitySearchCondition(null); // null-valued Bar is propagated through the Description condition Assert.IsTrue(sc.IsSatisfiedBy(ioo)); Assert.IsTrue(sc.IsSatisfiedBy(null)); sc.SubCriteria["Bar"].SubCriteria["Description"] = new EqualitySearchCondition("Bob"); // null-valued Bar is propagated through the Description condition Assert.IsFalse(sc.IsSatisfiedBy(ioo)); Assert.IsFalse(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_SingleCondition() { var sc = new ConcreteSearchCriteria(); var foo = new Foo() { Name = "Bob" }; var goo = new Foo() { Name = "Lena" }; sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); Assert.IsTrue(sc.IsSatisfiedBy(foo)); Assert.IsFalse(sc.IsSatisfiedBy(goo)); sc.SubCriteria["Name"] = new EqualitySearchCondition("Lena"); Assert.IsFalse(sc.IsSatisfiedBy(foo)); Assert.IsTrue(sc.IsSatisfiedBy(goo)); }
public void Test_IsSatisfiedBy_MultiCondition() { var foo = new Foo() { Name = "Bob", Age = 10 }; var hoo = new Foo() { Name = "Bob", Age = 12 }; var goo = new Foo() { Name = "Lena", Age = 10 }; var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); sc.SubCriteria["Age"] = new EqualitySearchCondition(10); Assert.IsFalse(sc.IsSatisfiedBy(hoo)); Assert.IsFalse(sc.IsSatisfiedBy(goo)); Assert.IsTrue(sc.IsSatisfiedBy(foo)); sc.SubCriteria["Name"] = new EqualitySearchCondition("Lena"); Assert.IsFalse(sc.IsSatisfiedBy(hoo)); Assert.IsTrue(sc.IsSatisfiedBy(goo)); Assert.IsFalse(sc.IsSatisfiedBy(foo)); }
public void Test_IsSatisfiedBy_NullPropagation() { var ioo = new Foo(); var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"] = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"].SubCriteria["Description"] = new EqualitySearchCondition(null); // null-valued Bar is propagated through the Description condition Assert.IsTrue(sc.IsSatisfiedBy(ioo)); Assert.IsTrue(sc.IsSatisfiedBy(null)); sc.SubCriteria["Bar"].SubCriteria["Description"] = new EqualitySearchCondition("Bob"); // null-valued Bar is propagated through the Description condition Assert.IsFalse(sc.IsSatisfiedBy(ioo)); Assert.IsFalse(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_Recursive() { var foo = new Foo() {Bar = new Bar() {Description = "xag"} }; var goo = new Foo() { Bar = new Bar() { Description = "yyy" } }; var hoo = new Foo() { Bar = new Bar() }; var ioo = new Foo(); var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"] = new ConcreteSearchCriteria(); sc.SubCriteria["Bar"].SubCriteria["Description"] = new EqualitySearchCondition("xag"); Assert.IsTrue(sc.IsSatisfiedBy(foo)); Assert.IsFalse(sc.IsSatisfiedBy(goo)); Assert.IsFalse(sc.IsSatisfiedBy(hoo)); Assert.IsFalse(sc.IsSatisfiedBy(ioo)); Assert.IsFalse(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_MissingProperty() { var foo = new Foo(); var sc = new ConcreteSearchCriteria(); // sc is not satisfied because Foo does not contain a property called Moo, // even though the Moo condition is always true // (this is the current behaviour... should it throw an exception instead?) sc.SubCriteria["Moo"] = new ConstantSearchCondition(true); Assert.IsFalse(sc.IsSatisfiedBy(foo)); // sc is not satisfied because Foo does not contain a property called Moo, // even though the Moo condition is equality with null // (this is the current behaviour... should it throw an exception instead?) sc.SubCriteria["Moo"] = new EqualitySearchCondition(null); Assert.IsFalse(sc.IsSatisfiedBy(foo)); // all properties are "missing" from null, by definition // but in this case, sc is satisfied by null, due to null propagation // (because the Moo condition is equality with null) Assert.IsTrue(sc.IsSatisfiedBy(null)); // all properties are "missing" from null, by definition // in this case, sc is not satisfied by null, due to null propagation // (because the Moo condition is equality with "Bob") sc.SubCriteria["Moo"] = new EqualitySearchCondition("Bob"); Assert.IsFalse(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_MultiCondition() { var foo = new Foo() { Name = "Bob", Age = 10}; var hoo = new Foo() { Name = "Bob", Age = 12 }; var goo = new Foo() { Name = "Lena", Age = 10 }; var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); sc.SubCriteria["Age"] = new EqualitySearchCondition(10); Assert.IsFalse(sc.IsSatisfiedBy(hoo)); Assert.IsFalse(sc.IsSatisfiedBy(goo)); Assert.IsTrue(sc.IsSatisfiedBy(foo)); sc.SubCriteria["Name"] = new EqualitySearchCondition("Lena"); Assert.IsFalse(sc.IsSatisfiedBy(hoo)); Assert.IsTrue(sc.IsSatisfiedBy(goo)); Assert.IsFalse(sc.IsSatisfiedBy(foo)); }
public void Test_IsSatisfiedBy_SingleCondition_Null() { var sc = new ConcreteSearchCriteria(); sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); Assert.IsFalse(sc.IsSatisfiedBy(null)); // due to null propagation, sc is satisfied // (because null is propagated to Name sub-criteria) sc.SubCriteria["Name"] = new EqualitySearchCondition(null); Assert.IsTrue(sc.IsSatisfiedBy(null)); }
public void Test_IsSatisfiedBy_SingleCondition() { var sc = new ConcreteSearchCriteria(); var foo = new Foo() {Name = "Bob"}; var goo = new Foo() {Name = "Lena"}; sc.SubCriteria["Name"] = new EqualitySearchCondition("Bob"); Assert.IsTrue(sc.IsSatisfiedBy(foo)); Assert.IsFalse(sc.IsSatisfiedBy(goo)); sc.SubCriteria["Name"] = new EqualitySearchCondition("Lena"); Assert.IsFalse(sc.IsSatisfiedBy(foo)); Assert.IsTrue(sc.IsSatisfiedBy(goo)); }
public void Test_IsSatisfiedBy_Empty() { var sc = new ConcreteSearchCriteria(); Assert.IsTrue(sc.IsEmpty); // an empty criteria can be satisfied by any object, or null Assert.IsTrue(sc.IsSatisfiedBy(new object())); Assert.IsTrue(sc.IsSatisfiedBy(null)); }