public void ConnectionString_Overridden_By_CloudFoundryConfig() { // arrange // simulate an appsettings file var appsettings = new Dictionary <string, string>() { ["mysql:client:ConnectionString"] = "Server=fake;Database=test;Uid=steeltoe;Pwd=password;" }; // add environment variables as Cloud Foundry would Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION); Environment.SetEnvironmentVariable("VCAP_SERVICES", MySqlTestHelpers.SingleServerVCAP); // add settings to config var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(appsettings); configurationBuilder.AddEnvironmentVariables(); configurationBuilder.AddCloudFoundry(); var config = configurationBuilder.Build(); // act var sconfig = new MySqlProviderConnectorOptions(config); // assert Assert.NotEqual(appsettings["mysql:client:ConnectionString"], sconfig.ToString()); // NOTE: for this test, we don't expect VCAP_SERVICES to be parsed, // this test is only here to demonstrate that when a binding is present, // a pre-supplied connectionString is not returned }
public void ConnectionString_Overridden_By_CloudFoundryConfig() { // arrange // simulate an appsettings file var appsettings = new Dictionary <string, string>() { ["mysql:client:ConnectionString"] = "Server=fake;Database=test;Uid=steeltoe;Pwd=password;" }; // add environment variables as Cloud Foundry would Environment.SetEnvironmentVariable("VCAP_APPLICATION", TestHelpers.VCAP_APPLICATION); Environment.SetEnvironmentVariable("VCAP_SERVICES", MySqlTestHelpers.SingleServerVCAP); // add settings to config ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(appsettings); configurationBuilder.AddEnvironmentVariables(); configurationBuilder.AddCloudFoundry(); var config = configurationBuilder.Build(); // act var sconfig = new MySqlProviderConnectorOptions(config); // assert Assert.NotEqual(appsettings["mysql:client:ConnectionString"], sconfig.ToString()); }
public void ConnectionString_Returned_AsConfigured() { var appsettings = new Dictionary <string, string>() { ["mysql:client:ConnectionString"] = "Server=fake;Database=test;Uid=steeltoe;Pwd=password;" }; var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddInMemoryCollection(appsettings); var config = configurationBuilder.Build(); var sconfig = new MySqlProviderConnectorOptions(config); Assert.Equal(appsettings["mysql:client:ConnectionString"], sconfig.ToString()); }