Skip to content

Commit 39b7df9

Browse files
committed
Don't update blogpost when same reference
1 parent e3a014d commit 39b7df9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/LinkDotNet.Blog.Domain/BlogPost.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public static BlogPost Create(
5151

5252
public void Update(BlogPost from)
5353
{
54+
if (from == this)
55+
{
56+
return;
57+
}
58+
5459
Title = from.Title;
5560
ShortDescription = from.ShortDescription;
5661
Content = from.Content;
@@ -75,4 +80,4 @@ private void ReplaceTags(IEnumerable<Tag> tags)
7580
}
7681
}
7782
}
78-
}
83+
}

tests/LinkDotNet.Blog.UnitTests/Domain/BlogPostTests.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@ public void ShouldSetDateWhenGiven()
5959

6060
blog.UpdatedDate.Should().Be(somewhen);
6161
}
62-
}
62+
63+
[Fact]
64+
public void ShouldNotDeleteTagsWhenSameReference()
65+
{
66+
var bp = new BlogPostBuilder().WithTags("tag 1").Build();
67+
68+
bp.Update(bp);
69+
70+
bp.Tags.Should().HaveCount(1);
71+
bp.Tags.Single().Content.Should().Be("tag 1");
72+
}
73+
}

0 commit comments

Comments
 (0)