protected Question SaveQuestion(User user)
        {
            var question = QuestionsFactory.CreateQuestion(user);

            QuestionsRepository.Save(question);
            return(question);
        }
示例#2
0
        public void GetNewestQuestions()
        {
            var user = CreateUser();

            // save some quetsions
            var question1 = QuestionsFactory.CreateQuestion(user);

            question1.UpdateDate = new DateTime(2009, 01, 01);
            _questionsRepository.Save(question1);
            var question2 = QuestionsFactory.CreateQuestion(user);

            question2.UpdateDate = new DateTime(2009, 12, 31);
            _questionsRepository.Save(question2);
            var question3 = QuestionsFactory.CreateQuestion(user);

            question3.UpdateDate = new DateTime(2009, 05, 06);
            _questionsRepository.Save(question3);
            var question4 = QuestionsFactory.CreateQuestion(user);

            question4.UpdateDate = new DateTime(2003, 05, 06);
            _questionsRepository.Save(question4);

            var questions = _questionsRepository.GetNewestQuestions(3);

            Assert.AreEqual(3, questions.Length);
            Assert.AreEqual(question2.Id, questions[0].Id);
            Assert.AreEqual(question3.Id, questions[1].Id);
            Assert.AreEqual(question1.Id, questions[2].Id);
        }
示例#3
0
        public void AddQuestion_IsRetrieved()
        {
            var user = CreateUser();

            var question = QuestionsFactory.CreateQuestion(user);

            _questionsRepository.Save(question);
            Assert.AreNotEqual(0, question.Id);

            var savedQuestion = _questionsRepository.GetById(question.Id);

            Assert.AreEqual(user.Id, savedQuestion.Author.Id);
            Assert.AreEqual(question.Title, savedQuestion.Title);
        }
示例#4
0
        public void AddQuestion_GetAllUserQuestions()
        {
            var user = CreateUser();

            var question = QuestionsFactory.CreateQuestion(user);

            _questionsRepository.Save(question);

            var savedUser = _userRepository.GetById(user.Id);

            Assert.AreEqual(1, savedUser.Questions.Count);

            var savedQuestion = savedUser.Questions.Single();

            Assert.AreEqual(question.Id, savedQuestion.Id);
            Assert.AreEqual(question.Title, savedQuestion.Title);
            Assert.AreEqual(question.Body, savedQuestion.Body);
        }