File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed
LinkDotNet.Blog.UnitTests/Domain Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,23 @@ public void Update(BlogPost from)
57
57
UpdatedDate = from . UpdatedDate ;
58
58
PreviewImageUrl = from . PreviewImageUrl ;
59
59
IsPublished = from . IsPublished ;
60
- Tags = from . Tags ;
60
+ ReplaceTags ( from . Tags ) ;
61
+ }
62
+
63
+ private void ReplaceTags ( IEnumerable < Tag > tags )
64
+ {
65
+ Tags ? . Clear ( ) ;
66
+ if ( Tags == null || tags == null )
67
+ {
68
+ Tags = tags ? . ToList ( ) ;
69
+ }
70
+ else
71
+ {
72
+ foreach ( var tag in tags )
73
+ {
74
+ Tags . Add ( tag ) ;
75
+ }
76
+ }
61
77
}
62
78
}
63
79
}
Original file line number Diff line number Diff line change @@ -27,6 +27,20 @@ public void ShouldUpdateBlogPost()
27
27
blogPostToUpdate . Tags . Should ( ) . BeNullOrEmpty ( ) ;
28
28
}
29
29
30
+ [ Fact ]
31
+ public void ShouldUpdateTagsWhenExisting ( )
32
+ {
33
+ var blogPostToUpdate = new BlogPostBuilder ( ) . WithTags ( "tag 1" ) . Build ( ) ;
34
+ blogPostToUpdate . Id = "random-id" ;
35
+ var blogPost = new BlogPostBuilder ( ) . WithTags ( "tag 2" ) . Build ( ) ;
36
+ blogPost . Id = "something else" ;
37
+
38
+ blogPostToUpdate . Update ( blogPost ) ;
39
+
40
+ blogPostToUpdate . Tags . Should ( ) . HaveCount ( 1 ) ;
41
+ blogPostToUpdate . Tags . Single ( ) . Content . Should ( ) . Be ( "tag 2" ) ;
42
+ }
43
+
30
44
[ Fact ]
31
45
public void ShouldTrimWhitespacesFromTags ( )
32
46
{
Original file line number Diff line number Diff line change 3
3
4
4
namespace LinkDotNet . Blog . Web
5
5
{
6
- public class Program
6
+ public static class Program
7
7
{
8
8
public static void Main ( string [ ] args )
9
9
{
You can’t perform that action at this time.
0 commit comments