public void Disconnect() { ConnectionWatchdog.Stop(); Reader.Close(); Writer.Close(); TcpClient.Close(); }
public async Task NotErrorOut_AfterWatchdogIsStopped() { var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(0.1)); Exception e = null; dog.Errored += (_, ex) => e = ex; dog.Start(tcpClientMock.Object); dog.Stop(); await Task.Delay(TimeSpan.FromSeconds(1)); Assert.Null(e); Assert.False(dog.Enabled); }
public async Task BeAbleToStartAgain_AndWorkCorrect() { var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(0.1)); Exception e = null; dog.Errored += (_, ex) => e = ex; dog.Start(tcpClientMock.Object); dog.Stop(); dog.Start(tcpClientMock.Object); tcpClientMock.Setup(x => x.SendMessage(It.IsAny <IAdminMessage>())) .Callback((IAdminMessage msg) => { var pingMsg = (AdminPingMessage)msg; var pongMsg = new AdminServerPongMessage(pingMsg.Argument); tcpClientMock.Object.SimulateMessageReceived(pongMsg); }); await Task.Delay(TimeSpan.FromSeconds(1)); Assert.Null(e); Assert.True(dog.Enabled); }