public void AnswerEditPresenter_EditAnswerShouldTrimContent()
        {
            var view = new Mock <IAnswerEditView>();

            view.SetupAllProperties();
            var forumData = new Mock <IForumData>();

            var answer = new Answer()
            {
                Id = 1, IsVisible = true
            };
            var comment = new Comment()
            {
                Id = 1, IsVisible = true
            };

            answer.Comments.Add(comment);

            forumData.Setup(f => f.AnswersRepository.GetAnswerById(It.IsAny <int>())).Returns(answer);


            var presenter = new AnswerEditPresenter(view.Object, forumData.Object);

            var testContent     = "  TestContent Should be at least 50 characters long!!!   ";
            var expectedContent = "TestContent Should be at least 50 characters long!!!";

            view.Raise(v => v.EditAnswer += null, view.Object, new ContentEventArgs(1, testContent));

            forumData.Verify(r => r.AnswersRepository.UpdateAnswer(It.Is <Answer>(a => a.Contents == expectedContent)), Times.Once);
            forumData.Verify(x => x.Save(), Times.Once);
        }
        public void AnswerEditPresenter_GetAnswerShouldReturnMessageWhenNotVisible()
        {
            var view = new Mock <IAnswerEditView>();

            view.SetupAllProperties();
            var forumData = new Mock <IForumData>();

            var presenter = new AnswerEditPresenter(view.Object, forumData.Object);

            var answer = new Answer()
            {
                Id = 1, IsVisible = false
            };
            var comment = new Comment()
            {
                Id = 1, IsVisible = true
            };

            answer.Comments.Add(comment);

            forumData.Setup(t => t.AnswersRepository.GetAnswerById(It.Is <int>(x => x == 1))).Returns(answer);

            view.Raise(v => v.GetAnswer += null, view.Object, new GetByIdEventArgs(1));

            StringAssert.Contains("File not found", view.Object.Model.Error);
        }
        public void AnswerEditPresenter_GetAnswerShouldGetItCorrectly()
        {
            var view = new Mock <IAnswerEditView>();

            view.SetupAllProperties();
            var forumData = new Mock <IForumData>();

            var presenter = new AnswerEditPresenter(view.Object, forumData.Object);

            var answer = new Answer()
            {
                Id = 1, IsVisible = true
            };
            var comment = new Comment()
            {
                Id = 1, IsVisible = true
            };

            answer.Comments.Add(comment);

            forumData.Setup(t => t.AnswersRepository.GetAnswerById(It.Is <int>(x => x == 1))).Returns(answer);

            view.Raise(v => v.GetAnswer += null, view.Object, new GetByIdEventArgs(1));

            Assert.AreEqual(answer, view.Object.Model.Answer);
        }
        public void AnswerEditPresenter_EditThreadShouldReturnMessageWhenContentLengthNotInRange(string testContent)
        {
            var view = new Mock <IAnswerEditView>();

            view.SetupAllProperties();
            var forumData = new Mock <IForumData>();

            var answer = new Answer()
            {
                Id = 1, IsVisible = true
            };

            forumData.Setup(f => f.AnswersRepository.GetAnswerById(It.IsAny <int>())).Returns(answer);

            var presenter = new AnswerEditPresenter(view.Object, forumData.Object);

            view.Raise(v => v.EditAnswer += null, view.Object, new ContentEventArgs(1, testContent));

            StringAssert.Contains("Content must be between", view.Object.Model.Error);
        }
        public void AnswerEditPresenter_EditCommentShouldThrowIfDbAnswersFail()
        {
            var view = new Mock <IAnswerEditView>();

            view.SetupAllProperties();
            var forumData = new Mock <IForumData>();

            var answer = new Answer()
            {
                Id = 1, IsVisible = true
            };

            forumData.Setup(f => f.AnswersRepository.GetAnswerById(It.IsAny <int>())).Returns(answer);
            forumData.Setup(f => f.AnswersRepository.UpdateAnswer(It.IsAny <Answer>())).Throws(new Exception());

            var presenter = new AnswerEditPresenter(view.Object, forumData.Object);

            var testContent = "TestContent Should be at least 50 characters long!!!";

            Assert.Throws <HttpException>(() => view.Raise(v => v.EditAnswer += null, view.Object, new ContentEventArgs(1, testContent)));
        }