File tree Expand file tree Collapse file tree 3 files changed +51
-4
lines changed
LinkDotNet.Blog.UnitTests/Domain Expand file tree Collapse file tree 3 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ public static BlogPost Create(
43
43
UpdatedDate = updatedDate ?? DateTime . Now ,
44
44
PreviewImageUrl = previewImageUrl ,
45
45
IsPublished = isPublished ,
46
- Tags = tags ? . Select ( t => new Tag { Content = t . Trim ( ) } ) . ToList ( ) ,
46
+ Tags = tags ? . Select ( Tag . Create ) . ToList ( ) ,
47
47
} ;
48
48
49
49
return blogPost ;
Original file line number Diff line number Diff line change 1
- namespace LinkDotNet . Blog . Domain ;
1
+ using System ;
2
+
3
+ namespace LinkDotNet . Blog . Domain ;
2
4
3
5
public class Tag
4
6
{
5
- public string Id { get ; set ; }
7
+ private Tag ( )
8
+ {
9
+ }
10
+
11
+ public string Id { get ; private set ; }
12
+
13
+ public string Content { get ; private set ; }
14
+
15
+ public static Tag Create ( string content )
16
+ {
17
+ if ( string . IsNullOrWhiteSpace ( content ) )
18
+ {
19
+ throw new ArgumentNullException ( nameof ( content ) ) ;
20
+ }
6
21
7
- public string Content { get ; set ; }
22
+ return new Tag
23
+ {
24
+ Content = content . Trim ( ) ,
25
+ } ;
26
+ }
8
27
}
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using FluentAssertions ;
3
+ using LinkDotNet . Blog . Domain ;
4
+ using Xunit ;
5
+
6
+ namespace LinkDotNet . Blog . UnitTests . Domain ;
7
+
8
+ public class TagTests
9
+ {
10
+ [ Fact ]
11
+ public void ShouldCreateTag ( )
12
+ {
13
+ var tag = Tag . Create ( " Test " ) ;
14
+
15
+ tag . Content . Should ( ) . Be ( "Test" ) ;
16
+ }
17
+
18
+ [ Theory ]
19
+ [ InlineData ( "" ) ]
20
+ [ InlineData ( null ) ]
21
+ [ InlineData ( " " ) ]
22
+ public void ShouldThrowExceptionIfInvalid ( string content )
23
+ {
24
+ Action act = ( ) => Tag . Create ( content ) ;
25
+
26
+ act . Should ( ) . Throw < ArgumentNullException > ( ) ;
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments