-
Notifications
You must be signed in to change notification settings - Fork 152
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 #402 from AArnott/fix400
Report argument deserialization failures more precisely
- Loading branch information
Showing
31 changed files
with
453 additions
and
20 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/StreamJsonRpc.Tests/Exceptions/RemoteInvocationExceptionTests.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,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using StreamJsonRpc; | ||
using StreamJsonRpc.Protocol; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
public class RemoteInvocationExceptionTests : TestBase | ||
{ | ||
private const string SomeMessage = "test message"; | ||
private static readonly Exception SomeInnerException = new Exception(); | ||
|
||
public RemoteInvocationExceptionTests(ITestOutputHelper logger) | ||
: base(logger) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Ctor_Message_Code_Data() | ||
{ | ||
var data = new CommonErrorData(); | ||
var ex = new RemoteInvocationException(SomeMessage, 123, data); | ||
Assert.Equal(SomeMessage, ex.Message); | ||
Assert.Equal(123, ex.ErrorCode); | ||
Assert.Same(data, ex.ErrorData); | ||
Assert.Null(ex.DeserializedErrorData); | ||
} | ||
|
||
[Fact] | ||
public void Ctor_Message_Code_Data_DeserializedData() | ||
{ | ||
var data = new CommonErrorData(); | ||
var deserializedData = new CommonErrorData(); | ||
var ex = new RemoteInvocationException(SomeMessage, 123, data, deserializedData); | ||
Assert.Equal(SomeMessage, ex.Message); | ||
Assert.Equal(123, ex.ErrorCode); | ||
Assert.Same(data, ex.ErrorData); | ||
Assert.Same(deserializedData, ex.DeserializedErrorData); | ||
} | ||
|
||
[Fact] | ||
public void Serializable() | ||
{ | ||
var data = new CommonErrorData(); | ||
var deserializedData = new CommonErrorData(); | ||
var original = new RemoteInvocationException(SomeMessage, 123, data, deserializedData); | ||
var deserialized = BinaryFormatterRoundtrip(original); | ||
Assert.Equal(original.Message, deserialized.Message); | ||
Assert.Equal(original.ErrorCode, deserialized.ErrorCode); | ||
Assert.Null(deserialized.ErrorData); | ||
Assert.Null(deserialized.DeserializedErrorData); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/StreamJsonRpc.Tests/Exceptions/RpcArgumentDeserializationExceptionTests.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,63 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using StreamJsonRpc; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
public class RpcArgumentDeserializationExceptionTests : TestBase | ||
{ | ||
private const string SomeMessage = "test message"; | ||
private static readonly Exception SomeInnerException = new Exception(); | ||
|
||
public RpcArgumentDeserializationExceptionTests(ITestOutputHelper logger) | ||
: base(logger) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Ctor_Message() | ||
{ | ||
var ex = new RpcArgumentDeserializationException(SomeMessage); | ||
Assert.Equal(SomeMessage, ex.Message); | ||
} | ||
|
||
[Fact] | ||
public void Ctor_Message_Exception() | ||
{ | ||
var ex = new RpcArgumentDeserializationException(SomeMessage, SomeInnerException); | ||
Assert.Equal(SomeMessage, ex.Message); | ||
Assert.Same(SomeInnerException, ex.InnerException); | ||
} | ||
|
||
[Fact] | ||
public void Ctor_WithDetails() | ||
{ | ||
var ex = new RpcArgumentDeserializationException("argName", 67856, typeof(RpcArgumentDeserializationExceptionTests), SomeInnerException); | ||
Assert.Equal("argName", ex.ArgumentName); | ||
Assert.Equal(67856, ex.ArgumentPosition); | ||
Assert.Equal(typeof(RpcArgumentDeserializationExceptionTests), ex.DeserializedType); | ||
Assert.Same(SomeInnerException, ex.InnerException); | ||
} | ||
|
||
[Fact] | ||
public void Serializable_WithPosition() | ||
{ | ||
var original = new RpcArgumentDeserializationException("argName", 67856, typeof(RpcArgumentDeserializationExceptionTests), SomeInnerException); | ||
var deserialized = BinaryFormatterRoundtrip(original); | ||
Assert.Equal(original.Message, deserialized.Message); | ||
Assert.Equal(original.ArgumentName, deserialized.ArgumentName); | ||
Assert.Equal(original.ArgumentPosition, deserialized.ArgumentPosition); | ||
} | ||
|
||
[Fact] | ||
public void Serializable_WithNoPosition() | ||
{ | ||
var original = new RpcArgumentDeserializationException("argName", argumentPosition: null, typeof(RpcArgumentDeserializationExceptionTests), SomeInnerException); | ||
var deserialized = BinaryFormatterRoundtrip(original); | ||
Assert.Equal(original.Message, deserialized.Message); | ||
Assert.Equal(original.ArgumentName, deserialized.ArgumentName); | ||
Assert.Equal(original.ArgumentPosition, deserialized.ArgumentPosition); | ||
} | ||
} |
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
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
Oops, something went wrong.