@@ -22,8 +22,7 @@ public async Task ShouldShowCounts()
22
22
await Repository . StoreAsync ( blogPost ) ;
23
23
using var ctx = new TestContext ( ) ;
24
24
ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => Repository ) ;
25
- var visits = new List < KeyValuePair < string , int > > ( ) ;
26
- visits . Add ( new KeyValuePair < string , int > ( $ "blogPost/{ blogPost . Id } ", 5 ) ) ;
25
+ var visits = new List < KeyValuePair < string , int > > { new ( $ "blogPost/{ blogPost . Id } ", 5 ) } ;
27
26
var pageVisitCounts = visits . OrderByDescending ( s => s . Value ) ;
28
27
29
28
var cut = ctx . RenderComponent < VisitCountPerPage > ( p => p . Add (
@@ -39,5 +38,33 @@ public async Task ShouldShowCounts()
39
38
elements [ 1 ] . InnerHtml . Should ( ) . Be ( "5" ) ;
40
39
elements [ 2 ] . InnerHtml . Should ( ) . Be ( "2" ) ;
41
40
}
41
+
42
+ [ Fact ]
43
+ public void ShouldIgnoreNullForBlogPostVisits ( )
44
+ {
45
+ using var ctx = new TestContext ( ) ;
46
+ ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => Repository ) ;
47
+
48
+ var cut = ctx . RenderComponent < VisitCountPerPage > ( p => p . Add (
49
+ s => s . PageVisitCount , null ) ) ;
50
+
51
+ var elements = cut . FindAll ( "td" ) . ToList ( ) ;
52
+ elements . Should ( ) . BeEmpty ( ) ;
53
+ }
54
+
55
+ [ Fact ]
56
+ public void ShouldIgnoreNotBlogPosts ( )
57
+ {
58
+ using var ctx = new TestContext ( ) ;
59
+ ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => Repository ) ;
60
+ var visits = new List < KeyValuePair < string , int > > { new ( "notablogpost" , 5 ) } ;
61
+ var pageVisitCounts = visits . OrderByDescending ( s => s . Value ) ;
62
+
63
+ var cut = ctx . RenderComponent < VisitCountPerPage > ( p => p . Add (
64
+ s => s . PageVisitCount , pageVisitCounts ) ) ;
65
+
66
+ var elements = cut . FindAll ( "td" ) . ToList ( ) ;
67
+ elements . Should ( ) . BeEmpty ( ) ;
68
+ }
42
69
}
43
70
}
0 commit comments