Fix AllProtocols with duplicates
This commit is contained in:
parent
ff5c200345
commit
4fb2dda133
|
|
@ -23,13 +23,12 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
||||||
_logger = logger ?? NullLogger<DefaultHubProtocolResolver>.Instance;
|
_logger = logger ?? NullLogger<DefaultHubProtocolResolver>.Instance;
|
||||||
_availableProtocols = new Dictionary<string, IHubProtocol>(StringComparer.OrdinalIgnoreCase);
|
_availableProtocols = new Dictionary<string, IHubProtocol>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
// We might get duplicates in _hubProtocols, but we're going to check it and overwrite in just a sec.
|
foreach (var protocol in availableProtocols)
|
||||||
_hubProtocols = availableProtocols.ToList();
|
|
||||||
foreach (var protocol in _hubProtocols)
|
|
||||||
{
|
{
|
||||||
Log.RegisteredSignalRProtocol(_logger, protocol.Name, protocol.GetType());
|
Log.RegisteredSignalRProtocol(_logger, protocol.Name, protocol.GetType());
|
||||||
_availableProtocols[protocol.Name] = protocol;
|
_availableProtocols[protocol.Name] = protocol;
|
||||||
}
|
}
|
||||||
|
_hubProtocols = _availableProtocols.Values.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IHubProtocol GetProtocol(string protocolName, IReadOnlyList<string> supportedProtocols)
|
public virtual IHubProtocol GetProtocol(string protocolName, IReadOnlyList<string> supportedProtocols)
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,22 @@ namespace Microsoft.AspNetCore.SignalR.Common.Protocol.Tests
|
||||||
Assert.Same(jsonProtocol2, resolvedProtocol);
|
Assert.Same(jsonProtocol2, resolvedProtocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AllProtocolsOnlyReturnsLatestOfSameType()
|
||||||
|
{
|
||||||
|
var jsonProtocol1 = new NewtonsoftJsonHubProtocol();
|
||||||
|
var jsonProtocol2 = new NewtonsoftJsonHubProtocol();
|
||||||
|
var resolver = new DefaultHubProtocolResolver(new[] {
|
||||||
|
jsonProtocol1,
|
||||||
|
jsonProtocol2
|
||||||
|
}, NullLogger<DefaultHubProtocolResolver>.Instance);
|
||||||
|
|
||||||
|
var hubProtocols = resolver.AllProtocols;
|
||||||
|
Assert.Equal(1, hubProtocols.Count);
|
||||||
|
|
||||||
|
Assert.Same(jsonProtocol2, hubProtocols[0]);
|
||||||
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> HubProtocolNames => HubProtocolHelpers.AllProtocols.Select(p => new object[] {p.Name});
|
public static IEnumerable<object[]> HubProtocolNames => HubProtocolHelpers.AllProtocols.Select(p => new object[] {p.Name});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue