コード例 #1
0
        public void WhenAContributorAddsAnAnswer_WithInsufficientReputation_AnExceptionShouldBeThrown()
        {
            var poster   = new Poster(new Name("Joe", "Bloggs"));
            var content  = new PlainTextContent();
            var question = new Question("A question", content, poster);

            var contributor = new Contributor(new Name("Joe", "Bloggs"), new Reputation(100));
            var answer      = new Answer(question.Id, contributor, new PlainTextContent("This is an answer"));

            Assert.Throws <InsufficientReputationException>(() => question.AddAnAnswer(answer));
        }
コード例 #2
0
        public void WhenAContributorThatIsNotThePoster_UnacceptsAnAnswerAnException_ShouldBeThrown()
        {
            var poster   = new Poster(new Name("Joe", "Bloggs"));
            var content  = new PlainTextContent();
            var question = new Question("A question", content, poster);

            var contributor = new Contributor(new Name("Joe", "Bloggs"), new Reputation(1000));
            var answer      = new Answer(question.Id, contributor, new PlainTextContent("This is an answer"));

            question.AddAnAnswer(answer);

            Assert.Throws <InvalidContributorException>(() => question.UnacceptAnswer(answer.Id, contributor.Id));
        }
コード例 #3
0
        public void WhenContributorAddsAComment_TheCommentShouldNotBeAddded_IfTheyDoNotHaveEnoughReputation()
        {
            var poster   = new Poster(new Name("Joe", "Bloggs"));
            var content  = new PlainTextContent();
            var question = new Question("A question", content, poster);

            var answerContributor = new Contributor(new Name("Jane", "Doe"), new Reputation(1000));
            var answer            = new Answer(question.Id, answerContributor, new PlainTextContent());

            var commentContributor = new Contributor(new Name("John", "Doe"), new Reputation(100));

            question.AddAnAnswer(answer);

            Assert.Throws <InsufficientReputationException>(() => question.CommentOnAnswer(answer.Id, new Comment(commentContributor, "This is a comment")));
        }
コード例 #4
0
        public void WhenAContributorAddsAnAsnwer_TheAnswer_ShouldBeAdded()
        {
            var poster   = new Poster(new Name("Joe", "Bloggs"));
            var content  = new PlainTextContent();
            var question = new Question("A question", content, poster);

            var contributor = new Contributor(new Name("Joe", "Bloggs"), new Reputation(1000));
            var answer      = new Answer(question.Id, contributor, new PlainTextContent("This is an answer"));

            var isAdded = false;

            DomainEvents.ListenFor <AnswerAdded>(@event =>
            {
                isAdded = true;
            });

            question.AddAnAnswer(answer);

            Assert.True(isAdded);
            Assert.Equal(1, question.Answers.Count);
        }
コード例 #5
0
        public void WhenThePosterUnacceptsAnAsnwer_TheAnswer_ShouldBeMarkedAsNotAccepted()
        {
            var poster   = new Poster(new Name("Joe", "Bloggs"));
            var content  = new PlainTextContent();
            var question = new Question("A question", content, poster);

            var contributor = new Contributor(new Name("Joe", "Bloggs"), new Reputation(1000));
            var answer      = new Answer(question.Id, contributor, new PlainTextContent("This is an answer"));

            question.AddAnAnswer(answer);
            question.AcceptAnswer(answer.Id, poster.Id);

            var isUnaccepted = false;

            DomainEvents.ListenFor <AnswerUnaccepted>(@event =>
            {
                isUnaccepted = true;
            });

            question.UnacceptAnswer(answer.Id, poster.Id);

            Assert.True(isUnaccepted);
            Assert.Null(question.AcceptedAnswer);
        }