public void Test_Constructor_Key()
        {
            var sc = new ConcreteSearchCriteria("foo");

            Assert.IsTrue(sc.IsEmpty);
            Assert.AreEqual("foo", sc.GetKey());
        }
        public void Test_Constructor_Default()
        {
            var sc = new ConcreteSearchCriteria();

            Assert.IsTrue(sc.IsEmpty);
            Assert.AreEqual(null, sc.GetKey());
        }
        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_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_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_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));
        }
 /// <summary>
 /// Creates an initialised instance of the 
 /// <see cref="Core.Model.SearchCriteria"/> class.
 /// </summary>
 /// <returns>Initialised SearchCriteria class.</returns>
 /// <remarks>
 /// Derives from the <see cref="Core.Factories.SearchCriteriaFactory"/> abstract class.
 /// </remarks>
 public override SearchCriteria Create()
 {
     //  Set defaults
     //      Type: Author
     //      Date: Now
     var search = new ConcreteSearchCriteria()
     {
         Title = "",
         //  TODO:   Change default to SearchTypeEnum.SearchString.
         Type = SearchTypeEnum.Author,
         SearchString = "",
         SearchDate = DateTime.Now
     };
     return search;
 }
        /// <summary>
        /// Creates an initialised instance of the
        /// <see cref="Core.Model.SearchCriteria"/> class.
        /// </summary>
        /// <returns>Initialised SearchCriteria class.</returns>
        /// <remarks>
        /// Derives from the <see cref="Core.Factories.SearchCriteriaFactory"/> abstract class.
        /// </remarks>
        public override SearchCriteria Create()
        {
            //  Set defaults
            //      Type: Author
            //      Date: Now
            var search = new ConcreteSearchCriteria()
            {
                Title = "",
                //  TODO:   Change default to SearchTypeEnum.SearchString.
                Type         = SearchTypeEnum.Author,
                SearchString = "",
                SearchDate   = DateTime.Now
            };

            return(search);
        }
        public void Test_IsEmpty()
        {
            var sc = new ConcreteSearchCriteria();

            Assert.IsTrue(sc.IsEmpty);

            var baz = new ConcreteSearchCriteria("baz");

            sc.SubCriteria.Add("baz", baz);

            // should still be empty, because baz is empty
            Assert.IsTrue(sc.IsEmpty);

            baz.SubCriteria.Add("moo", new ConstantSearchCondition(true));

            // now it should be false, because baz has a non-empty sub condition
            Assert.IsFalse(sc.IsEmpty);
        }
        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_Constructor_Copy()
        {
            var sc = new ConcreteSearchCriteria("foo");

            Assert.IsTrue(sc.IsEmpty);
            Assert.AreEqual("foo", sc.GetKey());

            var sub = new ConcreteSearchCriteria("baz");

            sc.SubCriteria.Add("baz", sub);

            var copy = new ConcreteSearchCriteria(sc);

            Assert.AreEqual("foo", copy.GetKey());
            Assert.AreEqual(1, copy.SubCriteria.Count);
            Assert.IsTrue(copy.SubCriteria.ContainsKey("baz"));

            // check that the sub-criteria was actually cloned, not just copied
            Assert.IsFalse(ReferenceEquals(sc.SubCriteria["baz"], copy.SubCriteria["baz"]));
        }
Esempio n. 14
0
		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));

		}
Esempio n. 15
0
		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));
		}
Esempio n. 16
0
		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));
		}
Esempio n. 17
0
		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));
		}
Esempio n. 18
0
		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));
		}
Esempio n. 19
0
		public void Test_IsEmpty()
		{
			var sc = new ConcreteSearchCriteria();
			Assert.IsTrue(sc.IsEmpty);

			var baz = new ConcreteSearchCriteria("baz");
			sc.SubCriteria.Add("baz", baz);

			// should still be empty, because baz is empty
			Assert.IsTrue(sc.IsEmpty);

			baz.SubCriteria.Add("moo", new ConstantSearchCondition(true));

			// now it should be false, because baz has a non-empty sub condition
			Assert.IsFalse(sc.IsEmpty);
		}
Esempio n. 20
0
		public void Test_Constructor_Key()
		{
			var sc = new ConcreteSearchCriteria("foo");
			Assert.IsTrue(sc.IsEmpty);
			Assert.AreEqual("foo", sc.GetKey());
		}
Esempio n. 21
0
		public void Test_Constructor_Default()
		{
			var sc = new ConcreteSearchCriteria();
			Assert.IsTrue(sc.IsEmpty);
			Assert.AreEqual(null, sc.GetKey());
		}
 public TResultsType Results <TResultsType>(ConcreteSearchCriteria searchCriteria)
 {
     // return something
 }
Esempio n. 23
0
 public TResultsType Results(ConcreteSearchCriteria searchCriteria)
 {
Esempio n. 24
0
		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));
		}
Esempio n. 25
0
		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));
		}
Esempio n. 26
0
		public void Test_Constructor_Copy()
		{
			var sc = new ConcreteSearchCriteria("foo");
			Assert.IsTrue(sc.IsEmpty);
			Assert.AreEqual("foo", sc.GetKey());

			var sub = new ConcreteSearchCriteria("baz");
			sc.SubCriteria.Add("baz", sub);

			var copy = new ConcreteSearchCriteria(sc);
			Assert.AreEqual("foo", copy.GetKey());
			Assert.AreEqual(1, copy.SubCriteria.Count);
			Assert.IsTrue(copy.SubCriteria.ContainsKey("baz"));

			// check that the sub-criteria was actually cloned, not just copied
			Assert.IsFalse(ReferenceEquals(sc.SubCriteria["baz"], copy.SubCriteria["baz"]));
		}