diff --git a/src/Service.Tests/Configuration/HotReload/ConfigurationHotReloadTests.cs b/src/Service.Tests/Configuration/HotReload/ConfigurationHotReloadTests.cs index de199a31e6..f2a3e33de2 100644 --- a/src/Service.Tests/Configuration/HotReload/ConfigurationHotReloadTests.cs +++ b/src/Service.Tests/Configuration/HotReload/ConfigurationHotReloadTests.cs @@ -40,6 +40,7 @@ public class ConfigurationHotReloadTests private static void GenerateConfigFile( DatabaseType databaseType = DatabaseType.MSSQL, + string sessionContext = "true", string connectionString = "", string restPath = "rest", string restEnabled = "true", @@ -61,7 +62,7 @@ private static void GenerateConfigFile( ""data-source"": { ""database-type"": """ + databaseType + @""", ""options"": { - ""set-session-context"": true + ""set-session-context"": " + sessionContext + @" }, ""connection-string"": """ + connectionString + @""" }, @@ -299,4 +300,41 @@ public async Task HotReloadConfigRuntimeGQLEnabledEndToEndTest() // Assert Assert.AreEqual(HttpStatusCode.NotFound, gQLResult.StatusCode); } + + /// + /// Hot reload the configuration file by saving a new database type and connection string. + /// Validate that the response from the server is correct when making a new request after + /// the change in database type. + /// + [TestCategory(MSSQL_ENVIRONMENT)] + [TestMethod] + public async Task HotReloadConfigDataSourceEndToEndTest() + { + // Arrange + RuntimeConfig previousRuntimeConfig = _configProvider.GetConfig(); + MsSqlOptions previousSessionContext = previousRuntimeConfig.DataSource.GetTypedOptions(); + + // String has additions that are not in original connection string + string expectedConnectionString = $"{ConfigurationTests.GetConnectionStringFromEnvironmentConfig(TestCategory.MSSQL).Replace("\\", "\\\\")}" + "Trusted_Connection=True;"; + + // Act + GenerateConfigFile( + sessionContext: "false", + connectionString: expectedConnectionString); + System.Threading.Thread.Sleep(3000); + + RuntimeConfig updatedRuntimeConfig = _configProvider.GetConfig(); + MsSqlOptions actualSessionContext = updatedRuntimeConfig.DataSource.GetTypedOptions(); + JsonElement reloadGQLContents = await GraphQLRequestExecutor.PostGraphQLRequestAsync( + _testClient, + _configProvider, + GQL_QUERY_NAME, + GQL_QUERY); + + // Assert + // If the assert succeeds it implies that the connection string is hot-reloadable + Assert.AreNotEqual(previousSessionContext, actualSessionContext); + Assert.AreEqual(false, actualSessionContext.SetSessionContext); + SqlTestHelper.PerformTestEqualJsonStrings(_bookDBOContents, reloadGQLContents.GetProperty("items").ToString()); + } }