From 3d29b7854bb454f1e3e0a75af43b67d2f4d80e4d Mon Sep 17 00:00:00 2001 From: Alexis Nowikowski Date: Fri, 31 Mar 2017 18:44:57 +0200 Subject: [PATCH] =?UTF-8?q?Bugfix=20issue=20#355:=20Don't=20handle=20Invoc?= =?UTF-8?q?ation=20when=20no=20InvocationHandler=20=E2=80=A6=20(#356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Don't handle Invocation when no InvocationHandler is present --- .../HubConnection.cs | 1 + .../HubConnectionTests.cs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Microsoft.AspNetCore.SignalR.Client/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client/HubConnection.cs index c784250269..42f7d85e78 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client/HubConnection.cs @@ -212,6 +212,7 @@ namespace Microsoft.AspNetCore.SignalR.Client if (!_handlers.TryGetValue(invocationDescriptor.Method, out InvocationHandler handler)) { _logger.LogWarning("Failed to find handler for '{0}' method", invocationDescriptor.Method); + return; } // TODO: Return values diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs index 80dd61ba58..5ba4de89b2 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Client.Tests; using Microsoft.AspNetCore.SignalR.Tests.Common; +using Microsoft.AspNetCore.Sockets; using Microsoft.AspNetCore.Sockets.Client; using Microsoft.Extensions.Logging; using Moq; @@ -246,5 +247,29 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var thrown = await Assert.ThrowsAsync(exception.GetType(), async () => await invokeTask); Assert.Same(exception, thrown); } + + [Fact] + public async Task DoesNotThrowWhenClientMethodCalledButNoInvocationHandlerHasBeenSetUp() + { + var mockConnection = new Mock(); + + var invocationDescriptor = new InvocationDescriptor + { + Method = "NonExistingMethod123", + Arguments = new object[] { true, "arg2", 123 }, + Id = Guid.NewGuid().ToString() + }; + + var mockInvocationAdapter = new Mock(); + mockInvocationAdapter + .Setup(a => a.ReadMessageAsync(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(Task.FromResult((InvocationMessage)invocationDescriptor)); + + var hubConnection = new HubConnection(mockConnection.Object, mockInvocationAdapter.Object, null); + await hubConnection.StartAsync(Mock.Of()); + + mockConnection.Raise(c => c.Received += null, new object[] { new byte[] { }, MessageType.Text }); + mockInvocationAdapter.Verify(a => a.ReadMessageAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); + } } }