示例#1
0
        private async Task UpdateBlogPost(BlogPost blogPost, UpdateBlogPostCommand message)
        {
            var tags          = message.Tags?.Select(s => new BlogPostTag(s)).ToList() ?? new List <BlogPostTag>();
            var externalLinks = message.ExternalLinks?.Select(el => new ExternalLink(el.Name, el.Url)).ToList() ?? new List <ExternalLink>();
            var category      = await _dbContext.Categories.FirstAsync(c => c.Id == message.CategoryId);

            var metaTags = message.MetaTags?.Select(m => new MetaTag(m.Name, m.Value));

            await _builder.UseBlogPost(blogPost)
            .WithContent(message)
            .WithImage(message.ImageFile)
            .WithTags(tags)
            .WithExternalLinks(externalLinks)
            .WithCategory(category)
            .WithMetaTags(metaTags)
            .Build();
        }
        public async Task BlogPostBuilder_DoesNotUpdatesBlogWithEqualMetaTag()
        {
            var blogPostContent = new BlogPostContent("", "", "");
            var author          = await Author.Create(new User(""), new AuthorProfile("", "", ""), Mock.Of <IAuthorValidator>());

            var category = new Category("", 1, "");
            var blogPost = new BlogPost(blogPostContent, author, category);

            blogPost.MetaTags.Add(new MetaTag("description", "test description"));
            var builder = new ExistingBlogPostBuilder(Mock.Of <IImageService>());
            var tags    = new[]
            {
                new MetaTag("description", "test description")
            };
            await builder.UseBlogPost(blogPost).WithMetaTags(tags).Build();

            Assert.Single(blogPost.MetaTags);
        }