Esempio n. 1
0
        public void Voteable_SameUserCannotApplyVoteTwice_Throws()
        {
            // Arrange
            var target     = new QuestionBuilder().SetupValidQuestion().Build();
            var firstVote  = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();
            var secondVote = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();

            target.ApplyVote(firstVote);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.ApplyVote(secondVote));
        }
Esempio n. 2
0
        public void Voteable_CanApplyVoteToComment_Successfully()
        {
            // Arrange
            var target = new CommentBuilder().SetupValidComment().Build();
            var vote   = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();

            // Act
            target.ApplyVote(vote);

            // Assert
            Assert.Equal(1, target.VotesSum);
            Assert.Contains(vote, target.Votes);
        }
Esempio n. 3
0
        public void Voteable_CannotRevokeNonExistingVote_Throws()
        {
            // Arrange
            var target     = new QuestionBuilder().SetupValidQuestion().Build();
            var limits     = new LimitsBuilder().Build();
            var firstVote  = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();
            var secondVote = new VoteBuilder(target).SetupValidUpvote().ByAnotherUser().Build();

            target.ApplyVote(firstVote);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.RevokeVote(secondVote, limits));
        }
Esempio n. 4
0
        public void Voteable_CanApplyVoteToAnswer_Successfully()
        {
            // Arrange
            var question = new QuestionBuilder().SetupValidQuestion().Build();
            var target   = new AnswerBuilder().SetupValidAnswer(question).Build();
            var vote     = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();

            // Act
            target.ApplyVote(vote);

            // Assert
            Assert.Equal(1, target.VotesSum);
            Assert.Contains(vote, target.Votes);
        }
Esempio n. 5
0
        public void Voteable_CanRevokeVoteWithinDeadline_Successfully()
        {
            // Arrange
            var target = new QuestionBuilder().SetupValidQuestion().Build();
            var vote   = new VoteBuilder(target).SetupValidUpvote().ByOneUser().Build();
            var limits = new LimitsBuilder().Build();

            target.ApplyVote(vote);

            // Act
            target.RevokeVote(vote, limits);

            // Assert
            Assert.Equal(0, target.VotesSum);
        }
Esempio n. 6
0
        public void Voteable_CannotRevokeVoteOutsideDeadline_Successfully()
        {
            // Arrange
            var target    = new QuestionBuilder().SetupValidQuestion().Build();
            var limits    = new LimitsBuilder().Build();
            var firstVote = new VoteBuilder(target)
                            .SetupValidUpvote()
                            .ByOneUser()
                            .MakeTimeGoBy()
                            .Build();

            target.ApplyVote(firstVote);

            // Act, Assert
            Assert.Throws <BusinessException>(() => target.RevokeVote(firstVote, limits));
        }