Skip to content

Commit 99cb4af

Browse files
committed
unit test for multiple conflicting argument values
1 parent 7b18eef commit 99cb4af

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

test/Serilog.Settings.Configuration.Tests/ConfigurationSettingsTests.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ namespace Serilog.Settings.Configuration.Tests
1212
{
1313
public class ConfigurationSettingsTests
1414
{
15-
static LoggerConfiguration ConfigFromJson(string jsonString)
15+
static LoggerConfiguration ConfigFromJson(string jsonString, string secondJsonSource = null)
1616
{
17-
var config = new ConfigurationBuilder().AddJsonString(jsonString).Build();
17+
var builder = new ConfigurationBuilder().AddJsonString(jsonString);
18+
if(secondJsonSource != null) builder.AddJsonString(secondJsonSource);
19+
var config = builder.Build();
1820
return new LoggerConfiguration()
1921
.ReadFrom.Configuration(config);
2022
}
@@ -556,5 +558,42 @@ public void WriteToSubLoggerWithLevelSwitchIsSupported()
556558

557559
Assert.Equal(1, DummyRollingFileSink.Emitted.Count);
558560
}
561+
562+
[Trait("Bugfix", "#103")]
563+
[Fact]
564+
public void MultipleArgumentValuesThrowsInvalidOperationException()
565+
{
566+
var jsonDiscreteValue = @"{
567+
""Serilog"": {
568+
""Using"": [""TestDummies""],
569+
""WriteTo"": [{
570+
""Name"": ""DummyRollingFile"",
571+
""Args"": {""pathFormat"" : ""C:\\""}
572+
}]
573+
}
574+
}";
575+
576+
var jsonComplexValue = @"{
577+
""Serilog"": {
578+
""Using"": [""TestDummies""],
579+
""WriteTo"": [{
580+
""Name"": ""DummyRollingFile"",
581+
""Args"": {""pathFormat"" : { ""foo"" : ""bar"" } }
582+
}]
583+
}
584+
}";
585+
586+
// These will combine into a ConfigurationSection object that has both
587+
// Value == "C:\" and GetChildren() == List<string>. No configuration
588+
// extension matching this exists (in theory an "object" argument could
589+
// accept either value). ConfigurationReader should throw as soon as
590+
// the multiple values are recognized; it will never attempt to locate
591+
// a matching argument.
592+
593+
var ex = Assert.Throws<InvalidOperationException>(() => ConfigFromJson(jsonDiscreteValue, jsonComplexValue));
594+
595+
Assert.Contains("Combined configuration sources", ex.Message);
596+
Assert.Contains("pathFormat", ex.Message);
597+
}
559598
}
560599
}

0 commit comments

Comments
 (0)