Ejemplo n.º 1
0
        public void Nh_Can_Fetch_Eager_Load()
        {
            EmptyDatabase();
            IRepository<Question> db = new NH.Repository<Question>(NhModelsMapper.GetSession(connectionString));
            Test_Can_Fetch_Eager_Load_Common(db);

            // Arrange
            EmptyDatabase();
            Question qx = new Question { Text = "42" };
            db.Save(qx);
            db.Evict(qx.QuestionId);

            // Act
            var qq = NH.EagerExtensionHelper.EagerLoad(db.All.Where(x => x.QuestionId == qx.QuestionId), "Answers").SingleOrDefault();

            // Assert
            Assert.AreEqual("42", qq.Text);
        }
Ejemplo n.º 2
0
        public void Test_Can_Fetch_Eager_Load_Common(IRepository<Question> r)
        {
            var q = new Question { Text = "Hello", Answers = new List<Answer>(), Comments = new List<QuestionComment>() };
            var c = new QuestionComment { Question = q, Text = "Hei" };
            var a = new Answer { Question = q, Text = "Yes", Comments = new List<AnswerComment>() };

            q.Comments.Add(c);

            var ac = new AnswerComment { Answer = a, Text = "hahah" };
            a.Comments.Add(ac);

            q.Answers.Add(a);

            r.Save(q);

            r.Evict(q.QuestionId);

            var g = r.GetEager(q.QuestionId, "Answers", "Comments");

            Assert.AreEqual("Hello", g.Text);
            // System.Threading.Thread.Sleep(10000);
            Assert.AreEqual("Hei", g.Comments[0].Text);
            Assert.AreEqual("Yes", g.Answers[0].Text);
            Assert.AreEqual("hahah", g.Answers[0].Comments[0].Text);
        }
Ejemplo n.º 3
0
        private Question PopulateQuestion()
        {
            var importantQuestion = new Question { Text = "The answer to life", Poster = "Boy", Answers = new List<Answer>(), Comments = new List<QuestionComment>() };
            var answerA = new Answer { Question = importantQuestion, Text = "42", Poster = "John", Comments = new List<AnswerComment>() };
            var answerB = new Answer { Question = importantQuestion, Text = "143", Poster = "Paul", Comments = new List<AnswerComment>() };
            var answerC = new Answer { Question = importantQuestion, Text = "888", Poster = "Elton", Comments = new List<AnswerComment>() };
            importantQuestion.Answers.Add(answerA);
            importantQuestion.Answers.Add(answerB);
            importantQuestion.Answers.Add(answerC);

            var commentToImportantQuestion = new QuestionComment { Question = importantQuestion, Text = "Is There?", Poster = "George" };
            importantQuestion.Comments.Add(commentToImportantQuestion);
            var commentToAnswerB = new AnswerComment { Answer = answerB, Text = "Isn't the answer is 7 times 6?", Poster = "Ringo" };
            answerB.Comments.Add(commentToAnswerB);
            return importantQuestion;
        }