From 185453908ffbe17b685b58e4483b97cff57bb74b Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 27 Mar 2018 10:25:00 -0700 Subject: [PATCH] Remove HubConnectionContext parameter from IHubProtocolResolver (#1735) --- .../HubConnectionContext.cs | 2 +- .../Internal/DefaultHubProtocolResolver.cs | 2 +- .../Internal/IHubProtocolResolver.cs | 2 +- .../DefaultHubProtocolResolverTests.cs | 28 ++++--------------- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs index 70a4ce9037..aa13f4cac8 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/HubConnectionContext.cs @@ -230,7 +230,7 @@ namespace Microsoft.AspNetCore.SignalR { if (HandshakeProtocol.TryParseRequestMessage(buffer, out var handshakeRequestMessage, out consumed, out examined)) { - Protocol = protocolResolver.GetProtocol(handshakeRequestMessage.Protocol, supportedProtocols, this); + Protocol = protocolResolver.GetProtocol(handshakeRequestMessage.Protocol, supportedProtocols); if (Protocol == null) { Log.HandshakeFailed(_logger, null); diff --git a/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs b/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs index 7129c0c286..a11c2d380e 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/Internal/DefaultHubProtocolResolver.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal } } - public IHubProtocol GetProtocol(string protocolName, IList supportedProtocols, HubConnectionContext connection) + public IHubProtocol GetProtocol(string protocolName, IList supportedProtocols) { protocolName = protocolName ?? throw new ArgumentNullException(nameof(protocolName)); diff --git a/src/Microsoft.AspNetCore.SignalR.Core/Internal/IHubProtocolResolver.cs b/src/Microsoft.AspNetCore.SignalR.Core/Internal/IHubProtocolResolver.cs index 8d45e69fc6..0141bf6a92 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/Internal/IHubProtocolResolver.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/Internal/IHubProtocolResolver.cs @@ -8,6 +8,6 @@ namespace Microsoft.AspNetCore.SignalR.Internal { public interface IHubProtocolResolver { - IHubProtocol GetProtocol(string protocolName, IList supportedProtocols, HubConnectionContext connection); + IHubProtocol GetProtocol(string protocolName, IList supportedProtocols); } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs index be08340a26..0284e1f630 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/Internal/DefaultHubProtocolResolverTests.cs @@ -28,52 +28,40 @@ namespace Microsoft.AspNetCore.SignalR.Common.Protocol.Tests [MemberData(nameof(HubProtocols))] public void DefaultHubProtocolResolverTestsCanCreateAllProtocols(IHubProtocol protocol) { - var connection = new Mock(); - connection.Setup(m => m.Features).Returns(new FeatureCollection()); - var mockConnection = new Mock(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance) { CallBase = true }; var resolver = new DefaultHubProtocolResolver(AllProtocols, NullLogger.Instance); Assert.IsType( protocol.GetType(), - resolver.GetProtocol(protocol.Name, AllProtocolNames, mockConnection.Object)); + resolver.GetProtocol(protocol.Name, AllProtocolNames)); } [Theory] [MemberData(nameof(HubProtocols))] public void DefaultHubProtocolResolverCreatesProtocolswhenSupoortedProtocolsIsNull(IHubProtocol protocol) { - var connection = new Mock(); - connection.Setup(m => m.Features).Returns(new FeatureCollection()); - var mockConnection = new Mock(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance) { CallBase = true }; List supportedProtocols = null; var resolver = new DefaultHubProtocolResolver(AllProtocols, NullLogger.Instance); Assert.IsType( protocol.GetType(), - resolver.GetProtocol(protocol.Name, supportedProtocols, mockConnection.Object)); + resolver.GetProtocol(protocol.Name, supportedProtocols)); } [Theory] [MemberData(nameof(HubProtocols))] public void DefaultHubProtocolResolverTestsCanCreateSupportedProtocols(IHubProtocol protocol) { - var connection = new Mock(); - connection.Setup(m => m.Features).Returns(new FeatureCollection()); - var mockConnection = new Mock(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance) { CallBase = true }; var supportedProtocols = new List { protocol.Name }; var resolver = new DefaultHubProtocolResolver(AllProtocols, NullLogger.Instance); Assert.IsType( protocol.GetType(), - resolver.GetProtocol(protocol.Name, supportedProtocols, mockConnection.Object)); + resolver.GetProtocol(protocol.Name, supportedProtocols)); } [Fact] public void DefaultHubProtocolResolverThrowsForNullProtocol() { - var connection = new Mock(); - connection.Setup(m => m.Features).Returns(new FeatureCollection()); - var mockConnection = new Mock(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance) { CallBase = true }; var resolver = new DefaultHubProtocolResolver(AllProtocols, NullLogger.Instance); var exception = Assert.Throws( - () => resolver.GetProtocol(null, AllProtocolNames, mockConnection.Object)); + () => resolver.GetProtocol(null, AllProtocolNames)); Assert.Equal("protocolName", exception.ParamName); } @@ -81,19 +69,13 @@ namespace Microsoft.AspNetCore.SignalR.Common.Protocol.Tests [Fact] public void DefaultHubProtocolResolverReturnsNullForNotSupportedProtocol() { - var connection = new Mock(); - connection.Setup(m => m.Features).Returns(new FeatureCollection()); - var mockConnection = new Mock(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance) { CallBase = true }; var resolver = new DefaultHubProtocolResolver(AllProtocols, NullLogger.Instance); - Assert.Null(resolver.GetProtocol("notARealProtocol", AllProtocolNames, mockConnection.Object)); + Assert.Null(resolver.GetProtocol("notARealProtocol", AllProtocolNames)); } [Fact] public void RegisteringMultipleHubProtocolsFails() { - var connection = new Mock(); - connection.Setup(m => m.Features).Returns(new FeatureCollection()); - var mockConnection = new Mock(connection.Object, TimeSpan.FromSeconds(30), NullLoggerFactory.Instance) { CallBase = true }; var exception = Assert.Throws(() => new DefaultHubProtocolResolver(new[] { new JsonHubProtocol(), new JsonHubProtocol()