Skip to content

Commit

Permalink
changes based on feedback
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 861d35e commit b629371
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ public override void Destructure(

#pragma warning disable CA1062 // Validate arguments of public methods
var socketException = (SocketException)exception;
_ = SocketErrorDocumentationBySocketError.TryGetValue(socketException.SocketErrorCode, out var documentation);
propertiesBag.AddProperty(nameof(SocketException.SocketErrorCode), socketException.SocketErrorCode);
propertiesBag.AddProperty(nameof(SocketException.SocketErrorCode) + "Documentation", documentation ?? "Unknown SocketErrorCode value " + socketException.SocketErrorCode);
if (SocketErrorDocumentationBySocketError.TryGetValue(socketException.SocketErrorCode, out var documentation))
{
propertiesBag.AddProperty(nameof(SocketException.SocketErrorCode) + "Message", documentation);
}
#pragma warning restore CA1062 // Validate arguments of public methods
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,15 @@ public class SocketExceptionDestructurerTest
[Fact]
public void SocketException_SocketErrorCodeIsAttachedAsProperty()
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
var socketException = new SocketException((int)SocketError.HostUnreachable);
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
Test_LoggedExceptionContainsProperty(socketException, nameof(SocketException.SocketErrorCode), nameof(SocketError.HostUnreachable));
}

[Fact]
public void SocketException_SocketErrorCodeDocumentationIsAttachedAsProperty()
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
var socketException = new SocketException((int)SocketError.ConnectionRefused);
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
Test_LoggedExceptionContainsProperty(socketException, nameof(SocketException.SocketErrorCode) + "Documentation", "The remote host is actively refusing a connection.");
}

[Fact]
public void SocketException_SocketErrorCodeDocumentationWhenSocketErrorCodeUnknown()
{
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
var socketException = new SocketException(42);
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
Test_LoggedExceptionContainsProperty(socketException, nameof(SocketException.SocketErrorCode) + "Documentation", "Unknown SocketErrorCode value 42");
Test_LoggedExceptionContainsProperty(socketException, nameof(SocketException.SocketErrorCode) + "Message", "The remote host is actively refusing a connection.");
}
}
}

0 comments on commit b629371

Please sign in to comment.