Skip to content

Commit

Permalink
Don't update blogpost when same reference
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jan 15, 2022
1 parent e3a014d commit 39b7df9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/LinkDotNet.Blog.Domain/BlogPost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ private BlogPost()

public void Update(BlogPost from)
{
if (from == this)
{
return;
}

Title = from.Title;
ShortDescription = from.ShortDescription;
Content = from.Content;
Expand All @@ -75,4 +80,4 @@ private void ReplaceTags(IEnumerable<Tag> tags)
}
}
}
}
}
13 changes: 12 additions & 1 deletion tests/LinkDotNet.Blog.UnitTests/Domain/BlogPostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ public void ShouldSetDateWhenGiven()

blog.UpdatedDate.Should().Be(somewhen);
}
}

[Fact]
public void ShouldNotDeleteTagsWhenSameReference()
{
var bp = new BlogPostBuilder().WithTags("tag 1").Build();

bp.Update(bp);

bp.Tags.Should().HaveCount(1);
bp.Tags.Single().Content.Should().Be("tag 1");
}
}

0 comments on commit 39b7df9

Please sign in to comment.