public void NullData() { var repositoryMock = new Mock <IRepository <PostCommentCount> >(); IEnumerable <PostCommentCount> result = null; repositoryMock.Setup(x => x.Save(It.IsAny <IEnumerable <PostCommentCount> >())).Callback <IEnumerable <PostCommentCount> >(items => { result = items; }); var aggregator = new CommentCountAggregator(repositoryMock.Object); aggregator.Aggregate(null, null); Assert.AreEqual(0, result.Count()); }
public void PostWithoutComment() { var repositoryMock = new Mock <IRepository <PostCommentCount> >(); IEnumerable <PostCommentCount> result = null; repositoryMock.Setup(x => x.Save(It.IsAny <IEnumerable <PostCommentCount> >())).Callback <IEnumerable <PostCommentCount> >(items => { result = items; }); var aggregator = new CommentCountAggregator(repositoryMock.Object); var posts = new List <Post>() { CreatePost("postOne"), CreatePost("postTwo") }; var comments = new List <Comment>() { CreateComment("postTwo"), CreateComment("postTwo") }; aggregator.Aggregate(posts, comments); Assert.AreEqual(2, result.Count()); Assert.IsNotNull(result.FirstOrDefault(x => x.PostId == "postOne" && x.CommentCount == 0)); Assert.IsNotNull(result.FirstOrDefault(x => x.PostId == "postTwo" && x.CommentCount == 2)); }