9
9
using LinkDotNet . Domain ;
10
10
using LinkDotNet . Infrastructure . Persistence ;
11
11
using Microsoft . Extensions . DependencyInjection ;
12
+ using Moq ;
13
+ using Toolbelt . Blazor . HeadElement ;
12
14
using Xunit ;
13
15
14
16
namespace LinkDotNet . Blog . IntegrationTests . Web . Pages
@@ -24,8 +26,7 @@ public async Task ShouldShowAllBlogPostsWithLatestOneFirst()
24
26
await BlogPostRepository . StoreAsync ( newestBlogPost ) ;
25
27
using var ctx = new TestContext ( ) ;
26
28
ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
27
- ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
28
- ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
29
+ RegisterComponents ( ctx ) ;
29
30
var cut = ctx . RenderComponent < Index > ( ) ;
30
31
cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
31
32
@@ -45,8 +46,7 @@ public async Task ShouldOnlyShowPublishedPosts()
45
46
await BlogPostRepository . StoreAsync ( unpublishedPost ) ;
46
47
using var ctx = new TestContext ( ) ;
47
48
ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
48
- ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
49
- ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
49
+ RegisterComponents ( ctx ) ;
50
50
var cut = ctx . RenderComponent < Index > ( ) ;
51
51
cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
52
52
@@ -62,8 +62,7 @@ public async Task ShouldOnlyLoadTenEntities()
62
62
await CreatePublishedBlogPosts ( 11 ) ;
63
63
using var ctx = new TestContext ( ) ;
64
64
ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
65
- ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
66
- ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
65
+ RegisterComponents ( ctx ) ;
67
66
var cut = ctx . RenderComponent < Index > ( ) ;
68
67
cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
69
68
@@ -78,8 +77,7 @@ public async Task ShouldLoadNextBatchOnClick()
78
77
await CreatePublishedBlogPosts ( 11 ) ;
79
78
using var ctx = new TestContext ( ) ;
80
79
ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
81
- ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
82
- ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
80
+ RegisterComponents ( ctx ) ;
83
81
var cut = ctx . RenderComponent < Index > ( ) ;
84
82
85
83
cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:last-child a" ) . Click ( ) ;
@@ -95,8 +93,7 @@ public async Task ShouldLoadPreviousBatchOnClick()
95
93
await CreatePublishedBlogPosts ( 11 ) ;
96
94
using var ctx = new TestContext ( ) ;
97
95
ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
98
- ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
99
- ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
96
+ RegisterComponents ( ctx ) ;
100
97
var cut = ctx . RenderComponent < Index > ( ) ;
101
98
cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
102
99
cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:last-child a" ) . Click ( ) ;
@@ -132,5 +129,12 @@ private async Task CreatePublishedBlogPosts(int amount)
132
129
await BlogPostRepository . StoreAsync ( blogPost ) ;
133
130
}
134
131
}
132
+
133
+ private void RegisterComponents ( TestContextBase ctx )
134
+ {
135
+ ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
136
+ ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
137
+ ctx . Services . AddScoped ( _ => new Mock < IHeadElementHelper > ( ) . Object ) ;
138
+ }
135
139
}
136
140
}
0 commit comments