diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs index 0c4fb3c6d0..31297b17ca 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs @@ -39,12 +39,6 @@ namespace Microsoft.AspNetCore.SignalR.Client private int _nextId = 0; - public event Func Connected - { - add { _connection.Connected += value; } - remove { _connection.Connected -= value; } - } - public event Func Closed { add { _connection.Closed += value; } diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs index 56643ed655..c01c8cdf05 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs @@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.Sockets.Client Task SendAsync(byte[] data, CancellationToken cancellationToken); Task DisposeAsync(); - event Func Connected; event Func Received; event Func Closed; diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs index 50a9fdba74..3d01f3e69d 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs @@ -45,7 +45,6 @@ namespace Microsoft.AspNetCore.Sockets.Client public IFeatureCollection Features { get; } = new FeatureCollection(); - public event Func Connected; public event Func Received; public event Func Closed; @@ -156,24 +155,6 @@ namespace Microsoft.AspNetCore.Sockets.Client if (Interlocked.CompareExchange(ref _connectionState, ConnectionState.Connected, ConnectionState.Connecting) == ConnectionState.Connecting) { - _ = _eventQueue.Enqueue(async () => - { - _logger.RaiseConnected(_connectionId); - - var connectedEventHandler = Connected; - if (connectedEventHandler != null) - { - try - { - await connectedEventHandler.Invoke(); - } - catch (Exception ex) - { - _logger.ExceptionThrownFromHandler(_connectionId, nameof(Connected), ex); - } - } - }); - _ = Input.Completion.ContinueWith(async t => { Interlocked.Exchange(ref _connectionState, ConnectionState.Disconnected); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs index 68673ae54e..20e99ffd0c 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs @@ -188,81 +188,6 @@ namespace Microsoft.AspNetCore.Sockets.Client.Tests Assert.Equal("Cannot send messages when the connection is not in the Connected state.", exception.Message); } - [Fact] - public async Task ConnectedEventRaisedWhenTheClientIsConnected() - { - var mockHttpHandler = new Mock(); - mockHttpHandler.Protected() - .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) - .Returns(async (request, cancellationToken) => - { - await Task.Yield(); - return request.Method == HttpMethod.Options - ? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse()) - : ResponseUtils.CreateResponse(HttpStatusCode.OK); - }); - - var connection = new HttpConnection(new Uri("http://fakeuri.org/"), TransportType.LongPolling, loggerFactory: null, httpMessageHandler: mockHttpHandler.Object); - - try - { - var connectedEventRaisedTcs = new TaskCompletionSource(); - connection.Connected += () => - { - connectedEventRaisedTcs.SetResult(null); - return Task.CompletedTask; - }; - - await connection.StartAsync(); - - await connectedEventRaisedTcs.Task.OrTimeout(); - } - finally - { - await connection.DisposeAsync(); - } - } - - [Fact] - public async Task ConnectedEventNotRaisedWhenTransportFailsToStart() - { - var mockHttpHandler = new Mock(); - mockHttpHandler.Protected() - .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) - .Returns(async (request, cancellationToken) => - { - await Task.Yield(); - return request.Method == HttpMethod.Options - ? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse()) - : ResponseUtils.CreateResponse(HttpStatusCode.OK); - }); - - var mockTransport = new Mock(); - mockTransport.Setup(t => t.StartAsync(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())) - .Returns(Task.FromException(new InvalidOperationException("Transport failed to start"))); - - var connection = new HttpConnection(new Uri("http://fakeuri.org/"), new TestTransportFactory(mockTransport.Object), loggerFactory: null, httpMessageHandler: mockHttpHandler.Object); - var connectedEventRaised = false; - - try - { - connection.Connected += () => - { - connectedEventRaised = true; - return Task.CompletedTask; - }; - - await Assert.ThrowsAsync( - async () => await connection.StartAsync()); - } - finally - { - await connection.DisposeAsync(); - } - - Assert.False(connectedEventRaised); - } - [Fact] public async Task ClosedEventRaisedWhenTheClientIsBeingStopped() { @@ -746,123 +671,6 @@ namespace Microsoft.AspNetCore.Sockets.Client.Tests } } - [Fact] - public async Task CanReceiveDataEvenIfUserThrowsInConnectedEvent() - { - var mockHttpHandler = new Mock(); - mockHttpHandler.Protected() - .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) - .Returns(async (request, cancellationToken) => - { - await Task.Yield(); - - var content = string.Empty; - - if (request.Method == HttpMethod.Get) - { - content = "42"; - } - - return request.Method == HttpMethod.Options - ? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse()) - : ResponseUtils.CreateResponse(HttpStatusCode.OK, content); - }); - - var connection = new HttpConnection(new Uri("http://fakeuri.org/"), TransportType.LongPolling, loggerFactory: null, httpMessageHandler: mockHttpHandler.Object); - try - { - connection.Connected += () => Task.FromException(new InvalidOperationException()); - - var receiveTcs = new TaskCompletionSource(); - connection.Received += data => - { - receiveTcs.TrySetResult(Encoding.UTF8.GetString(data)); - return Task.CompletedTask; - }; - - connection.Closed += e => - { - if (e != null) - { - receiveTcs.TrySetException(e); - } - else - { - receiveTcs.TrySetCanceled(); - } - return Task.CompletedTask; - }; - - await connection.StartAsync(); - - Assert.Equal("42", await receiveTcs.Task.OrTimeout()); - } - finally - { - await connection.DisposeAsync(); - } - } - - [Fact] - public async Task CanReceiveDataEvenIfUserThrowsSynchronouslyInConnectedEvent() - { - var mockHttpHandler = new Mock(); - mockHttpHandler.Protected() - .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) - .Returns(async (request, cancellationToken) => - { - await Task.Yield(); - - var content = string.Empty; - - if (request.Method == HttpMethod.Get) - { - content = "42"; - } - - return request.Method == HttpMethod.Options - ? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse()) - : ResponseUtils.CreateResponse(HttpStatusCode.OK, content); - }); - - var connection = new HttpConnection(new Uri("http://fakeuri.org/"), TransportType.LongPolling, loggerFactory: null, httpMessageHandler: mockHttpHandler.Object); - try - { - connection.Connected += () => - { - throw new InvalidOperationException(); - }; - - var receiveTcs = new TaskCompletionSource(); - connection.Received += data => - { - receiveTcs.TrySetResult(Encoding.UTF8.GetString(data)); - return Task.CompletedTask; - }; - - connection.Closed += e => - { - if (e != null) - { - receiveTcs.TrySetException(e); - } - else - { - receiveTcs.TrySetCanceled(); - } - return Task.CompletedTask; - }; - - await connection.StartAsync(); - - Assert.Equal("42", await receiveTcs.Task.OrTimeout()); - } - finally - { - await connection.DisposeAsync(); - } - } - [Fact] public async Task CanReceiveDataEvenIfExceptionThrownFromPreviousReceivedEvent() { diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs index 3a25409ee3..e3b0f554e2 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs @@ -55,30 +55,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests Assert.Same(exception, actualException); } - [Fact] - public async Task HubConnectionConnectedEventRaisedWhenTheClientIsConnected() - { - var connection = new TestConnection(); - var hubConnection = new HubConnection(connection, Mock.Of(), null); - try - { - var connectedEventRaisedTcs = new TaskCompletionSource(); - hubConnection.Connected += () => - { - connectedEventRaisedTcs.SetResult(null); - return Task.CompletedTask; - }; - - await hubConnection.StartAsync(); - - await connectedEventRaisedTcs.Task.OrTimeout(); - } - finally - { - await hubConnection.DisposeAsync(); - } - } - [Fact] public async Task ClosedEventRaisedWhenTheClientIsStopped() {