public void TestEvaluateSubclass()
        {
            Person     person = new CustomPerson();
            ICriterion before = Restrictions.Eq("Father", person);
            ICriterion after  = ExpressionProcessor.ProcessExpression <Person>(p => p.Father == person);

            Assert.AreEqual(before.ToString(), after.ToString());
        }
Beispiel #2
0
        public void NullRestriction()
        {
            ICriteria expected =
                CreateTestCriteria(typeof(Person), "personAlias")
                .Add(Restrictions.IsNull("Name"))
                .Add(Restrictions.IsNull("Name"))
                .Add(Restrictions.IsNull("Name"))
                .Add(Restrictions.IsNull("Father"))
                .Add(Restrictions.IsNull("Father"))
                .Add(Restrictions.IsNull("NullableGender"))
                .Add(Restrictions.IsNull("NullableAge"))
                .Add(Restrictions.IsNull("NullableIsParent"))
                .Add(Restrictions.Not(Restrictions.IsNull("Name")))
                .Add(Restrictions.Not(Restrictions.IsNull("Name")))
                .Add(Restrictions.Not(Restrictions.IsNull("Name")))
                .Add(Restrictions.Not(Restrictions.IsNull("Father")))
                .Add(Restrictions.Not(Restrictions.IsNull("Father")))
                .Add(Restrictions.Not(Restrictions.IsNull("NullableGender")))
                .Add(Restrictions.Not(Restrictions.IsNull("NullableAge")))
                .Add(Restrictions.Not(Restrictions.IsNull("NullableIsParent")))
                .Add(Restrictions.IsNull("personAlias.Name"));

            Person       personAlias = null;
            CustomPerson nullPerson  = null;

            Person.StaticName = null;
            Person emptyPerson = new Person()
            {
                Name = null
            };
            var actual =
                CreateTestQueryOver <Person>(() => personAlias)
                .Where(p => p.Name == null)
                .Where(p => p.Name == Person.StaticName)
                .Where(p => p.Name == emptyPerson.Name)
                .Where(p => p.Father == null)
                .Where(p => p.Father == nullPerson)
                .Where(p => p.NullableGender == null)
                .Where(p => p.NullableAge == null)
                .Where(p => p.NullableIsParent == null)
                .Where(p => p.Name != null)
                .Where(p => p.Name != Person.StaticName)
                .Where(p => p.Name != emptyPerson.Name)
                .Where(p => p.Father != null)
                .Where(p => p.Father != nullPerson)
                .Where(p => p.NullableGender != null)
                .Where(p => p.NullableAge != null)
                .Where(p => p.NullableIsParent != null)
                .Where(() => personAlias.Name == null);

            AssertCriteriaAreEqual(expected, actual);
        }
