Skip to content

Commit

Permalink
added test for case when socket error code is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyson Williams authored and RehanSaeed committed Nov 3, 2020
1 parent b629371 commit 817a9ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Tests/Serilog.Exceptions.Test/Destructurers/LogJsonOutputUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public static void Test_LoggedExceptionContainsProperty(Exception exception, str
Assert_JObjectContainsPropertiesExceptionDetailsWithProperty(rootObject, propertyKey, propertyValue);
}

public static void Test_LoggedExceptionDoesNotContainProperty(Exception exception, string propertyKey)
{
var rootObject = LogAndDestructureException(exception);
Assert_JObjectContainsPropertiesExceptionDetailsWithoutProperty(rootObject, propertyKey);
}

public static JArray ExtractInnerExceptionsProperty(JObject jObject)
{
var exceptionDetailValue = ExtractExceptionDetails(jObject);
Expand Down Expand Up @@ -89,6 +95,19 @@ public static void Assert_ContainsPropertyWithValue(
}
}

public static void Assert_DoesNotContainProperty(
JObject jObject,
string propertyKey)
{
if (jObject is null)
{
throw new ArgumentNullException(nameof(jObject));
}

jObject.Properties().Should()
.NotContain(x => x.Name == propertyKey, $"property with name {propertyKey} was not expected");
}

public static JProperty ExtractProperty(JObject jObject, string propertyKey)
{
if (jObject is null)
Expand All @@ -110,6 +129,14 @@ public static void Assert_JObjectContainsPropertiesExceptionDetailsWithProperty(
Assert_ContainsPropertyWithValue(exceptionDetailValue, propertyKey, propertyValue);
}

public static void Assert_JObjectContainsPropertiesExceptionDetailsWithoutProperty(
JObject jObject,
string propertyKey)
{
var exceptionDetailValue = ExtractExceptionDetails(jObject);
Assert_DoesNotContainProperty(exceptionDetailValue, propertyKey);
}

internal class TestTextWriterSink : ILogEventSink
{
private readonly TextWriter textWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ public void SocketException_SocketErrorCodeDocumentationIsAttachedAsProperty()
var socketException = new SocketException((int)SocketError.ConnectionRefused);
Test_LoggedExceptionContainsProperty(socketException, nameof(SocketException.SocketErrorCode) + "Message", "The remote host is actively refusing a connection.");
}

[Fact]
public void SocketException_SocketErrorCodeDocumentationWhenSocketErrorCodeUnknown()
{
var socketException = new SocketException(42);
Test_LoggedExceptionDoesNotContainProperty(socketException, nameof(SocketException.SocketErrorCode) + "Message");
}
}
}

0 comments on commit 817a9ba

Please sign in to comment.