Beispiel #1
0
        public void TestConnectTimeoutClosesWebSocketIfAlive()
        {
            WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081");
            ITimer     timer     = A.Fake <ITimer>();
            IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatFailsConnectDueTimeout(timer);

            webSocketJetConnection.SetWebSocket(webSocket);
            webSocketJetConnection.ConnectTimer = timer;
            A.CallTo(() => webSocket.IsAlive).Returns(true);
            webSocketJetConnection.Connect(A.Dummy <Action <bool> >(), 1000.0);

            A.CallTo(() => webSocket.Close()).MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #2
0
        public void TestConnectTimeoutInvokesCompleteAction()
        {
            WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081");
            ITimer     timer     = A.Fake <ITimer>();
            IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatFailsConnectDueTimeout(timer);

            webSocketJetConnection.SetWebSocket(webSocket);
            webSocketJetConnection.ConnectTimer = timer;
            A.CallTo(() => webSocket.IsAlive).Returns(false);
            Action <bool> completed = A.Fake <Action <bool> >();

            webSocketJetConnection.Connect(completed, 10.0);

            A.CallTo(() => completed(false)).MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #3
0
        public void TestConnectTimeoutCallsTimer()
        {
            WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081");
            ITimer     timer     = A.Fake <ITimer>();
            IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatFailsConnectDueTimeout(timer);

            webSocketJetConnection.SetWebSocket(webSocket);
            webSocketJetConnection.ConnectTimer = timer;

            Action <bool> connectCallback = A.Fake <Action <bool> >();

            A.CallTo(() => connectCallback(false)).Invokes(() => {
                webSocket.OnOpen += Raise.WithEmpty();
            });

            webSocketJetConnection.Connect(connectCallback, 1234.56);

            AssertTimerCallsOnConnect(timer, 1234.56);
            A.CallTo(() => connectCallback(true)).MustNotHaveHappened();
            A.CallTo(() => connectCallback(false)).MustHaveHappened(Repeated.Exactly.Once);
        }