Skip to content

Commit

Permalink
Merge pull request #367 from 0xced/valid-json
Browse files Browse the repository at this point in the history
Make all JSON strings valid in tests
  • Loading branch information
nblumhardt authored Mar 16, 2023
2 parents de58300 + b6fe2cf commit 79ecfe6
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Globalization;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using Serilog.Events;
Expand All @@ -16,17 +15,18 @@ public class ConfigurationReaderTests
public ConfigurationReaderTests()
{
_configurationReader = new ConfigurationReader(
JsonStringConfigSource.LoadSection("{ 'Serilog': { } }", "Serilog"),
JsonStringConfigSource.LoadSection("{ \"Serilog\": { } }", "Serilog"),
AssemblyFinder.ForSource(ConfigurationAssemblySource.UseLoadedAssemblies),
new ConfigurationReaderOptions());
}

[Fact]
public void WriteToSupportSimplifiedSyntax()
{
// language=json
var json = """
{
'WriteTo': [ 'LiterateConsole', 'DiagnosticTrace' ]
"WriteTo": [ "LiterateConsole", "DiagnosticTrace" ]
}
""";

Expand All @@ -42,10 +42,11 @@ public void WriteToSupportSimplifiedSyntax()
[Fact]
public void WriteToSupportExpandedSyntaxWithoutArgs()
{
// language=json
var json = """
{
'WriteTo': [ {
'Name': 'LiterateConsole'
"WriteTo": [ {
"Name": "LiterateConsole"
}]
}
""";
Expand All @@ -60,13 +61,14 @@ public void WriteToSupportExpandedSyntaxWithoutArgs()
[Fact]
public void WriteToSupportExpandedSyntaxWithArgs()
{
// language=json
var json = """
{
'WriteTo': [ {
'Name': 'LiterateConsole',
'Args': {
'outputTemplate': '{Message}'
},
"WriteTo": [ {
"Name": "LiterateConsole",
"Args": {
"outputTemplate": "{Message}"
}
}]
}
""";
Expand All @@ -88,28 +90,29 @@ public void WriteToSupportExpandedSyntaxWithArgs()
[Fact]
public void WriteToSupportMultipleSinksOfTheSameKind()
{
// language=json
var json = """
{
'WriteTo': [
"WriteTo": [
{
'Name': 'LiterateConsole',
'Args': {
'outputTemplate': '{Message}'
},
"Name": "LiterateConsole",
"Args": {
"outputTemplate": "{Message}"
}
},
'DiagnosticTrace'
"DiagnosticTrace"
],
'WriteTo:File1': {
'Name': 'File',
'Args': {
'outputTemplate': '{Message}'
},
"WriteTo:File1": {
"Name": "File",
"Args": {
"outputTemplate": "{Message}"
}
},
'WriteTo:File2': {
'Name': 'File',
'Args': {
'outputTemplate': '{Message}'
},
"WriteTo:File2": {
"Name": "File",
"Args": {
"outputTemplate": "{Message}"
}
}
}
""";
Expand All @@ -129,9 +132,10 @@ public void WriteToSupportMultipleSinksOfTheSameKind()
[Fact]
public void Enrich_SupportSimplifiedSyntax()
{
// language=json
var json = """
{
'Enrich': [ 'FromLogContext', 'WithMachineName', 'WithThreadId' ]
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
""";

Expand Down Expand Up @@ -274,7 +278,18 @@ public void MixedMinimumLevelCorrectOneIsEnabledOnLogger(IConfigurationRoot root
[Fact]
public void NoConfigurationRootUsedStillValid()
{
var section = JsonStringConfigSource.LoadSection("{ 'Nest': { 'Serilog': { 'MinimumLevel': 'Error' } } }", "Nest");
// language=json
var json = """
{
"Nest": {
"Serilog": {
"MinimumLevel": "Error"
}
}
}
""";

var section = JsonStringConfigSource.LoadSection(json, "Nest");
var reader = new ConfigurationReader(section.GetSection("Serilog"), AssemblyFinder.ForSource(ConfigurationAssemblySource.UseLoadedAssemblies), new ConfigurationReaderOptions(), section);
var loggerConfig = new LoggerConfiguration();

Expand Down
Loading

0 comments on commit 79ecfe6

Please sign in to comment.