public async Task Connect_websocketopens_but_handshake_times_out() { // arrange var mockSocket = new MockSocket { OpenedAction = handler => { Thread.Sleep(100); handler.Invoke(this, new EventArgs()); } }; SetupWebSocket(mockSocket); InstantiateFayeClient(); _fayeClient.HandshakeTimeout = 150.Milliseconds(); // act var result = await _fayeClient.InvokingAsync(t => t.Connect()) .ShouldThrow <HandshakeException>(); // assert result.Message .Should() .Be("Timed out at 150 milliseconds waiting for server to respond to handshake request."); }
public async Task Connect_websocketopens_but_handshake_fails() { // arrange var mockSocket = new MockSocket { OpenedAction = handler => { Thread.Sleep(100); handler.Invoke(this, new EventArgs()); }, MessageReceiveAction = gotThis => { Thread.Sleep(100); return(GetHandshakeResponse(successful: false, error: "something failed")); } }; SetupWebSocket(mockSocket); InstantiateFayeClient(); // act + assert var result = await _fayeClient.InvokingAsync(t => t.Connect()) .ShouldThrow <HandshakeException>(); result.Message .Should() .Be("Handshaking with server failed. Reason: something failed"); }
public async Task Connect_no_common_connection_types() { // arrange var mockSocket = new MockSocket { OpenedAction = handler => { Thread.Sleep(100); handler.Invoke(this, new EventArgs()); }, MessageReceiveAction = gotThisMsg => { Thread.Sleep(100); return(GetHandshakeResponse(connTypes: new List <string> { "someTypeWeDontSupport" })); } }; SetupWebSocket(mockSocket); InstantiateFayeClient(); // act + assert var exception = await _fayeClient.InvokingAsync(c => c.Connect()) .ShouldThrow <HandshakeException>(); var expectedError = "Handshaking with server failed. Reason: " + string.Format(FayeClient.CONNECTION_TYPE_ERROR_FORMAT, "'someTypeWeDontSupport'"); exception .Message .Should() .Be(expectedError); }