// 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(); connectionBuilder.WithHubProtocol(hubProtocol); Assert.Same(hubProtocol, connectionBuilder.GetHubProtocol()); } [Fact] public void WithJsonProtocolRegistersJsonProtocol() { var connectionBuilder = new HubConnectionBuilder(); connectionBuilder.WithJsonProtocol(); Assert.IsType(connectionBuilder.GetHubProtocol()); } [Fact] public void WithMessagePackProtocolRegistersMessagePackProtocol() { var connectionBuilder = new HubConnectionBuilder(); connectionBuilder.WithMessagePackProtocol(); Assert.IsType(connectionBuilder.GetHubProtocol()); } [Fact] public void WithLoggerRegistersGivenLogger() { var connectionBuilder = new HubConnectionBuilder(); var loggerFactory = Mock.Of(); connectionBuilder.WithLogger(loggerFactory); Assert.Same(loggerFactory, connectionBuilder.GetLoggerFactory()); } [Fact] public void WithConsoleLoggerRegistersConsoleLogger() { var connectionBuilder = new HubConnectionBuilder(); var mockLoggerFactory = new Mock(); connectionBuilder.WithConsoleLogger(mockLoggerFactory.Object); mockLoggerFactory.Verify(f => f.AddProvider(It.IsAny()), Times.Once); } [Fact] public void WithMsgHandlerRegistersGivenMessageHandler() { var connectionBuilder = new HubConnectionBuilder(); var msgHandler = Mock.Of(); 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()); } } }