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)); }
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)); }
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"))); }
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); }
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); }