public void GetOnNonExistingVote_ReturnsNull()
        {
            var author   = UserFactory.CreateUser();
            var question = SaveQuestion(author);

            Assert.IsNull(QuestionVoteRepository.GetVote(author, question));
        }
Пример #2
0
        private void CreateData()
        {
            _questionAuthor = UserFactory.CreateUser();
            _question       = SaveQuestion(_questionAuthor);
            for (int i = 0; i < 5; ++i)
            {
                var answer = new Answer
                {
                    Author          = _questionAuthor,
                    Body            = i.ToString(),
                    CreatedDate     = DateTime.Now,
                    LastRelatedUser = _questionAuthor,
                    QuestionId      = _question.Id,
                    UpdateDate      = DateTime.Now
                };
                _answersRepository.Save(answer);
                _answers.Add(answer);

                // add i up-votes for answer i
                for (int j = 0; j < i; ++j)
                {
                    var voter = UserFactory.CreateUser();
                    AnswerVoteRepository.CreateOrUpdateVote(voter, answer, VoteType.ThumbUp);
                }
            }
        }
        public void BulkCount()
        {
            var author    = UserFactory.CreateUser();
            var voter1    = UserFactory.CreateUser();
            var voter2    = UserFactory.CreateUser();
            var voter3    = UserFactory.CreateUser();
            var question1 = SaveQuestion(author);
            var question2 = SaveQuestion(author);

            QuestionVoteRepository.CreateOrUpdateVote(voter1, question1, VoteType.ThumbUp);
            QuestionVoteRepository.CreateOrUpdateVote(voter2, question1, VoteType.ThumbUp);
            QuestionVoteRepository.CreateOrUpdateVote(voter3, question1, VoteType.ThumbDown);

            QuestionVoteRepository.CreateOrUpdateVote(voter1, question2, VoteType.ThumbDown);
            QuestionVoteRepository.CreateOrUpdateVote(voter2, question2, VoteType.ThumbDown);

            var votes = QuestionVoteRepository.GetVoteCount(new[] { question1.Id, question2.Id });

            Assert.AreEqual(2, votes.Count);
            Assert.AreEqual(1, votes[question1.Id]);
            Assert.AreEqual(-2, votes[question2.Id]);

            AssertVotesOnQuestion(1, question1);

            AssertVotesOnQuestion(-2, question2);
        }
        public void UnvotedQuestion_CountVotesIsZero()
        {
            var user     = UserFactory.CreateUser();
            var question = SaveQuestion(user);

            var voteCount = QuestionVoteRepository.GetVoteCount(question.Id);

            Assert.AreEqual(0, voteCount.ThumbUps);
            Assert.AreEqual(0, voteCount.ThumbDowns);
            AssertVotesOnQuestion(0, question);
        }
        public void RemoveVote_RemovesCorrectVote()
        {
            var author   = UserFactory.CreateUser();
            var voter    = UserFactory.CreateUser();
            var question = SaveQuestion(author);

            QuestionVoteRepository.CreateOrUpdateVote(voter, question, VoteType.ThumbUp);
            Assert.AreEqual(1, TallyVotes(question.Id));
            AssertVotesOnQuestion(1, question);
            QuestionVoteRepository.RemoveVote(voter.Id, question.Id);
            Assert.AreEqual(0, TallyVotes(question.Id));
            AssertVotesOnQuestion(0, question);
        }
        public void AddAndReadVote()
        {
            var user     = UserFactory.CreateUser();
            var question = SaveQuestion(user);

            QuestionVoteRepository.CreateOrUpdateVote(user, question, VoteType.ThumbUp);
            var vote = QuestionVoteRepository.GetVote(user, question);

            Assert.AreEqual(user.Id, vote.Key.UserId);
            Assert.AreEqual(question.Id, vote.Key.PostId);
            Assert.AreEqual(VoteType.ThumbUp, vote.Vote);

            AssertVotesOnQuestion(1, question);
        }
        public void UpdatingAVoteTwice_DoesntUpdate_ThenUpdateToDifferetnVoteWorks()
        {
            var author   = UserFactory.CreateUser();
            var voter    = UserFactory.CreateUser();
            var question = SaveQuestion(author);

            QuestionVoteRepository.CreateOrUpdateVote(voter, question, VoteType.ThumbUp);
            Assert.AreEqual(1, TallyVotes(question.Id));
            AssertVotesOnQuestion(1, question);
            QuestionVoteRepository.CreateOrUpdateVote(voter, question, VoteType.ThumbUp);
            Assert.AreEqual(1, TallyVotes(question.Id));
            AssertVotesOnQuestion(1, question);
            QuestionVoteRepository.CreateOrUpdateVote(voter, question, VoteType.ThumbDown);
            Assert.AreEqual(-1, TallyVotes(question.Id));
            AssertVotesOnQuestion(-1, question);
        }
        public void TwoThumbUpsAndOneThumbDown_CountVotesIsCorrect()
        {
            // prepare users
            var askingUser  = UserFactory.CreateUser();
            var thumbUpper1 = UserFactory.CreateUser();
            var thumbUpper2 = UserFactory.CreateUser();
            var thumbDowner = UserFactory.CreateUser();

            // and question
            var question = SaveQuestion(askingUser);

            // vote
            QuestionVoteRepository.CreateOrUpdateVote(thumbUpper1, question, VoteType.ThumbUp);
            QuestionVoteRepository.CreateOrUpdateVote(thumbUpper2, question, VoteType.ThumbUp);
            QuestionVoteRepository.CreateOrUpdateVote(thumbDowner, question, VoteType.ThumbDown);

            // count votes
            var voteCount = QuestionVoteRepository.GetVoteCount(question.Id);

            Assert.AreEqual(2, voteCount.ThumbUps);
            Assert.AreEqual(1, voteCount.ThumbDowns);

            AssertVotesOnQuestion(1, question);
        }
Пример #9
0
 private User CreateUser()
 {
     return(UserFactory.CreateUser());
 }