Fixing a bug where adding protocol with build would have no effect
This commit is contained in:
parent
abd669849d
commit
35683fb2b8
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
||||||
|
|
||||||
public static IHubProtocol GetHubProtocol(this IHubConnectionBuilder hubConnectionBuilder)
|
public static IHubProtocol GetHubProtocol(this IHubConnectionBuilder hubConnectionBuilder)
|
||||||
{
|
{
|
||||||
hubConnectionBuilder.TryGetSetting<IHubProtocol>(HubConnectionBuilderDefaults.LoggerFactoryKey, out var hubProtocol);
|
hubConnectionBuilder.TryGetSetting<IHubProtocol>(HubConnectionBuilderDefaults.HubProtocolKey, out var hubProtocol);
|
||||||
return hubProtocol;
|
return hubProtocol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Net.Http;
|
||||||
|
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||||
|
using Microsoft.AspNetCore.Sockets;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Logging.Console;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
|
{
|
||||||
|
public class HubConnectionBuilderExtensionsTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void WithHubProtocolRegistersGivenProtocol()
|
||||||
|
{
|
||||||
|
var connectionBuilder = new HubConnectionBuilder();
|
||||||
|
var hubProtocol = Mock.Of<IHubProtocol>();
|
||||||
|
connectionBuilder.WithHubProtocol(hubProtocol);
|
||||||
|
Assert.Same(hubProtocol, connectionBuilder.GetHubProtocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithJsonProtocolRegistersJsonProtocol()
|
||||||
|
{
|
||||||
|
var connectionBuilder = new HubConnectionBuilder();
|
||||||
|
connectionBuilder.WithJsonProtocol();
|
||||||
|
Assert.IsType<JsonHubProtocol>(connectionBuilder.GetHubProtocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithMessagePackProtocolRegistersMessagePackProtocol()
|
||||||
|
{
|
||||||
|
var connectionBuilder = new HubConnectionBuilder();
|
||||||
|
connectionBuilder.WithMessagePackProtocol();
|
||||||
|
Assert.IsType<MessagePackHubProtocol>(connectionBuilder.GetHubProtocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithLoggerRegistersGivenLogger()
|
||||||
|
{
|
||||||
|
var connectionBuilder = new HubConnectionBuilder();
|
||||||
|
var loggerFactory = Mock.Of<ILoggerFactory>();
|
||||||
|
connectionBuilder.WithLogger(loggerFactory);
|
||||||
|
Assert.Same(loggerFactory, connectionBuilder.GetLoggerFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithConsoleLoggerRegistersConsoleLogger()
|
||||||
|
{
|
||||||
|
var connectionBuilder = new HubConnectionBuilder();
|
||||||
|
var mockLoggerFactory = new Mock<ILoggerFactory>();
|
||||||
|
connectionBuilder.WithConsoleLogger(mockLoggerFactory.Object);
|
||||||
|
mockLoggerFactory.Verify(f => f.AddProvider(It.IsAny<ConsoleLoggerProvider>()), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WithMsgHandlerRegistersGivenMessageHandler()
|
||||||
|
{
|
||||||
|
var connectionBuilder = new HubConnectionBuilder();
|
||||||
|
var msgHandler = Mock.Of<HttpMessageHandler>();
|
||||||
|
connectionBuilder.WithMessageHandler(msgHandler);
|
||||||
|
Assert.Same(msgHandler, connectionBuilder.GetMessageHandler());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(TransportType.All)]
|
||||||
|
[InlineData(TransportType.WebSockets)]
|
||||||
|
[InlineData(TransportType.ServerSentEvents)]
|
||||||
|
[InlineData(TransportType.LongPolling)]
|
||||||
|
public void WithTransportTypeRegistersGivenTransportType(TransportType transportType)
|
||||||
|
{
|
||||||
|
var connectionBuilder = new HubConnectionBuilder();
|
||||||
|
connectionBuilder.WithTransportType(transportType);
|
||||||
|
Assert.Equal(transportType, connectionBuilder.GetTransportType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue