internal void DoWork(object state) { try { lock (_threadLock) { if (Connected) { if (_sendCompassCalibrationCommand && DateTimeFactory.Now > _takeOffTime.AddSeconds(5)) { _sendCompassCalibrationCommand = false; CommandWorker.SendCalibrateCompassCommand(); } if (CommWatchDog) { CommandWorker.SendResetWatchDogCommand(); } else if (Flying && DateTimeFactory.Now > _takeOffTime.AddSeconds(10)) { CommandWorker.SendProgressiveCommand(this); } CommandWorker.Flush(); } } } catch { Disconnect(); } }
public void GivenResultFromCommandFlush_Flush_SendsCommandToSocket() { // Arrange const string testCommand = "testCommand"; _mockCommandQueue.Setup(x => x.Flush()).Returns(testCommand); DateTime timeOfLastTransmission = DateTime.UtcNow.AddMilliseconds(-1); _target.TimeOfLastTransmission = timeOfLastTransmission; // Act _target.Flush(); // Assert _mockUdpSocket.Verify(x => x.Write(testCommand)); _target.TimeOfLastTransmission.Should().BeAfter(timeOfLastTransmission); }