Adding IConnection interface
This commit is contained in:
parent
7a4746868a
commit
12c6a4b917
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
|||
public class HubConnection
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Connection _connection;
|
||||
private readonly IConnection _connection;
|
||||
private readonly IInvocationAdapter _adapter;
|
||||
private readonly HubBinder _binder;
|
||||
|
||||
|
|
@ -46,6 +46,10 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
|||
}
|
||||
|
||||
public HubConnection(Uri url, IInvocationAdapter adapter, ILoggerFactory loggerFactory)
|
||||
: this(new Connection(url, loggerFactory), adapter, loggerFactory)
|
||||
{ }
|
||||
|
||||
public HubConnection(IConnection connection, IInvocationAdapter adapter, ILoggerFactory loggerFactory)
|
||||
{
|
||||
// TODO: loggerFactory shouldn't be required
|
||||
if (loggerFactory == null)
|
||||
|
|
@ -53,8 +57,14 @@ namespace Microsoft.AspNetCore.SignalR.Client
|
|||
throw new ArgumentNullException(nameof(loggerFactory));
|
||||
}
|
||||
|
||||
if (connection == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(connection));
|
||||
}
|
||||
|
||||
_connection = connection;
|
||||
|
||||
_binder = new HubBinder(this);
|
||||
_connection = new Connection(url, loggerFactory);
|
||||
_adapter = adapter;
|
||||
_logger = loggerFactory.CreateLogger<HubConnection>();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
{
|
||||
public class Connection
|
||||
public class Connection: IConnection
|
||||
{
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
private readonly ILogger _logger;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
// 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;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
{
|
||||
public interface IConnection
|
||||
{
|
||||
Task StartAsync(ITransport transport, HttpClient httpClient);
|
||||
Task<bool> SendAsync(byte[] data, MessageType type, CancellationToken cancellationToken);
|
||||
Task DisposeAsync();
|
||||
|
||||
event Action Connected;
|
||||
event Action<byte[], MessageType> Received;
|
||||
event Action<Exception> Closed;
|
||||
}
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Sockets.Client
|
|||
{
|
||||
throw new ArgumentNullException(nameof(application));
|
||||
}
|
||||
|
||||
|
||||
_application = application;
|
||||
|
||||
await Connect(url);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
public void CannotCreateHubConnectionWithNullUrl()
|
||||
{
|
||||
var exception = Assert.Throws<ArgumentNullException>(
|
||||
() => new HubConnection(null, Mock.Of<IInvocationAdapter>(), Mock.Of<ILoggerFactory>()));
|
||||
() => new HubConnection((Uri)null, Mock.Of<IInvocationAdapter>(), Mock.Of<ILoggerFactory>()));
|
||||
Assert.Equal("url", exception.ParamName);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue