Skip to content

Commit fcc0b60

Browse files
committed
Added IsPublished
1 parent 6c93740 commit fcc0b60

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

LinkDotNet.Blog.IntegrationTests/Infrastructure/Persistence/Sql/SqlRepositoryTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public sealed class SqlRepositoryTests : SqlDatabaseTestBase
1313
[Fact]
1414
public async Task ShouldLoadBlogPost()
1515
{
16-
var blogPost = BlogPost.Create("Title", "Subtitle", "Content", "url", new[] { "Tag 1", "Tag 2" });
16+
var blogPost = BlogPost.Create("Title", "Subtitle", "Content", "url", true, new[] { "Tag 1", "Tag 2" });
1717
await DbContext.BlogPosts.AddAsync(blogPost);
1818
await DbContext.SaveChangesAsync();
1919

@@ -24,6 +24,7 @@ public async Task ShouldLoadBlogPost()
2424
blogPostFromRepo.ShortDescription.Should().Be("Subtitle");
2525
blogPostFromRepo.Content.Should().Be("Content");
2626
blogPostFromRepo.PreviewImageUrl.Should().Be("url");
27+
blogPostFromRepo.IsPublished.Should().BeTrue();
2728
blogPostFromRepo.Tags.Should().HaveCount(2);
2829
var tagContent = blogPostFromRepo.Tags.Select(t => t.Content).ToList();
2930
tagContent.Should().Contain(new[] { "Tag 1", "Tag 2" });
@@ -32,7 +33,7 @@ public async Task ShouldLoadBlogPost()
3233
[Fact]
3334
public async Task ShouldSaveBlogPost()
3435
{
35-
var blogPost = BlogPost.Create("Title", "Subtitle", "Content", "url", new[] { "Tag 1", "Tag 2" });
36+
var blogPost = BlogPost.Create("Title", "Subtitle", "Content", "url", true, new[] { "Tag 1", "Tag 2" });
3637

3738
await BlogPostRepository.StoreAsync(blogPost);
3839

@@ -41,6 +42,7 @@ public async Task ShouldSaveBlogPost()
4142
blogPostFromContext.Title.Should().Be("Title");
4243
blogPostFromContext.ShortDescription.Should().Be("Subtitle");
4344
blogPostFromContext.Content.Should().Be("Content");
45+
blogPostFromContext.IsPublished.Should().BeTrue();
4446
blogPostFromContext.PreviewImageUrl.Should().Be("url");
4547
blogPostFromContext.Tags.Should().HaveCount(2);
4648
var tagContent = blogPostFromContext.Tags.Select(t => t.Content).ToList();
@@ -50,7 +52,7 @@ public async Task ShouldSaveBlogPost()
5052
[Fact]
5153
public async Task ShouldGetAllBlogPosts()
5254
{
53-
var blogPost = BlogPost.Create("Title", "Subtitle", "Content", "url", new[] { "Tag 1", "Tag 2" });
55+
var blogPost = BlogPost.Create("Title", "Subtitle", "Content", "url", true, new[] { "Tag 1", "Tag 2" });
5456
await DbContext.BlogPosts.AddAsync(blogPost);
5557
await DbContext.SaveChangesAsync();
5658

@@ -63,6 +65,7 @@ public async Task ShouldGetAllBlogPosts()
6365
blogPostFromRepo.ShortDescription.Should().Be("Subtitle");
6466
blogPostFromRepo.Content.Should().Be("Content");
6567
blogPostFromRepo.PreviewImageUrl.Should().Be("url");
68+
blogPostFromRepo.IsPublished.Should().BeTrue();
6669
blogPostFromRepo.Tags.Should().HaveCount(2);
6770
var tagContent = blogPostFromRepo.Tags.Select(t => t.Content).ToList();
6871
tagContent.Should().Contain(new[] { "Tag 1", "Tag 2" });

LinkDotNet.Blog.TestUtilities/BlogPostBuilder.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class BlogPostBuilder
88
private string shortDescription = "Some Text";
99
private string content = "Some Content";
1010
private string url = "localhost";
11+
private bool isPublished = true;
1112
private string[] tags;
1213

1314
public BlogPostBuilder WithTitle(string title)
@@ -40,9 +41,15 @@ public BlogPostBuilder WithTags(params string[] tags)
4041
return this;
4142
}
4243

44+
public BlogPostBuilder IsPublished(bool isPublished = true)
45+
{
46+
this.isPublished = isPublished;
47+
return this;
48+
}
49+
4350
public BlogPost Build()
4451
{
45-
return BlogPost.Create(title, shortDescription, content, url, tags);
52+
return BlogPost.Create(title, shortDescription, content, url, isPublished, tags);
4653
}
4754
}
4855
}

