-
Notifications
You must be signed in to change notification settings - Fork 130
Multiple value exception, fixes #103 #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7b18eef
99cb4af
36df0a6
5e6d67d
67e7ca8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,12 @@ namespace Serilog.Settings.Configuration.Tests | |
{ | ||
public class ConfigurationSettingsTests | ||
{ | ||
static LoggerConfiguration ConfigFromJson(string jsonString) | ||
static LoggerConfiguration ConfigFromJson(string jsonString, string secondJsonSource = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could possibly make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And YAGNI... I can't think of a test scenario where |
||
{ | ||
var config = new ConfigurationBuilder().AddJsonString(jsonString).Build(); | ||
var builder = new ConfigurationBuilder().AddJsonString(jsonString); | ||
if (secondJsonSource != null) | ||
builder.AddJsonString(secondJsonSource); | ||
var config = builder.Build(); | ||
return new LoggerConfiguration() | ||
.ReadFrom.Configuration(config); | ||
} | ||
|
@@ -31,7 +34,7 @@ public void PropertyEnrichmentIsApplied() | |
} | ||
} | ||
}"; | ||
|
||
var log = ConfigFromJson(json) | ||
.WriteTo.Sink(new DelegatingSink(e => evt = e)) | ||
.CreateLogger(); | ||
|
@@ -114,7 +117,7 @@ public void AuditSinksAreConfigured() | |
|
||
var log = ConfigFromJson(json) | ||
.CreateLogger(); | ||
|
||
DummyRollingFileSink.Emitted.Clear(); | ||
DummyRollingFileAuditSink.Emitted.Clear(); | ||
|
||
|
@@ -227,7 +230,7 @@ public void LoggingLevelSwitchWithInvalidNameThrowsFormatException() | |
""LevelSwitches"": {""switchNameNotStartingWithDollar"" : ""Warning"" } | ||
} | ||
}"; | ||
|
||
var ex = Assert.Throws<FormatException>(() => ConfigFromJson(json)); | ||
|
||
Assert.Contains("\"switchNameNotStartingWithDollar\"", ex.Message); | ||
|
@@ -271,7 +274,7 @@ public void SettingMinimumLevelControlledByToAnUndeclaredSwitchThrows() | |
} | ||
} | ||
}"; | ||
|
||
var ex = Assert.Throws<InvalidOperationException>(() => | ||
ConfigFromJson(json) | ||
.CreateLogger()); | ||
|
@@ -332,7 +335,7 @@ public void ReferencingAnUndeclaredSwitchInSinkThrows() | |
}] | ||
} | ||
}"; | ||
|
||
var ex = Assert.Throws<InvalidOperationException>(() => | ||
ConfigFromJson(json) | ||
.CreateLogger()); | ||
|
@@ -544,8 +547,8 @@ public void WriteToSubLoggerWithLevelSwitchIsSupported() | |
} | ||
}] | ||
} | ||
}"; | ||
}"; | ||
|
||
var log = ConfigFromJson(json) | ||
.CreateLogger(); | ||
|
||
|
@@ -556,5 +559,43 @@ public void WriteToSubLoggerWithLevelSwitchIsSupported() | |
|
||
Assert.Equal(1, DummyRollingFileSink.Emitted.Count); | ||
} | ||
|
||
[Trait("Bugfix", "#103")] | ||
[Fact] | ||
public void InconsistentComplexVsScalarArgumentValuesThrowsIOE() | ||
{ | ||
var jsonDiscreteValue = @"{ | ||
""Serilog"": { | ||
""Using"": [""TestDummies""], | ||
""WriteTo"": [{ | ||
""Name"": ""DummyRollingFile"", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rolling file is deprecated, maybe example can start using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, I see its used in the rest of the test codebase here; prob leave it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thinking as well. |
||
""Args"": {""pathFormat"" : ""C:\\""} | ||
}] | ||
} | ||
}"; | ||
|
||
var jsonComplexValue = @"{ | ||
""Serilog"": { | ||
""Using"": [""TestDummies""], | ||
""WriteTo"": [{ | ||
""Name"": ""DummyRollingFile"", | ||
""Args"": {""pathFormat"" : { ""foo"" : ""bar"" } } | ||
}] | ||
} | ||
}"; | ||
|
||
// These will combine into a ConfigurationSection object that has both | ||
// Value == "C:\" and GetChildren() == List<string>. No configuration | ||
// extension matching this exists (in theory an "object" argument could | ||
// accept either value). ConfigurationReader should throw as soon as | ||
// the multiple values are recognized; it will never attempt to locate | ||
// a matching argument. | ||
|
||
var ex = Assert.Throws<InvalidOperationException>(() | ||
=> ConfigFromJson(jsonDiscreteValue, jsonComplexValue)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think one line would be consistent with the rest of the code. Earlier you suggested the split (I tend to split them myself). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant that the |
||
|
||
Assert.Contains("The value for the argument", ex.Message); | ||
Assert.Contains("'Serilog:WriteTo:0:Args:pathFormat'", ex.Message); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I keep thinking
ArgumentException
but I guess that's best reserved for actual method arguments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first inclination, too, but then I noticed IOE is used elsewhere in the code for similar "processing" errors.