Bugfix issue #355: Don't handle Invocation when no InvocationHandler … (#356)

- Don't handle Invocation when no InvocationHandler is present
This commit is contained in:
Alexis Nowikowski 2017-03-31 18:44:57 +02:00 committed by David Fowler
parent f87e0234e2
commit 3d29b7854b
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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<IConnection>();
var invocationDescriptor = new InvocationDescriptor
{
Method = "NonExistingMethod123",
Arguments = new object[] { true, "arg2", 123 },
Id = Guid.NewGuid().ToString()
};
var mockInvocationAdapter = new Mock<IInvocationAdapter>();
mockInvocationAdapter
.Setup(a => a.ReadMessageAsync(It.IsAny<Stream>(), It.IsAny<IInvocationBinder>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult((InvocationMessage)invocationDescriptor));
var hubConnection = new HubConnection(mockConnection.Object, mockInvocationAdapter.Object, null);
await hubConnection.StartAsync(Mock.Of<ITransport>());
mockConnection.Raise(c => c.Received += null, new object[] { new byte[] { }, MessageType.Text });
mockInvocationAdapter.Verify(a => a.ReadMessageAsync(It.IsAny<Stream>(), It.IsAny<IInvocationBinder>(), It.IsAny<CancellationToken>()), Times.Once());
}
}
}