コード例 #1
0
        public void AnotherTest()
        {
            using (ISession db = TestSessionFactory.OpenSession())
            {
                var query = (from t in db.Query <Teacher>() select t).ToList();

                Assert.AreEqual(0, query.Count);
            }
        }
コード例 #2
0
        public void TestMethod1()
        {
            using (ISession db = TestSessionFactory.OpenSession())
            {
                Teacher teacher = new Teacher
                {
                    Name = "test teacher"
                };

                db.Save(teacher);

                SchoolClass schoolClass = new SchoolClass
                {
                    Name      = "MTH 101",
                    TeacherId = 1
                };
                db.Save(schoolClass);

                Student student = new Student
                {
                    Name    = "Joe",
                    classid = 1
                };
                db.Save(student);

                var query = (from t in db.Query <Teacher>()
                             join c in db.Query <SchoolClass>() on t.Id equals c.TeacherId
                             join s in db.Query <Student>() on c.Id equals s.classid
                             select new
                {
                    TeacherName = t.Name,
                    ClassName = c.Name,
                    StudentName = s.Name
                }).ToList();


                Assert.AreEqual(1, query.Count);
            }
        }
コード例 #3
0
        public void ThirdTest()
        {
            using (ISession db = TestSessionFactory.OpenSession())
            {
                Teacher teacher = new Teacher
                {
                    Name = "test teacher"
                };

                db.Save(teacher);

                teacher = new Teacher
                {
                    Name = "test teacher2"
                };

                db.Save(teacher);

                var query = (from t in db.Query <Teacher>() select t).ToList();

                Assert.AreEqual(2, query.Count);
            }
        }
コード例 #4
0
 public void CreateSessionAndRepository()
 {
     Session    = TestSessionFactory.OpenSession();
     Repository = (TRepository)Activator.CreateInstance(typeof(TRepository), Session);
 }