1+ namespace FileProcessor . Tests
2+ {
3+ using System ;
4+ using System . Collections . Generic ;
5+ using System . Diagnostics ;
6+ using Lamar ;
7+ using Microsoft . AspNetCore . Hosting ;
8+ using Microsoft . Extensions . Configuration ;
9+ using Microsoft . Extensions . DependencyInjection ;
10+ using Moq ;
11+ using Xunit ;
12+
13+ public class BootstrapperTests
14+ {
15+ [ Fact ]
16+ public void VerifyBootstrapperIsValid ( )
17+ {
18+ Mock < IWebHostEnvironment > hostingEnvironment = new Mock < IWebHostEnvironment > ( ) ;
19+ hostingEnvironment . Setup ( he => he . EnvironmentName ) . Returns ( "Development" ) ;
20+ hostingEnvironment . Setup ( he => he . ContentRootPath ) . Returns ( "/home" ) ;
21+ hostingEnvironment . Setup ( he => he . ApplicationName ) . Returns ( "Test Application" ) ;
22+
23+ ServiceRegistry services = new ServiceRegistry ( ) ;
24+ Startup s = new Startup ( hostingEnvironment . Object ) ;
25+ Startup . Configuration = this . SetupMemoryConfiguration ( ) ;
26+
27+ this . AddTestRegistrations ( services , hostingEnvironment . Object ) ;
28+ s . ConfigureContainer ( services ) ;
29+ Startup . Container . AssertConfigurationIsValid ( AssertMode . Full ) ;
30+ }
31+
32+ private IConfigurationRoot SetupMemoryConfiguration ( )
33+ {
34+ Dictionary < String , String > configuration = new Dictionary < String , String > ( ) ;
35+
36+ IConfigurationBuilder builder = new ConfigurationBuilder ( ) ;
37+
38+ configuration . Add ( "ConnectionStrings:HealthCheck" , "HeathCheckConnString" ) ;
39+ configuration . Add ( "SecurityConfiguration:Authority" , "https://127.0.0.1" ) ;
40+ configuration . Add ( "EventStoreSettings:ConnectionString" , "https://127.0.0.1:2113" ) ;
41+ configuration . Add ( "EventStoreSettings:ConnectionName" , "UnitTestConnection" ) ;
42+ configuration . Add ( "EventStoreSettings:UserName" , "admin" ) ;
43+ configuration . Add ( "EventStoreSettings:Password" , "changeit" ) ;
44+ configuration . Add ( "AppSettings:UseConnectionStringConfig" , "false" ) ;
45+ configuration . Add ( "AppSettings:SecurityService" , "http://127.0.0.1" ) ;
46+ configuration . Add ( "AppSettings:MessagingServiceApi" , "http://127.0.0.1" ) ;
47+ configuration . Add ( "AppSettings:EstateManagementApi" , "http://127.0.0.1" ) ;
48+ configuration . Add ( "AppSettings:TransactionProcessorApi" , "http://127.0.0.1" ) ;
49+ configuration . Add ( "AppSettings:DatabaseEngine" , "SqlServer" ) ;
50+
51+ builder . AddInMemoryCollection ( configuration ) ;
52+
53+ return builder . Build ( ) ;
54+ }
55+
56+ private void AddTestRegistrations ( ServiceRegistry services ,
57+ IWebHostEnvironment hostingEnvironment )
58+ {
59+ services . AddLogging ( ) ;
60+ DiagnosticListener diagnosticSource = new DiagnosticListener ( hostingEnvironment . ApplicationName ) ;
61+ services . AddSingleton < DiagnosticSource > ( diagnosticSource ) ;
62+ services . AddSingleton < DiagnosticListener > ( diagnosticSource ) ;
63+ services . AddSingleton < IWebHostEnvironment > ( hostingEnvironment ) ;
64+ }
65+ }
66+ }
0 commit comments