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()); + } } }