public void StartTest() { //Arrange var objKeepAliveTimer = Substitute.For <ITimer>(); var objPingTimer = Substitute.For <ITimer>(); //Act var obj = new KeepAliveMonitor(objKeepAliveTimer, objPingTimer); obj.Start(); //Assert objKeepAliveTimer.Received(1).Start(); objPingTimer.Received(1).Stop(); }
public async Task <bool> RunAsync(MqttConnectPacket connectPacket, IMqttChannelAdapter adapter) { if (connectPacket == null) { throw new ArgumentNullException(nameof(connectPacket)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } try { var cancellationTokenSource = new CancellationTokenSource(); _wasCleanDisconnect = false; _willMessage = connectPacket.WillMessage; _adapter = adapter; _cancellationTokenSource = cancellationTokenSource; PendingMessagesQueue.Start(adapter, cancellationTokenSource.Token); KeepAliveMonitor.Start(connectPacket.KeepAlivePeriod, cancellationTokenSource.Token); await ReceivePacketsAsync(adapter, cancellationTokenSource.Token).ConfigureAwait(false); } catch (OperationCanceledException) { } catch (MqttCommunicationException exception) { _logger.Warning <MqttClientSession>(exception, "Client '{0}': Communication exception while processing client packets.", ClientId); } catch (Exception exception) { _logger.Error <MqttClientSession>(exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId); } return(_wasCleanDisconnect); }