示例#1
0
        public async void UpdateAsync_BlogPost()
        {
            // Arrange
            // since the final step of UpdateAsync is to call repo.GetAsync,
            // make it return a non-null post
            postRepoMock.Setup(repo => repo.GetAsync(It.IsAny <int>(), EPostType.BlogPost))
            .Returns(Task.FromResult(new Post()));

            // Act
            var tagTitles = new List <string> {
                "test", "c#"
            };
            await blogPostService.UpdateAsync(new BlogPost
            {
                Id            = 1,
                UserId        = Actor.ADMIN_ID,
                Title         = "Hello World!",
                Slug          = "hello-world-from-browser",
                Body          = "This is my first post",
                Excerpt       = null,
                CategoryId    = 1,
                TagTitles     = tagTitles,
                CreatedOn     = DateTimeOffset.Now,
                Status        = EPostStatus.Published,
                CommentStatus = ECommentStatus.AllowComments,
            });

            // Assert
            mediatorMock.Verify(m => m.Publish(
                                    It.Is <BlogPostBeforeUpdate>(e => e.CategoryTitle == null &&
                                                                 e.TagTitles == tagTitles &&
                                                                 e.PostTags.Count() == 0), cancellationToken), Times.Once);

            postRepoMock.Verify(repo => repo.UpdateAsync(
                                    It.Is <Post>(p => p.Slug == "hello-world-from-browser" &&
                                                 p.Excerpt == null &&
                                                 p.Category == null),
                                    null, tagTitles), Times.Once);
        }