Merge branch 'rel/1.0.0-alpha1' into dev

This commit is contained in:
Pawel Kadluczka 2017-09-07 09:52:28 -07:00
commit 8ff6a4b624
8 changed files with 76 additions and 17 deletions

View File

@ -75,7 +75,7 @@ export class HubConnection {
}
private invokeClientMethod(invocationMessage: InvocationMessage) {
let method = this.methods.get(invocationMessage.target);
let method = this.methods.get(invocationMessage.target.toLowerCase());
if (method) {
method.apply(this, invocationMessage.arguments);
if (!invocationMessage.nonblocking) {
@ -202,7 +202,7 @@ export class HubConnection {
}
on(methodName: string, method: (...args: any[]) => void) {
this.methods.set(methodName, method);
this.methods.set(methodName.toLowerCase(), method);
}
set onClosed(callback: ConnectionClosed) {

View File

@ -2,7 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
export enum LogLevel {
Information = 0,
Trace = 0,
Information,
Warning,
Error,
None

View File

@ -54,7 +54,7 @@ export class WebSocketTransport implements ITransport {
};
webSocket.onmessage = (message: MessageEvent) => {
this.logger.log(LogLevel.Information, `(WebSockets transport) data received: ${message.data}`);
this.logger.log(LogLevel.Trace, `(WebSockets transport) data received: ${message.data}`);
if (this.onDataReceived) {
this.onDataReceived(message.data);
}
@ -118,7 +118,7 @@ export class ServerSentEventsTransport implements ITransport {
eventSource.onmessage = (e: MessageEvent) => {
if (this.onDataReceived) {
try {
this.logger.log(LogLevel.Information, `(SSE transport) data received: ${e.data}`);
this.logger.log(LogLevel.Trace, `(SSE transport) data received: ${e.data}`);
this.onDataReceived(e.data);
} catch (error) {
if (this.onClosed) {
@ -208,7 +208,7 @@ export class LongPollingTransport implements ITransport {
: pollXhr.response;
if (response) {
this.logger.log(LogLevel.Information, `(LongPolling transport) data received: ${response}`);
this.logger.log(LogLevel.Trace, `(LongPolling transport) data received: ${response}`);
this.onDataReceived(response);
}
else {

View File

@ -34,7 +34,7 @@ describe('connection', function () {
var message = "Hello World!";
var connection = new signalR.HttpConnection(ECHOENDPOINT_URL, {
transport: transportType,
logger: signalR.LogLevel.Information
logging: signalR.LogLevel.Trace
});
var received = "";

View File

@ -11,7 +11,13 @@ describe('hubConnection', function () {
it('can invoke server method and receive result', function (done) {
var message = "你好,世界!";
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, { transport: transportType }), { protocol: protocol});
var options = {
transport: transportType,
protocol: protocol,
logging: signalR.LogLevel.Trace
};
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
hubConnection.onClosed = function (error) {
expect(error).toBe(undefined);
done();
@ -32,7 +38,13 @@ describe('hubConnection', function () {
});
it('can stream server method and receive result', function (done) {
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, { transport: transportType }), { protocol: protocol});
var options = {
transport: transportType,
protocol: protocol,
logging: signalR.LogLevel.Trace
};
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
hubConnection.onClosed = function (error) {
expect(error).toBe(undefined);
@ -62,7 +74,12 @@ describe('hubConnection', function () {
it('rethrows an exception from the server when invoking', function (done) {
var errorMessage = "An error occurred.";
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, { transport: transportType }), { protocol: protocol});
var options = {
transport: transportType,
protocol: protocol,
logging: signalR.LogLevel.Trace
};
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
hubConnection.start().then(function () {
hubConnection.invoke('ThrowException', errorMessage).then(function () {
@ -83,8 +100,12 @@ describe('hubConnection', function () {
it('rethrows an exception from the server when streaming', function (done) {
var errorMessage = "An error occurred.";
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, { transport: transportType }), { protocol: protocol});
var options = {
transport: transportType,
protocol: protocol,
logging: signalR.LogLevel.Trace
};
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
hubConnection.start().then(function () {
hubConnection.stream('ThrowException', errorMessage).subscribe({
@ -106,11 +127,21 @@ describe('hubConnection', function () {
});
it('can receive server calls', function (done) {
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, { transport: transportType }), { protocol: protocol});
var options = {
transport: transportType,
protocol: protocol,
logging: signalR.LogLevel.Trace
};
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection(TESTHUBENDPOINT_URL, options), options);
var message = "你好 SignalR";
hubConnection.on("Message", function (msg) {
// client side method names are case insensitive
var methodName = 'message';
var idx = Math.floor(Math.random() * (methodName.length - 1));
methodName = methodName.substr(0, idx) + methodName[idx].toUpperCase() + methodName.substr(idx + 1);
hubConnection.on(methodName, function (msg) {
expect(msg).toBe(message);
done();
});
@ -134,7 +165,12 @@ describe('hubConnection', function () {
ServerSentEvents: "Error occurred"
};
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection('http://' + document.location.host + '/uncreatable', { transport: transportType }), { protocol: protocol});
var options = {
transport: transportType,
protocol: protocol,
logging: signalR.LogLevel.Trace
};
var hubConnection = new signalR.HubConnection(new signalR.HttpConnection('http://' + document.location.host + '/uncreatable', options), options);
hubConnection.onClosed = function (error) {
expect(error.message).toMatch(errorRegex[signalR.TransportType[transportType]]);

View File

@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.SignalR
{
public class HubOptions
{
public JsonSerializerSettings JsonSerializerSettings { get; set; }
public JsonSerializerSettings JsonSerializerSettings { get; set; } = new JsonSerializerSettings();
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Microsoft.CSharp;
namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
{

View File

@ -0,0 +1,23 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Xunit;
namespace Microsoft.AspNetCore.SignalR.Tests
{
public class SignalRDependencyInjectionExtensionsTests
{
[Fact]
public void JSonSerializerSettingsShouldNotBeNullInOptions()
{
var services = new ServiceCollection();
services.AddOptions();
services.AddSignalR();
var serviceProvider = services.BuildServiceProvider();
var hubOptions = serviceProvider.GetService<IOptions<HubOptions>>();
Assert.NotNull(hubOptions.Value.JsonSerializerSettings);
}
}
}