forked from serilog/serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes serilog#1323 - respect explicit format specifiers even when JSO…
…N defaults are selected
- Loading branch information
1 parent
a1e9850
commit d953cee
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/Serilog.Tests/Rendering/MessageTemplateRendererTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
using Serilog.Rendering; | ||
using Xunit; | ||
|
||
namespace Serilog.Tests.Rendering | ||
{ | ||
public class MessageTemplateRendererTests | ||
{ | ||
readonly MessageTemplateParser _messageTemplateParser = new MessageTemplateParser(); | ||
|
||
[Theory] | ||
[InlineData("{Number}", null, "16")] | ||
[InlineData("{Number:X8}", null, "00000010")] | ||
[InlineData("{Number}", "j", "16")] | ||
[InlineData("{Number:X8}", "j", "00000010")] | ||
public void PropertyTokenFormatsAreApplied(string template, string appliedFormat, string expected) | ||
{ | ||
var eventTemplate = _messageTemplateParser.Parse(template); | ||
var properties = new Dictionary<string, LogEventPropertyValue>{["Number"] = new ScalarValue(16)}; | ||
|
||
var output = new StringWriter(); | ||
MessageTemplateRenderer.Render(eventTemplate, properties, output, appliedFormat, CultureInfo.InvariantCulture); | ||
|
||
Assert.Equal(expected, output.ToString()); | ||
} | ||
} | ||
} |