1
+ using System . Collections . Generic ;
2
+ using FluentAssertions ;
3
+ using LinkDotNet . Blog . Web ;
4
+ using Microsoft . Extensions . Configuration ;
5
+ using Xunit ;
6
+
7
+ namespace LinkDotNet . Blog . UnitTests . Web
8
+ {
9
+ public class AppConfigurationFactoryTests
10
+ {
11
+ [ Fact ]
12
+ public void ShouldMapFromAppConfiguration ( )
13
+ {
14
+ var inMemorySettings = new Dictionary < string , string >
15
+ {
16
+ { "BlogName" , "UnitTest" } ,
17
+ { "GithubAccountUrl" , "github" } ,
18
+ { "LinkedInAccountUrl" , "linkedIn" } ,
19
+ { "ConnectionString" , "cs" } ,
20
+ { "DatabaseName" , "db" } ,
21
+ { "Introduction:BackgroundUrl" , "someurl" } ,
22
+ { "Introduction:ProfilePictureUrl" , "anotherurl" } ,
23
+ { "Introduction:Description" , "desc" } ,
24
+ } ;
25
+ var configuration = new ConfigurationBuilder ( )
26
+ . AddInMemoryCollection ( inMemorySettings )
27
+ . Build ( ) ;
28
+
29
+ var appConfiguration = AppConfigurationFactory . Create ( configuration ) ;
30
+
31
+ appConfiguration . BlogName . Should ( ) . Be ( "UnitTest" ) ;
32
+ appConfiguration . GithubAccountUrl . Should ( ) . Be ( "github" ) ;
33
+ appConfiguration . HasGithubAccount . Should ( ) . BeTrue ( ) ;
34
+ appConfiguration . LinkedinAccountUrl . Should ( ) . Be ( "linkedIn" ) ;
35
+ appConfiguration . HasLinkedinAccount . Should ( ) . BeTrue ( ) ;
36
+ appConfiguration . ConnectionString . Should ( ) . Be ( "cs" ) ;
37
+ appConfiguration . DatabaseName . Should ( ) . Be ( "db" ) ;
38
+ appConfiguration . Introduction . BackgroundUrl . Should ( ) . Be ( "someurl" ) ;
39
+ appConfiguration . Introduction . ProfilePictureUrl . Should ( ) . Be ( "anotherurl" ) ;
40
+ appConfiguration . Introduction . Description . Should ( ) . Be ( "desc" ) ;
41
+ }
42
+
43
+ [ Fact ]
44
+ public void ShouldSetGithubLinkedAccountAccordingToValueSet ( )
45
+ {
46
+ var inMemorySettings = new Dictionary < string , string >
47
+ {
48
+ { "Introduction:BackgroundUrl" , "someurl" } ,
49
+ { "Introduction:ProfilePictureUrl" , "anotherurl" } ,
50
+ { "Introduction:Description" , "desc" } ,
51
+ } ;
52
+ var configuration = new ConfigurationBuilder ( )
53
+ . AddInMemoryCollection ( inMemorySettings )
54
+ . Build ( ) ;
55
+
56
+ var appConfiguration = AppConfigurationFactory . Create ( configuration ) ;
57
+
58
+ appConfiguration . HasGithubAccount . Should ( ) . BeFalse ( ) ;
59
+ appConfiguration . HasLinkedinAccount . Should ( ) . BeFalse ( ) ;
60
+ }
61
+ }
62
+ }
0 commit comments