1
+ using System . Threading . Tasks ;
2
+ using Bunit ;
3
+ using FluentAssertions ;
4
+ using LinkDotNet . Blog . TestUtilities ;
5
+ using LinkDotNet . Blog . Web ;
6
+ using LinkDotNet . Blog . Web . Pages ;
7
+ using LinkDotNet . Blog . Web . Shared ;
8
+ using LinkDotNet . Domain ;
9
+ using LinkDotNet . Infrastructure . Persistence ;
10
+ using Microsoft . Extensions . DependencyInjection ;
11
+ using Xunit ;
12
+
13
+ namespace LinkDotNet . Blog . IntegrationTests . Web . Pages
14
+ {
15
+ public class IndexTests : SqlDatabaseTestBase
16
+ {
17
+ [ Fact ]
18
+ public async Task ShouldShowAllBlogPostsWithLatestOneFirst ( )
19
+ {
20
+ var oldestBlogPost = new BlogPostBuilder ( ) . WithTitle ( "Old" ) . Build ( ) ;
21
+ var newestBlogPost = new BlogPostBuilder ( ) . WithTitle ( "New" ) . Build ( ) ;
22
+ await BlogPostRepository . StoreAsync ( oldestBlogPost ) ;
23
+ await BlogPostRepository . StoreAsync ( newestBlogPost ) ;
24
+ using var ctx = new TestContext ( ) ;
25
+ ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
26
+ ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
27
+ ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
28
+ var cut = ctx . RenderComponent < Index > ( ) ;
29
+
30
+ var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
31
+
32
+ blogPosts . Should ( ) . HaveCount ( 2 ) ;
33
+ blogPosts [ 0 ] . Find ( ".description h1" ) . InnerHtml . Should ( ) . Be ( "New" ) ;
34
+ blogPosts [ 1 ] . Find ( ".description h1" ) . InnerHtml . Should ( ) . Be ( "Old" ) ;
35
+ }
36
+
37
+ private static AppConfiguration CreateSampleAppConfiguration ( )
38
+ {
39
+ return new ( )
40
+ {
41
+ Introduction = new Introduction
42
+ {
43
+ Description = string . Empty ,
44
+ BackgroundUrl = string . Empty ,
45
+ ProfilePictureUrl = string . Empty ,
46
+ } ,
47
+ } ;
48
+ }
49
+ }
50
+ }
0 commit comments