@@ -14,37 +14,32 @@ public abstract class OptimizelyIntegrationTestBase(bool includeCommerce) : IAsy
1414{
1515 private IHost _host = null ! ;
1616
17- // Since we use same container with different db names we can remove one of these :P
1817 private MsSqlContainer _databaseContainer = null ! ;
1918
2019 protected IServiceProvider Services { get ; private set ; } = null ! ;
2120
2221 public virtual async Task InitializeAsync ( )
2322 {
24- // Create Cms SQL Server container
23+ // Create SQL Server container
2524 var container = await CreateDatabaseContainer ( ) ;
2625
27- // Create CMS databse
28- var cmsDatabaseConnectionString = await CreateNamedDatabaseConnectionString ( container , "Cms" ) ;
26+ // Create CMS database
27+ var cmsDatabaseConnectionString = await CreateNamedDatabase ( container , "Cms" ) ;
2928
3029 string ? commerceDatabaseConnectionString = null ;
3130 if ( includeCommerce )
3231 {
33- commerceDatabaseConnectionString = await CreateNamedDatabaseConnectionString ( container , "Commerce" ) ;
32+ // Create Commerce database
33+ commerceDatabaseConnectionString = await CreateNamedDatabase ( container , "Commerce" ) ;
3434 }
3535
36-
3736 // Build CMS host
3837 _host = Host . CreateDefaultBuilder ( )
3938 . ConfigureWebHostDefaults ( webHostBuilder =>
4039 {
4140 webHostBuilder
4241 . ConfigureServices ( ( context , services ) =>
4342 {
44- // TODO: Only include in CMS test
45- // Add data importer service to setup default content for the tests
46- //services.AddTransient<OptimizelyDataImporter>();
47-
4843 // Must be set here too for initialization to work for CMS
4944 services . Configure < DataAccessOptions > ( o =>
5045 {
@@ -62,8 +57,8 @@ public virtual async Task InitializeAsync()
6257 configBuilder . AddInMemoryCollection ( testSettings ) ;
6358 } ) ;
6459
65- // To configure aps separately with Cms and Commerce Statup files in separate projects
66- ConfiureWebHostBuilder ( webHostBuilder ) ;
60+ // To configure apps separately with Cms and Commerce Startup files in separate projects
61+ ConfigureWebHostBuilder ( webHostBuilder ) ;
6762 } )
6863 . ConfigureCmsDefaults ( )
6964 . Build ( ) ;
@@ -78,7 +73,7 @@ public virtual async Task InitializeAsync()
7873 await _host . StartAsync ( ) ;
7974 }
8075
81- protected abstract void ConfiureWebHostBuilder ( IWebHostBuilder webHostBuilder ) ;
76+ protected abstract void ConfigureWebHostBuilder ( IWebHostBuilder webHostBuilder ) ;
8277
8378 public async Task DisposeAsync ( )
8479 {
@@ -89,26 +84,22 @@ public async Task DisposeAsync()
8984
9085 private async Task < MsSqlContainer > CreateDatabaseContainer ( )
9186 {
92- var container = new MsSqlBuilder ( )
87+ _databaseContainer = new MsSqlBuilder ( )
9388 . WithImage ( "mcr.microsoft.com/mssql/server:2022-latest" )
9489 . WithPassword ( "yourStrong(!)Password" )
9590 . Build ( ) ;
9691
97- await container . StartAsync ( ) ;
98-
99- _databaseContainer = container ;
92+ await _databaseContainer . StartAsync ( ) ;
10093
10194 return _databaseContainer ;
10295 }
10396
104- private async Task < string > CreateNamedDatabaseConnectionString ( MsSqlContainer container , string databaseName )
97+ private async Task < string > CreateNamedDatabase ( MsSqlContainer container , string databaseName )
10598 {
106- databaseName = $ "{ GetType ( ) . Name } -{ databaseName } ";
107-
10899 var masterConnectionString = container . GetConnectionString ( ) ;
109100 await using var connection = new SqlConnection ( masterConnectionString ) ;
110101 await connection . OpenAsync ( ) ;
111- await using var command = new SqlCommand ( $ "CREATE DATABASE [{ databaseName } ]", connection ) ;
102+ await using var command = new SqlCommand ( $ "CREATE DATABASE [{ GetType ( ) . Name } - { databaseName } ]", connection ) ;
112103 await command . ExecuteNonQueryAsync ( ) ;
113104
114105 // Workaround to set separate database names inside container
0 commit comments