public void TestConnectSucceeds() { WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081"); ITimer timer = A.Dummy <ITimer>(); webSocketJetConnection.ConnectTimer = timer; IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatConnectsSuccessful(); webSocketJetConnection.SetWebSocket(webSocket); webSocketJetConnection.Connect(A.Dummy <Action <bool> >(), 1000.0); Assert.IsTrue(webSocketJetConnection.IsConnected); }
public void TestConnectCallsTimer() { WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081"); IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatConnectsSuccessful(); webSocketJetConnection.SetWebSocket(webSocket); ITimer timer = A.Fake <ITimer>(); webSocketJetConnection.ConnectTimer = timer; double timeoutMs = 4242.42; webSocketJetConnection.Connect(A.Dummy <Action <bool> >(), timeoutMs); AssertTimerCallsOnConnect(timer, timeoutMs); }
public void TestConnectInvokesCompletedAction() { WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081"); ITimer timer = A.Dummy <ITimer>(); webSocketJetConnection.ConnectTimer = timer; IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatConnectsSuccessful(); A.CallTo(() => webSocket.IsAlive).Returns(true); webSocketJetConnection.SetWebSocket(webSocket); Action <bool> completed = A.Fake <Action <bool> >(); webSocketJetConnection.Connect(completed, 1000.0); A.CallTo(() => completed(true)).MustHaveHappened(Repeated.Exactly.Once); }
public void TestConnectThrowsExceptionIfAlreadyConnected() { WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081"); ITimer timer = A.Dummy <ITimer>(); webSocketJetConnection.ConnectTimer = timer; IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatConnectsSuccessful(); webSocketJetConnection.SetWebSocket(webSocket); webSocketJetConnection.Connect(A.Dummy <Action <bool> >(), 1000.0); Assert.Throws <JetPeerException>(() => { //Second call. webSocketJetConnection.Connect(A.Dummy <Action <bool> >(), 1000.0); }); }