1
+ using System . Threading . Tasks ;
2
+ using Blazored . Toast . Services ;
3
+ using Bunit ;
4
+ using Bunit . TestDoubles ;
5
+ using FluentAssertions ;
6
+ using LinkDotNet . Blog . Web . Pages . Admin ;
7
+ using LinkDotNet . Blog . Web . Shared . Admin ;
8
+ using LinkDotNet . Domain ;
9
+ using LinkDotNet . Infrastructure . Persistence ;
10
+ using Microsoft . EntityFrameworkCore ;
11
+ using Microsoft . Extensions . DependencyInjection ;
12
+ using Moq ;
13
+ using Xunit ;
14
+
15
+ namespace LinkDotNet . Blog . IntegrationTests . Web . Pages . Admin
16
+ {
17
+ public class CreateNewBlogPostPageTests : SqlDatabaseTestBase < BlogPost >
18
+ {
19
+ [ Fact ]
20
+ public async Task ShouldSaveBlogPostOnSave ( )
21
+ {
22
+ using var ctx = new TestContext ( ) ;
23
+ var toastService = new Mock < IToastService > ( ) ;
24
+ ctx . AddTestAuthorization ( ) . SetAuthorized ( "some username" ) ;
25
+ ctx . Services . AddScoped < IRepository < BlogPost > > ( _ => Repository ) ;
26
+ ctx . Services . AddScoped ( _ => toastService . Object ) ;
27
+ using var cut = ctx . RenderComponent < CreateNewBlogPostPage > ( ) ;
28
+ var newBlogPost = cut . FindComponent < CreateNewBlogPost > ( ) ;
29
+
30
+ TriggerNewBlogPost ( newBlogPost ) ;
31
+
32
+ var blogPostFromDb = await DbContext . BlogPosts . SingleOrDefaultAsync ( t => t . Title == "My Title" ) ;
33
+ blogPostFromDb . Should ( ) . NotBeNull ( ) ;
34
+ blogPostFromDb . ShortDescription . Should ( ) . Be ( "My short Description" ) ;
35
+ toastService . Verify ( t => t . ShowInfo ( "Created BlogPost My Title" , string . Empty ) , Times . Once ) ;
36
+ }
37
+
38
+ private void TriggerNewBlogPost ( IRenderedComponent < CreateNewBlogPost > cut )
39
+ {
40
+ cut . Find ( "#title" ) . Change ( "My Title" ) ;
41
+ cut . Find ( "#short" ) . Change ( "My short Description" ) ;
42
+ cut . Find ( "#content" ) . Change ( "My content" ) ;
43
+ cut . Find ( "#preview" ) . Change ( "My preview url" ) ;
44
+ cut . Find ( "#published" ) . Change ( false ) ;
45
+ cut . Find ( "#tags" ) . Change ( "Tag1,Tag2,Tag3" ) ;
46
+
47
+ cut . Find ( "form" ) . Submit ( ) ;
48
+ }
49
+ }
50
+ }
0 commit comments