Skip to content

Commit cd1fd0f

Browse files
Merge pull request #181 from Stravaig-Projects/#159/damaged-connection-string
#159: LogAllConnectionStrings message is corrupted on damaged connection string
2 parents 7563b8a + c2e8163 commit cd1fd0f

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

release-notes/wip-release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Date: ???
88

99
- #176: Add support for .NET 6.0
1010

11+
### Bugs
12+
13+
- #159: Fix for when multiple connection strings cannot be interpreted.Do you
14+
1115
### Dependent Packages
1216

1317
- .NET 6.0

src/Stravaig.Configuration.Diagnostics.Core/Renderers/StructuredAllConnectionStringsRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public MessageEntry Render(IConfiguration config, ConfigurationDiagnosticsOption
5959
return new MessageEntry(
6060
new AggregateException("Multiple errors occurred when rendering the connection strings.", exceptions),
6161
messageTemplate.ToString(),
62-
properties);
62+
properties.ToArray());
6363
}
6464
}
6565
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.Extensions.Configuration;
4+
using NUnit.Framework;
5+
using Shouldly;
6+
using Stravaig.Configuration.Diagnostics.Logging;
7+
8+
namespace Stravaig.Extensions.Configuration.Diagnostics.Tests.RegressionTests
9+
{
10+
[TestFixture]
11+
public class BadConnectionStringTests : LoggerExtensionsTestBase
12+
{
13+
[Test]
14+
public void MultipleConnectionStringCannotBeInterpreted()
15+
{
16+
SetupConfig(c =>
17+
{
18+
c.AddInMemoryCollection(new[]
19+
{
20+
new KeyValuePair<string, string>("ConnectionStrings:Bad1", "*** I'm the first placeholder, value to be filled in by another provider ***"),
21+
new KeyValuePair<string, string>("ConnectionStrings:Good", "server=TheServer;database=TheDatabase;userName=TheUserName;password=ThePassword"),
22+
new KeyValuePair<string, string>("ConnectionStrings:Bad2", "*** I'm the second placeholder, value to be filled in by another provider ***"),
23+
});
24+
});
25+
SetupLogger();
26+
27+
Logger.LogAllConnectionStringsAsInformation(ConfigRoot);
28+
29+
var logs = GetLogs();
30+
var log = logs[0];
31+
32+
log.Exception.ShouldBeOfType<AggregateException>();
33+
((AggregateException)log.Exception).InnerExceptions.Count.ShouldBe(2);
34+
((AggregateException)log.Exception).InnerExceptions.ShouldAllBe(e => e.GetType() == typeof(ArgumentException));
35+
log.OriginalMessage.ShouldContain("The \"{Bad1_name}\" connection string value could not be interpreted as a connection string.");
36+
log.OriginalMessage.ShouldContain("The \"{Bad2_name}\" connection string value could not be interpreted as a connection string.");
37+
}
38+
}
39+
}

src/Stravaig.Configuration.Diagnostics.Tests/Stravaig.Configuration.Diagnostics.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
1717
<PackageReference Include="Serilog.Sinks.TextWriter" Version="2.1.0" />
1818
<PackageReference Include="Shouldly" Version="4.0.3" />
19-
<PackageReference Include="Stravaig.Extensions.Logging.Diagnostics" Version="1.1.3" />
19+
<PackageReference Include="Stravaig.Extensions.Logging.Diagnostics" Version="1.2.0" />
2020
<PackageReference Include="Stravaig.Jailbreak" Version="0.1.0" />
2121
</ItemGroup>
2222

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.5
1+
1.1.0

0 commit comments

Comments
 (0)