Skip to content

Commit

Permalink
Updated IntegrationTestBase config setup to use seperate test DB
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonGeering committed Apr 8, 2021
1 parent f415ae0 commit 3c387a4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/AdminAssistant.Test/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using AdminAssistant.DomainModel.Shared;
using AdminAssistant.Infra.DAL.EntityFramework;
using AdminAssistant.Infra.DAL.EntityFramework.Model;
using AdminAssistant.Infra.DAL.EntityFramework.Model.Accounts;
Expand Down Expand Up @@ -54,7 +55,22 @@ public IntegrationTestBase()
// TODO: Configure production logging.
#endif
})
.ConfigureAppConfiguration((hostingContext, config) => config.AddUserSecrets(Assembly.GetExecutingAssembly()))
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddUserSecrets(Assembly.GetExecutingAssembly());

// Get config from UserSecrets so we can refer to it when setting up Test config setting overrides below ...
var baseConfig = config.Build();

// Switch out the DB for a Test DB by convention - assumes a '_TestDB' suffix to prod DB name ...
var connectionStringFromUserSecrets = baseConfig.GetSection(nameof(ConfigurationSettings)).Get<ConfigurationSettings>().ConnectionString;
// TODO: Update this to use connection string builder so it is not hard coded to assume Application Name from config.
var testConnectionString = connectionStringFromUserSecrets.Replace("Initial Catalog=AdminAssistant", "Initial Catalog=AdminAssistant_Test", StringComparison.InvariantCulture);
config.AddInMemoryCollection(new Dictionary<string, string>
{
[$"{nameof(ConfigurationSettings)}:{nameof(ConfigurationSettings.ConnectionString)}"] = testConnectionString
});
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Blazor.Server.Startup>();
Expand All @@ -63,6 +79,8 @@ public IntegrationTestBase()
});

_testServer = hostBuilder.Start();

// TODO: Update this to use connection string builder so it is not hard coded to assume Application Name from config.
_connectionString = _testServer.Services.GetRequiredService<IApplicationDbContext>().ConnectionString.Replace("Application Name=AdminAssistant;", "Application Name=AdminAssistant_TestDBReset", StringComparison.InvariantCulture);

_checkpoint = new Respawn.Checkpoint
Expand Down

0 comments on commit 3c387a4

Please sign in to comment.