Skip to content

Commit

Permalink
Fix connection string section load.
Browse files Browse the repository at this point in the history
  • Loading branch information
tusmester committed Jul 15, 2019
1 parent 8c9521a commit 973bd37
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SenseNet.Tools.Tests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
</sectionGroup>
<section name="feature1" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<connectionStrings>
<add name="cs1" connectionString="csvalue1"/>
</connectionStrings>
<appSettings>
<add key="key1" value="value1" />
<add key="key2" value="123" />
Expand Down
15 changes: 15 additions & 0 deletions src/SenseNet.Tools.Tests/SnConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ void Test()
Test();
}

//============================================================================== Legacy tests

[TestMethod]
public void SnConfig_Legacy_ConnectionString()
{
void Test()
{
Assert.AreEqual("csvalue1", SnConfig.GetValue<string>("connectionStrings", "cs1"));
Assert.AreEqual("csvalue1", SnConfig.GetValue<string>("ConnectionStrings", "cs1"));
}

using (new ConfigurationSwindler(new SnLegacyConfiguration()))
Test();
}

//============================================================================== Error tests

[TestMethod]
Expand Down
4 changes: 4 additions & 0 deletions src/SenseNet.Tools/Configuration/SnLegacyConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public string this[string key]
{
get
{
// special section in old configuration files
if (string.Compare(Key, "connectionStrings", StringComparison.InvariantCultureIgnoreCase) == 0)
return ConfigurationManager.ConnectionStrings[key]?.ConnectionString;

var configValue = _configValues?[key];

// backward compatibility: fallback to the appsettings section
Expand Down

0 comments on commit 973bd37

Please sign in to comment.