Пример #1
0
        public void AnswerCount()
        {
            var answers = _answersRepository.GetAnswerCount(new [] { _question.Id });

            Assert.AreEqual(1, answers.Count);
            Assert.AreEqual(_question.Id, answers.Single().Key);
            Assert.AreEqual(5, answers.Single().Value);
        }
Пример #2
0
        public RichQuestion GetById(User viewingUser, int questionId, int answerStart, int numAnswers)
        {
            var      question         = _questionsRepository.GetById(questionId);
            var      votesOnQuestions = _questionVoteRepository.GetVoteCount(questionId);
            VoteType?vote             = null;

            if (viewingUser != null)
            {
                var voteOnQuestion = _questionVoteRepository.GetVote(viewingUser.Id, questionId);
                if (voteOnQuestion != null)
                {
                    vote = voteOnQuestion.Vote;
                }
            }
            var answers        = _answersRepository.GetTopAnswers(questionId, answerStart, numAnswers);
            var answerCount    = _answersRepository.GetAnswerCount(questionId);
            var answerIDs      = answers.Select(x => x.Id);
            var votesOnAnswers = viewingUser == null ? null : _answerVoteRepository.GetVotes(viewingUser.Id, answerIDs);

            return(new RichQuestion(question, votesOnQuestions.Total, vote, CreateRichAnswers(answers, votesOnAnswers), answerCount));
        }