public async Task Handle_InitializeMessage_True() { // arrange (WebSocketContext context, WebSocketMock socket) = WebSocketContextHelper.Create(); var handler = new ConnectionInitializeHandler(); var message = new GenericOperationMessage { Type = MessageTypes.Connection.Initialize }; // act await handler.HandleAsync( context, message, CancellationToken.None); // assert Assert.Collection(socket.Outgoing, t => { Assert.Equal(MessageTypes.Connection.Accept, t.Type); }, t => { Assert.Equal(MessageTypes.Connection.KeepAlive, t.Type); }); }
public async Task AfterTimeout_ReceiveKeepAlive() { // arrange var timeout = TimeSpan.FromMilliseconds(100); (WebSocketContext context, WebSocketMock socket) = WebSocketContextHelper.Create(); var keepAlive = new WebSocketKeepAlive( context, timeout, new CancellationTokenSource()); // act keepAlive.Start(); await Task.Delay(timeout.Add(TimeSpan.FromMilliseconds(500))); // assert Assert.True(socket.Outgoing.Any(t => t.Type.Equals(MessageTypes.Connection.KeepAlive))); }
public async Task Handle_TerminateMessage_True() { // arrange (WebSocketContext context, WebSocketMock socket) = WebSocketContextHelper.Create(); var handler = new ConnectionTerminateHandler(); var message = new GenericOperationMessage { Type = MessageTypes.Connection.Terminate }; // act await handler.HandleAsync( context, message, CancellationToken.None); // assert Assert.True(socket.Closed); }