-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Represent Uri as string, not destructure it, closes #46
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 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
66 changes: 66 additions & 0 deletions
66
Tests/Serilog.Exceptions.Test/Destructurers/UriDestructurerTest.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,66 @@ | ||
using System; | ||
using System.Collections; | ||
using Serilog.Exceptions.Core; | ||
using Serilog.Exceptions.Destructurers; | ||
using Xunit; | ||
|
||
namespace Serilog.Exceptions.Test.Destructurers | ||
{ | ||
public class UriDestructurerTest | ||
{ | ||
private ReflectionBasedDestructurer destructurer; | ||
|
||
public UriDestructurerTest() | ||
{ | ||
this.destructurer = new ReflectionBasedDestructurer(); | ||
} | ||
|
||
[Fact] | ||
public void CanDestructureUriProperty() | ||
{ | ||
const string uriValue = "http://localhost/property"; | ||
var exception = new UriException("test", new Uri(uriValue)); | ||
|
||
var propertiesBag = new ExceptionPropertiesBag(exception); | ||
this.destructurer.Destructure(exception, propertiesBag, null); | ||
|
||
var properties = propertiesBag.GetResultDictionary(); | ||
var uriPropertyValue = properties[nameof(UriException.Uri)]; | ||
Assert.IsType<string>(uriPropertyValue); | ||
Assert.Equal(uriValue, uriPropertyValue); | ||
} | ||
|
||
[Fact] | ||
public void CanDestructureDataItem() | ||
{ | ||
const string uriValue = "http://localhost/data-item"; | ||
var exception = new Exception("test") | ||
{ | ||
Data = | ||
{ | ||
{"UriDataItem", new Uri(uriValue)} | ||
} | ||
}; | ||
|
||
var propertiesBag = new ExceptionPropertiesBag(exception); | ||
this.destructurer.Destructure(exception, propertiesBag, null); | ||
|
||
var properties = propertiesBag.GetResultDictionary(); | ||
var data = (IDictionary) properties[nameof(Exception.Data)]; | ||
var uriDataValue = data["UriDataItem"]; | ||
Assert.IsType<string>(uriDataValue); | ||
Assert.Equal(uriValue, uriDataValue); | ||
} | ||
|
||
public class UriException : Exception | ||
{ | ||
public Uri Uri { get; } | ||
|
||
public UriException(string message, Uri uri) : base(message) | ||
{ | ||
Uri = uri; | ||
} | ||
} | ||
|
||
} | ||
} |