public void AddNewCommentWithValidDataShouldAddItToTheRepo() { // Arrange string author = "testAuthor"; string content = "testContent"; int postId = 1; List<CommentViewModel> comments = new List<CommentViewModel>(); var postViewMock = new Mock<IPostView>(); postViewMock.Setup(v => v.Id).Returns(postId); postViewMock.Setup(v => v.Comments).Returns(comments); postViewMock.SetupSet(v => v.Comments = It.IsAny<List<CommentViewModel>>()) .Callback<List<CommentViewModel>>((list) => comments = list); var fakePostPresenter = new PostPresenter(postViewMock.Object, this.mocksContainer.DataMock.Object); // Act fakePostPresenter.AddComment(author, content); // Assert Assert.AreEqual(3, this.mocksContainer.CommentsRepoMock.Object.All().Count()); Assert.AreEqual(1, comments.Count); }
public void AddNewCommentWithNotValidDataShouldThrowExeption() { // Arrange string author = ""; string content = ""; int postId = 1; List<CommentViewModel> comments = new List<CommentViewModel>(); var postViewMock = new Mock<IPostView>(); postViewMock.Setup(v => v.Id).Returns(postId); postViewMock.Setup(v => v.Comments).Returns(comments); postViewMock.SetupSet(v => v.Comments = It.IsAny<List<CommentViewModel>>()) .Callback<List<CommentViewModel>>((list) => comments = list); var fakePostPresenter = new PostPresenter(postViewMock.Object, this.mocksContainer.DataMock.Object); // Act fakePostPresenter.AddComment(author, content); }