10
10
using LinkDotNet . Blog . Web . Features . Admin . Dashboard . Components ;
11
11
using LinkDotNet . Blog . Web . Features . Admin . Dashboard . Services ;
12
12
using Microsoft . AspNetCore . Components ;
13
+ using Microsoft . EntityFrameworkCore ;
13
14
using Microsoft . Extensions . DependencyInjection ;
14
15
15
16
namespace LinkDotNet . Blog . IntegrationTests . Web . Features . Admin . Dashboard . Components ;
@@ -22,8 +23,7 @@ public async Task ShouldShowCounts()
22
23
var blogPost = new BlogPostBuilder ( ) . WithTitle ( "I was clicked" ) . WithLikes ( 2 ) . Build ( ) ;
23
24
await Repository . StoreAsync ( blogPost ) ;
24
25
using var ctx = new TestContext ( ) ;
25
- ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => new Repository < BlogPost > ( DbContext ) ) ;
26
- ctx . Services . AddScoped < IRepository < UserRecord > > ( _ => new Repository < UserRecord > ( DbContext ) ) ;
26
+ RegisterRepositories ( ctx ) ;
27
27
await SaveBlogPostArticleClicked ( blogPost . Id , 10 ) ;
28
28
29
29
var cut = ctx . RenderComponent < VisitCountPerPage > ( ) ;
@@ -58,8 +58,7 @@ public async Task ShouldFilterByDate()
58
58
await DbContext . SaveChangesAsync ( ) ;
59
59
using var ctx = new TestContext ( ) ;
60
60
ctx . ComponentFactories . Add < DateRangeSelector , FilterStubComponent > ( ) ;
61
- ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => new Repository < BlogPost > ( DbContext ) ) ;
62
- ctx . Services . AddScoped < IRepository < UserRecord > > ( _ => new Repository < UserRecord > ( DbContext ) ) ;
61
+ RegisterRepositories ( ctx ) ;
63
62
var cut = ctx . RenderComponent < VisitCountPerPage > ( ) ;
64
63
var filter = new Filter { StartDate = new DateTime ( 2019 , 1 , 1 ) , EndDate = new DateTime ( 2020 , 12 , 31 ) } ;
65
64
@@ -93,15 +92,20 @@ public async Task ShouldShowTotalClickCount()
93
92
await DbContext . UserRecords . AddRangeAsync ( new [ ] { clicked1 , clicked2 , clicked3 , clicked4 } ) ;
94
93
await DbContext . SaveChangesAsync ( ) ;
95
94
using var ctx = new TestContext ( ) ;
96
- ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => new Repository < BlogPost > ( DbContext ) ) ;
97
- ctx . Services . AddScoped < IRepository < UserRecord > > ( _ => new Repository < UserRecord > ( DbContext ) ) ;
95
+ RegisterRepositories ( ctx ) ;
98
96
99
97
var cut = ctx . RenderComponent < VisitCountPerPage > ( ) ;
100
98
101
99
cut . WaitForState ( ( ) => cut . FindAll ( "td" ) . Any ( ) ) ;
102
100
cut . Find ( "#total-clicks" ) . Unwrap ( ) . TextContent . Should ( ) . Be ( "4 clicks in total" ) ;
103
101
}
104
102
103
+ private void RegisterRepositories ( TestContextBase ctx )
104
+ {
105
+ ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => new Repository < BlogPost > ( DbContextFactory ) ) ;
106
+ ctx . Services . AddScoped < IRepository < UserRecord > > ( _ => new Repository < UserRecord > ( DbContextFactory ) ) ;
107
+ }
108
+
105
109
private async Task SaveBlogPostArticleClicked ( string blogPostId , int count )
106
110
{
107
111
var urlClicked = $ "blogPost/{ blogPostId } ";
0 commit comments