Beispiel #3
0
        public void TestFindMemberExpressionConstants()
        {
            var children = new List <Child> {
                new Child {
                    Nickname = "test nickname"
                }
            };
            Person person =
                new CustomPerson()
            {
                Name        = "test name",
                MiddleName  = "test middle name",
                NullableAge = 4,
                Children    = children,
            };

            Assert.That(Projection(() => person.Name), Is.EqualTo("test name"));
            Assert.That(Projection(() => ((CustomPerson)person).MiddleName), Is.EqualTo("test middle name"));
            Assert.That(Projection(() => "test name"), Is.EqualTo("test name"));
            Assert.That(Projection(() => person.NullableAge.Value), Is.EqualTo(4));
            Assert.That(Projection(() => person.GetType()), Is.EqualTo(typeof(CustomPerson)));
            Assert.That(Projection(() => person.Children.First().Nickname), Is.EqualTo("test nickname"));
            Assert.That(Projection(() => children[0].Nickname), Is.EqualTo("test nickname"));
        }
		public void IsType()
		{
			using (ISession s = OpenSession())
			using (ITransaction t = s.BeginTransaction())
			{
				var father1 = new Person() { Name = "Father 1" };
				var father2 = new CustomPerson() { Name = "Father 2" };

				var person1 = new Person() { Name = "Person 1", Father = father2 };
				var person2 = new CustomPerson() { Name = "Person 2", Father = father1 };

				s.Save(father1);
				s.Save(father2);

				s.Save(person1);
				s.Save(person2);

				t.Commit();
			}

			using (ISession s = OpenSession())
			{
				var actual =
					s.QueryOver<Person>()
						.Where(p => p is CustomPerson)
						.And(p => p.Father != null)
						.List();

				Assert.That(actual.Count, Is.EqualTo(1));
				Assert.That(actual[0].Name, Is.EqualTo("Person 2"));
			}

			using (ISession s = OpenSession())
			{
				var actual =
					s.QueryOver<Person>()
						.Where(p => p.GetType() == typeof(CustomPerson))
						.And(p => p.Father != null)
						.List();

				Assert.That(actual.Count, Is.EqualTo(1));
				Assert.That(actual[0].Name, Is.EqualTo("Person 2"));
			}

			using (ISession s = OpenSession())
			{
				Person f = null;
				var actual =
					s.QueryOver<Person>()
						.JoinAlias(p => p.Father, () => f)
						.Where(() => f is CustomPerson)
						.List();

				Assert.That(actual.Count, Is.EqualTo(1));
				Assert.That(actual[0].Name, Is.EqualTo("Person 1"));
			}

			using (ISession s = OpenSession())
			{
				Person f = null;
				var actual =
					s.QueryOver<Person>()
						.JoinAlias(p => p.Father, () => f)
						.Where(() => f.GetType() == typeof(CustomPerson))
						.List();

				Assert.That(actual.Count, Is.EqualTo(1));
				Assert.That(actual[0].Name, Is.EqualTo("Person 1"));
			}
		}
        public void IsType()
        {
            using (ISession s = OpenSession())
                using (ITransaction t = s.BeginTransaction())
                {
                    var father1 = new Person()
                    {
                        Name = "Father 1"
                    };
                    var father2 = new CustomPerson()
                    {
                        Name = "Father 2"
                    };

                    var person1 = new Person()
                    {
                        Name = "Person 1", Father = father2
                    };
                    var person2 = new CustomPerson()
                    {
                        Name = "Person 2", Father = father1
                    };

                    s.Save(father1);
                    s.Save(father2);

                    s.Save(person1);
                    s.Save(person2);

                    t.Commit();
                }

            using (ISession s = OpenSession())
            {
                var actual =
                    s.QueryOver <Person>()
                    .Where(p => p is CustomPerson)
                    .And(p => p.Father != null)
                    .List();

                Assert.That(actual.Count, Is.EqualTo(1));
                Assert.That(actual[0].Name, Is.EqualTo("Person 2"));
            }

            using (ISession s = OpenSession())
            {
                var actual =
                    s.QueryOver <Person>()
                    .Where(p => p.GetType() == typeof(CustomPerson))
                    .And(p => p.Father != null)
                    .List();

                Assert.That(actual.Count, Is.EqualTo(1));
                Assert.That(actual[0].Name, Is.EqualTo("Person 2"));
            }

            using (ISession s = OpenSession())
            {
                Person f      = null;
                var    actual =
                    s.QueryOver <Person>()
                    .JoinAlias(p => p.Father, () => f)
                    .Where(() => f is CustomPerson)
                    .List();

                Assert.That(actual.Count, Is.EqualTo(1));
                Assert.That(actual[0].Name, Is.EqualTo("Person 1"));
            }

            using (ISession s = OpenSession())
            {
                Person f      = null;
                var    actual =
                    s.QueryOver <Person>()
                    .JoinAlias(p => p.Father, () => f)
                    .Where(() => f.GetType() == typeof(CustomPerson))
                    .List();

                Assert.That(actual.Count, Is.EqualTo(1));
                Assert.That(actual[0].Name, Is.EqualTo("Person 1"));
            }
        }
		public void TestEvaluateSubclass()
		{
			Person person = new CustomPerson();
			ICriterion before = Restrictions.Eq("Father", person);
			ICriterion after = ExpressionProcessor.ProcessExpression<Person>(p => p.Father == person);
			Assert.AreEqual(before.ToString(), after.ToString());
		}