Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 72514f3

Browse files
authored
Removing the connected event (#989)
1 parent ba1c210 commit 72514f3

File tree

5 files changed

+0
-242
lines changed

5 files changed

+0
-242
lines changed

src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs

-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ public class HubConnection
3939

4040
private int _nextId = 0;
4141

42-
public event Func<Task> Connected
43-
{
44-
add { _connection.Connected += value; }
45-
remove { _connection.Connected -= value; }
46-
}
47-
4842
public event Func<Exception, Task> Closed
4943
{
5044
add { _connection.Closed += value; }

src/Microsoft.AspNetCore.Sockets.Abstractions/IConnection.cs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public interface IConnection
1414
Task SendAsync(byte[] data, CancellationToken cancellationToken);
1515
Task DisposeAsync();
1616

17-
event Func<Task> Connected;
1817
event Func<byte[], Task> Received;
1918
event Func<Exception, Task> Closed;
2019

src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs

-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class HttpConnection : IConnection
4545

4646
public IFeatureCollection Features { get; } = new FeatureCollection();
4747

48-
public event Func<Task> Connected;
4948
public event Func<byte[], Task> Received;
5049
public event Func<Exception, Task> Closed;
5150

@@ -156,24 +155,6 @@ private async Task StartAsyncInternal()
156155
if (Interlocked.CompareExchange(ref _connectionState, ConnectionState.Connected, ConnectionState.Connecting)
157156
== ConnectionState.Connecting)
158157
{
159-
_ = _eventQueue.Enqueue(async () =>
160-
{
161-
_logger.RaiseConnected(_connectionId);
162-
163-
var connectedEventHandler = Connected;
164-
if (connectedEventHandler != null)
165-
{
166-
try
167-
{
168-
await connectedEventHandler.Invoke();
169-
}
170-
catch (Exception ex)
171-
{
172-
_logger.ExceptionThrownFromHandler(_connectionId, nameof(Connected), ex);
173-
}
174-
}
175-
});
176-
177158
_ = Input.Completion.ContinueWith(async t =>
178159
{
179160
Interlocked.Exchange(ref _connectionState, ConnectionState.Disconnected);

test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.cs

-192
Original file line numberDiff line numberDiff line change
@@ -188,81 +188,6 @@ public async Task SendThrowsIfConnectionIsDisposed()
188188
Assert.Equal("Cannot send messages when the connection is not in the Connected state.", exception.Message);
189189
}
190190

191-
[Fact]
192-
public async Task ConnectedEventRaisedWhenTheClientIsConnected()
193-
{
194-
var mockHttpHandler = new Mock<HttpMessageHandler>();
195-
mockHttpHandler.Protected()
196-
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
197-
.Returns<HttpRequestMessage, CancellationToken>(async (request, cancellationToken) =>
198-
{
199-
await Task.Yield();
200-
return request.Method == HttpMethod.Options
201-
? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse())
202-
: ResponseUtils.CreateResponse(HttpStatusCode.OK);
203-
});
204-
205-
var connection = new HttpConnection(new Uri("http://fakeuri.org/"), TransportType.LongPolling, loggerFactory: null, httpMessageHandler: mockHttpHandler.Object);
206-
207-
try
208-
{
209-
var connectedEventRaisedTcs = new TaskCompletionSource<object>();
210-
connection.Connected += () =>
211-
{
212-
connectedEventRaisedTcs.SetResult(null);
213-
return Task.CompletedTask;
214-
};
215-
216-
await connection.StartAsync();
217-
218-
await connectedEventRaisedTcs.Task.OrTimeout();
219-
}
220-
finally
221-
{
222-
await connection.DisposeAsync();
223-
}
224-
}
225-
226-
[Fact]
227-
public async Task ConnectedEventNotRaisedWhenTransportFailsToStart()
228-
{
229-
var mockHttpHandler = new Mock<HttpMessageHandler>();
230-
mockHttpHandler.Protected()
231-
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
232-
.Returns<HttpRequestMessage, CancellationToken>(async (request, cancellationToken) =>
233-
{
234-
await Task.Yield();
235-
return request.Method == HttpMethod.Options
236-
? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse())
237-
: ResponseUtils.CreateResponse(HttpStatusCode.OK);
238-
});
239-
240-
var mockTransport = new Mock<ITransport>();
241-
mockTransport.Setup(t => t.StartAsync(It.IsAny<Uri>(), It.IsAny<Channel<byte[], SendMessage>>(), It.IsAny<TransferMode>(), It.IsAny<string>()))
242-
.Returns(Task.FromException(new InvalidOperationException("Transport failed to start")));
243-
244-
var connection = new HttpConnection(new Uri("http://fakeuri.org/"), new TestTransportFactory(mockTransport.Object), loggerFactory: null, httpMessageHandler: mockHttpHandler.Object);
245-
var connectedEventRaised = false;
246-
247-
try
248-
{
249-
connection.Connected += () =>
250-
{
251-
connectedEventRaised = true;
252-
return Task.CompletedTask;
253-
};
254-
255-
await Assert.ThrowsAsync<InvalidOperationException>(
256-
async () => await connection.StartAsync());
257-
}
258-
finally
259-
{
260-
await connection.DisposeAsync();
261-
}
262-
263-
Assert.False(connectedEventRaised);
264-
}
265-
266191
[Fact]
267192
public async Task ClosedEventRaisedWhenTheClientIsBeingStopped()
268193
{
@@ -746,123 +671,6 @@ public async Task CanReceiveData()
746671
}
747672
}
748673

749-
[Fact]
750-
public async Task CanReceiveDataEvenIfUserThrowsInConnectedEvent()
751-
{
752-
var mockHttpHandler = new Mock<HttpMessageHandler>();
753-
mockHttpHandler.Protected()
754-
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
755-
.Returns<HttpRequestMessage, CancellationToken>(async (request, cancellationToken) =>
756-
{
757-
await Task.Yield();
758-
759-
var content = string.Empty;
760-
761-
if (request.Method == HttpMethod.Get)
762-
{
763-
content = "42";
764-
}
765-
766-
return request.Method == HttpMethod.Options
767-
? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse())
768-
: ResponseUtils.CreateResponse(HttpStatusCode.OK, content);
769-
});
770-
771-
var connection = new HttpConnection(new Uri("http://fakeuri.org/"), TransportType.LongPolling, loggerFactory: null, httpMessageHandler: mockHttpHandler.Object);
772-
try
773-
{
774-
connection.Connected += () => Task.FromException(new InvalidOperationException());
775-
776-
var receiveTcs = new TaskCompletionSource<string>();
777-
connection.Received += data =>
778-
{
779-
receiveTcs.TrySetResult(Encoding.UTF8.GetString(data));
780-
return Task.CompletedTask;
781-
};
782-
783-
connection.Closed += e =>
784-
{
785-
if (e != null)
786-
{
787-
receiveTcs.TrySetException(e);
788-
}
789-
else
790-
{
791-
receiveTcs.TrySetCanceled();
792-
}
793-
return Task.CompletedTask;
794-
};
795-
796-
await connection.StartAsync();
797-
798-
Assert.Equal("42", await receiveTcs.Task.OrTimeout());
799-
}
800-
finally
801-
{
802-
await connection.DisposeAsync();
803-
}
804-
}
805-
806-
[Fact]
807-
public async Task CanReceiveDataEvenIfUserThrowsSynchronouslyInConnectedEvent()
808-
{
809-
var mockHttpHandler = new Mock<HttpMessageHandler>();
810-
mockHttpHandler.Protected()
811-
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())
812-
.Returns<HttpRequestMessage, CancellationToken>(async (request, cancellationToken) =>
813-
{
814-
await Task.Yield();
815-
816-
var content = string.Empty;
817-
818-
if (request.Method == HttpMethod.Get)
819-
{
820-
content = "42";
821-
}
822-
823-
return request.Method == HttpMethod.Options
824-
? ResponseUtils.CreateResponse(HttpStatusCode.OK, ResponseUtils.CreateNegotiationResponse())
825-
: ResponseUtils.CreateResponse(HttpStatusCode.OK, content);
826-
});
827-
828-
var connection = new HttpConnection(new Uri("http://fakeuri.org/"), TransportType.LongPolling, loggerFactory: null, httpMessageHandler: mockHttpHandler.Object);
829-
try
830-
{
831-
connection.Connected += () =>
832-
{
833-
throw new InvalidOperationException();
834-
};
835-
836-
var receiveTcs = new TaskCompletionSource<string>();
837-
connection.Received += data =>
838-
{
839-
receiveTcs.TrySetResult(Encoding.UTF8.GetString(data));
840-
return Task.CompletedTask;
841-
};
842-
843-
connection.Closed += e =>
844-
{
845-
if (e != null)
846-
{
847-
receiveTcs.TrySetException(e);
848-
}
849-
else
850-
{
851-
receiveTcs.TrySetCanceled();
852-
}
853-
return Task.CompletedTask;
854-
};
855-
856-
await connection.StartAsync();
857-
858-
Assert.Equal("42", await receiveTcs.Task.OrTimeout());
859-
}
860-
finally
861-
{
862-
await connection.DisposeAsync();
863-
}
864-
}
865-
866674
[Fact]
867675
public async Task CanReceiveDataEvenIfExceptionThrownFromPreviousReceivedEvent()
868676
{

test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs

-24
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,6 @@ public async Task InvokeThrowsIfSerializingMessageFails()
5555
Assert.Same(exception, actualException);
5656
}
5757

58-
[Fact]
59-
public async Task HubConnectionConnectedEventRaisedWhenTheClientIsConnected()
60-
{
61-
var connection = new TestConnection();
62-
var hubConnection = new HubConnection(connection, Mock.Of<IHubProtocol>(), null);
63-
try
64-
{
65-
var connectedEventRaisedTcs = new TaskCompletionSource<object>();
66-
hubConnection.Connected += () =>
67-
{
68-
connectedEventRaisedTcs.SetResult(null);
69-
return Task.CompletedTask;
70-
};
71-
72-
await hubConnection.StartAsync();
73-
74-
await connectedEventRaisedTcs.Task.OrTimeout();
75-
}
76-
finally
77-
{
78-
await hubConnection.DisposeAsync();
79-
}
80-
}
81-
8258
[Fact]
8359
public async Task ClosedEventRaisedWhenTheClientIsStopped()
8460
{

0 commit comments

Comments
 (0)