Detailed errors enabled for functional tests (#1822)

This commit is contained in:
BrennanConroy 2018-04-02 10:42:26 -07:00 committed by GitHub
parent e9d58154ec
commit 6640f14e35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 22 deletions

View File

@ -24,7 +24,10 @@ namespace FunctionalTests
public void ConfigureServices(IServiceCollection services)
{
services.AddConnections();
services.AddSignalR()
services.AddSignalR(options =>
{
options.EnableDetailedErrors = true;
})
.AddJsonProtocol(options =>
{
// we are running the same tests with JSON and MsgPack protocols and having

View File

@ -125,7 +125,7 @@ describe("hubConnection", () => {
});
it("rethrows an exception from the server when invoking", (done) => {
const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server.";
const errorMessage = "An unexpected error occurred invoking 'ThrowException' on the server. InvalidOperationException: An error occurred.";
const hubConnection = new HubConnection(TESTHUBENDPOINT_URL, {
logger: TestLogger.instance,
protocol,
@ -198,7 +198,7 @@ describe("hubConnection", () => {
});
it("rethrows an exception from the server when streaming", (done) => {
const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server.";
const errorMessage = "An unexpected error occurred invoking 'StreamThrowException' on the server. InvalidOperationException: An error occurred.";
const hubConnection = new HubConnection(TESTHUBENDPOINT_URL, {
logger: TestLogger.instance,
protocol,
@ -353,7 +353,7 @@ describe("hubConnection", () => {
});
hubConnection.onclose((error) => {
expect(error.message).toEqual("Server returned an error on close: Connection closed with an error.");
expect(error.message).toEqual("Server returned an error on close: Connection closed with an error. InvalidOperationException: Unable to resolve service for type 'System.Object' while attempting to activate 'FunctionalTests.UncreatableHub'.");
done();
});
hubConnection.start();

View File

@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
hasResult = false;
break;
default:
throw new FormatException("Invalid invocation result kind.");
throw new InvalidDataException("Invalid invocation result kind.");
}
return ApplyHeaders(headers, new CompletionMessage(invocationId, error, result, hasResult));
@ -231,7 +231,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
if (parameterTypes.Count != argumentCount)
{
throw new FormatException(
throw new InvalidDataException(
$"Invocation provides {argumentCount} argument(s) but target expects {parameterTypes.Count}.");
}
@ -247,7 +247,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
}
catch (Exception ex)
{
throw new FormatException("Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex);
throw new InvalidDataException("Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex);
}
}
@ -304,7 +304,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
WriteCloseMessage(closeMessage, packer);
break;
default:
throw new FormatException($"Unexpected message type: {message.GetType().Name}");
throw new InvalidDataException($"Unexpected message type: {message.GetType().Name}");
}
}
@ -435,7 +435,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
msgPackException = e;
}
throw new FormatException($"Reading '{field}' as Int32 failed.", msgPackException);
throw new InvalidDataException($"Reading '{field}' as Int32 failed.", msgPackException);
}
private static string ReadString(Unpacker unpacker, string field)
@ -460,7 +460,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
msgPackException = e;
}
throw new FormatException($"Reading '{field}' as String failed.", msgPackException);
throw new InvalidDataException($"Reading '{field}' as String failed.", msgPackException);
}
private static bool ReadBoolean(Unpacker unpacker, string field)
@ -478,7 +478,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
msgPackException = e;
}
throw new FormatException($"Reading '{field}' as Boolean failed.", msgPackException);
throw new InvalidDataException($"Reading '{field}' as Boolean failed.", msgPackException);
}
private static long ReadMapLength(Unpacker unpacker, string field)
@ -496,7 +496,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
msgPackException = e;
}
throw new FormatException($"Reading map length for '{field}' failed.", msgPackException);
throw new InvalidDataException($"Reading map length for '{field}' failed.", msgPackException);
}
private static long ReadArrayLength(Unpacker unpacker, string field)
@ -514,7 +514,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
msgPackException = e;
}
throw new FormatException($"Reading array length for '{field}' failed.", msgPackException);
throw new InvalidDataException($"Reading array length for '{field}' failed.", msgPackException);
}
private static object DeserializeObject(Unpacker unpacker, Type type, string field)
@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
msgPackException = ex;
}
throw new FormatException($"Deserializing object of the `{type.Name}` type for '{field}' failed.", msgPackException);
throw new InvalidDataException($"Deserializing object of the `{type.Name}` type for '{field}' failed.", msgPackException);
}
internal static SerializationContext CreateDefaultSerializationContext()

View File

@ -415,7 +415,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var channel = await connection.StreamAsChannelAsync<int>("StreamException").OrTimeout();
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
Assert.Equal("An unexpected error occurred invoking 'StreamException' on the server.", ex.Message);
Assert.Equal("An unexpected error occurred invoking 'StreamException' on the server. InvalidOperationException: Error occurred while streaming.", ex.Message);
}
catch (Exception ex)
{
@ -469,7 +469,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
await connection.StartAsync().OrTimeout();
var ex = await Assert.ThrowsAsync<HubException>(() => connection.InvokeAsync("Echo", "p1", 42)).OrTimeout();
Assert.Equal("Failed to invoke 'Echo' due to an error on the server.", ex.Message);
Assert.Equal("Failed to invoke 'Echo' due to an error on the server. InvalidDataException: Invocation provides 2 argument(s) but target expects 1.", ex.Message);
}
catch (Exception ex)
{
@ -553,7 +553,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var channel = await connection.StreamAsChannelAsync<int>("Stream", 42, 42);
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
Assert.Equal("Failed to invoke 'Stream' due to an error on the server.", ex.Message);
Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Invocation provides 2 argument(s) but target expects 1.", ex.Message);
}
catch (Exception ex)
{
@ -581,7 +581,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
var channel = await connection.StreamAsChannelAsync<int>("Stream", "xyz");
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
Assert.Equal("Failed to invoke 'Stream' due to an error on the server.", ex.Message);
Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex.Message);
}
catch (Exception ex)
{

View File

@ -20,7 +20,10 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR()
services.AddSignalR(options =>
{
options.EnableDetailedErrors = true;
})
.AddMessagePackProtocol();
services.AddAuthorization(options =>
{

View File

@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
var buffer = Frame(Pack(testData.Encoded));
var binder = new TestBinder(new[] { typeof(string) }, typeof(string));
var data = new ReadOnlySequence<byte>(buffer);
var exception = Assert.Throws<FormatException>(() => _hubProtocol.TryParseMessage(ref data, binder, out _));
var exception = Assert.Throws<InvalidDataException>(() => _hubProtocol.TryParseMessage(ref data, binder, out _));
Assert.Equal(testData.ErrorMessage, exception.Message);
}
@ -413,7 +413,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
var binder = new TestBinder(new[] { typeof(string) }, typeof(string));
var data = new ReadOnlySequence<byte>(buffer);
_hubProtocol.TryParseMessage(ref data, binder, out var message);
var exception = Assert.Throws<FormatException>(() => ((HubMethodInvocationMessage)message).Arguments);
var exception = Assert.Throws<InvalidDataException>(() => ((HubMethodInvocationMessage)message).Arguments);
Assert.Equal(testData.ErrorMessage, exception.Message);
}

View File

@ -12,7 +12,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests
public void ConfigureServices(IServiceCollection services)
{
services.AddConnections();
services.AddSignalR();
services.AddSignalR(options =>
{
options.EnableDetailedErrors = true;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)