LinkDotNet.Blog.UnitTests/Domain/BlogPostTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public void ShouldUpdateBlogPost()
1313
{
1414
var blogPostToUpdate = new BlogPostBuilder().Build();
1515
blogPostToUpdate.Id = "random-id";
16-
var blogPost = BlogPost.Create("Title", "Desc", "Content", "Url");
16+
var blogPost = BlogPost.Create("Title", "Desc", "Content", "Url", true);
1717
blogPost.Id = "something else";
1818

1919
blogPostToUpdate.Update(blogPost);
@@ -22,13 +22,14 @@ public void ShouldUpdateBlogPost()
2222
blogPostToUpdate.ShortDescription.Should().Be("Desc");
2323
blogPostToUpdate.Content.Should().Be("Content");
2424
blogPostToUpdate.PreviewImageUrl.Should().Be("Url");
25+
blogPostToUpdate.IsPublished.Should().BeTrue();
2526
blogPostToUpdate.Tags.Should().BeNullOrEmpty();
2627
}
2728

2829
[Fact]
2930
public void ShouldTrimWhitespacesFromTags()
3031
{
31-
var blogPost = BlogPost.Create("Title", "Sub", "Content", "Ppeview", new[] { " Tag 1", " Tag 2 " });
32+
var blogPost = BlogPost.Create("Title", "Sub", "Content", "Preview", false, new[] { " Tag 1", " Tag 2 " });
3233

3334
blogPost.Tags.Select(t => t.Content).Should().Contain("Tag 1");
3435
blogPost.Tags.Select(t => t.Content).Should().Contain("Tag 2");

LinkDotNet.Blog.Web/Shared/Admin/CreateNewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public BlogPost ToBlogPost()
4040
{
4141
var tags = string.IsNullOrWhiteSpace(Tags) ? ArraySegment<string>.Empty : Tags.Split(",");
4242

43-
var blogPost = BlogPost.Create(Title, ShortDescription, Content, PreviewImageUrl, tags);
43+
var blogPost = BlogPost.Create(Title, ShortDescription, Content, PreviewImageUrl, true, tags);
4444
blogPost.Id = Id;
4545
return blogPost;
4646
}

LinkDotNet.Domain/BlogPost.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ private BlogPost()
2424

2525
public virtual ICollection<Tag> Tags { get; private set; }
2626

27-
public static BlogPost Create(string title, string shortDescription, string content, string previewImageUrl, IEnumerable<string> tags = null)
27+
public bool IsPublished { get; set; }
28+
29+
public static BlogPost Create(string title, string shortDescription, string content, string previewImageUrl,
30+
bool isPublished, IEnumerable<string> tags = null)
2831
{
2932
var blogPost = new BlogPost
3033
{
@@ -33,6 +36,7 @@ public static BlogPost Create(string title, string shortDescription, string cont
3336
Content = content,
3437
UpdatedDate = DateTime.Now,
3538
PreviewImageUrl = previewImageUrl,
39+
IsPublished = isPublished,
3640
Tags = tags?.Select(t => new Tag { Content = t.Trim() }).ToList(),
3741
};
3842

@@ -46,6 +50,7 @@ public void Update(BlogPost from)
4650
Content = from.Content;
4751
UpdatedDate = from.UpdatedDate;
4852
PreviewImageUrl = from.PreviewImageUrl;
53+
IsPublished = from.IsPublished;
4954
Tags = from.Tags;
5055
}
5156
}

0 commit comments

Comments
 (0)