-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from nblumhardt/capture-function
Add the `Inspect()` function
- Loading branch information
Showing
6 changed files
with
126 additions
and
26 deletions.
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
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
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
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
39 changes: 39 additions & 0 deletions
39
test/Serilog.Expressions.Tests/Expressions/Runtime/RuntimeOperatorsTests.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,39 @@ | ||
using System.Reflection; | ||
using Serilog.Events; | ||
using Serilog.Expressions.Runtime; | ||
using Serilog.Expressions.Tests.Support; | ||
using Xunit; | ||
|
||
namespace Serilog.Expressions.Tests.Expressions.Runtime; | ||
|
||
public class RuntimeOperatorsTests | ||
{ | ||
[Fact] | ||
public void InspectReadsPublicPropertiesFromScalarValue() | ||
{ | ||
var message = Some.String(); | ||
var ex = new DivideByZeroException(message); | ||
var scalar = new ScalarValue(ex); | ||
var inspected = RuntimeOperators.Inspect(scalar); | ||
var structure = Assert.IsType<StructureValue>(inspected); | ||
var asProperties = structure.Properties.ToDictionary(p => p.Name, p => p.Value); | ||
Assert.Contains("Message", asProperties); | ||
Assert.Contains("StackTrace", asProperties); | ||
var messageResult = Assert.IsType<ScalarValue>(asProperties["Message"]); | ||
Assert.Equal(message, messageResult.Value); | ||
} | ||
|
||
[Fact] | ||
public void DeepInspectionReadsSubproperties() | ||
{ | ||
var innerMessage = Some.String(); | ||
var inner = new DivideByZeroException(innerMessage); | ||
var ex = new TargetInvocationException(inner); | ||
var scalar = new ScalarValue(ex); | ||
var inspected = RuntimeOperators.Inspect(scalar, deep: new ScalarValue(true)); | ||
var structure = Assert.IsType<StructureValue>(inspected); | ||
var innerStructure = Assert.IsType<StructureValue>(structure.Properties.Single(p => p.Name == "InnerException").Value); | ||
var innerMessageValue = Assert.IsType<ScalarValue>(innerStructure.Properties.Single(p => p.Name == "Message").Value); | ||
Assert.Equal(innerMessage, innerMessageValue.Value); | ||
} | ||
} |
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