public void BalloonLandedDetection(BalloonState initialState, double altitude, BalloonState expectedState) { // arrange var fakeModuleClient = new FakeModuleClient(); var telemetryMessage = CreateTelemetryMessage(); // set gps to indicate rising balloon state telemetryMessage.alt = altitude; var balloonModule = new WeatherBalloon.BalloonModule.BalloonModule(); balloonModule.BalloonState = initialState; // act balloonModule.Receive(telemetryMessage); var task = balloonModule.TransmitBalloonMessage(fakeModuleClient); // verify task.Result.ShouldBe(true); // Sent a Balloon message? fakeModuleClient.SentMessages.Count.ShouldBe(1); // Correct message? var rawMessage = fakeModuleClient.SentMessages[0].Item2; var balloonMessage = MessageHelper.ParseMessage <BalloonMessage>(rawMessage); balloonMessage.State.ShouldBe(expectedState); }
public void BalloonFallingStateDetection(double climb, double altitude, BalloonState expectedState) { // arrange var fakeModuleClient = new FakeModuleClient(); var telemetryMessage = CreateTelemetryMessage(); // set gps to indicate rising balloon state telemetryMessage.climb = climb; telemetryMessage.alt = altitude; var balloonModule = new WeatherBalloon.BalloonModule.BalloonModule(); // set the balloon state to Rising, that's the only transition to Falling. balloonModule.BalloonState = BalloonState.Rising; // act balloonModule.Receive(telemetryMessage); var task = balloonModule.TransmitBalloonMessage(fakeModuleClient); // verify task.Result.ShouldBe(true); // Sent a Balloon message? fakeModuleClient.SentMessages.Count.ShouldBe(1); // Sent on correct output? fakeModuleClient.SentMessages[0].Item1.ShouldBe(WeatherBalloon.BalloonModule.BalloonModule.BalloonOutputName); // Correct message? var rawMessage = fakeModuleClient.SentMessages[0].Item2; var balloonMessage = MessageHelper.ParseMessage <BalloonMessage>(rawMessage); // balloon location balloonMessage.Location.track.ShouldBe(telemetryMessage.track); [email protected](telemetryMessage.@long); balloonMessage.Location.lat.ShouldBe(telemetryMessage.lat); balloonMessage.Location.mode.ShouldBe(telemetryMessage.mode); balloonMessage.Location.time.ShouldBe(telemetryMessage.time); balloonMessage.Location.speed.ShouldBe(telemetryMessage.speed); balloonMessage.Location.climb.ShouldBe(telemetryMessage.climb); balloonMessage.Temperature.ShouldBe(telemetryMessage.temp); balloonMessage.Pressure.ShouldBe(telemetryMessage.pressure); balloonMessage.Humidity.ShouldBe(telemetryMessage.humidity); if (expectedState == BalloonState.Rising) { balloonMessage.AveAscent.ShouldBe(telemetryMessage.climb); balloonMessage.AveDescent.ShouldBe(0.0); } else if (expectedState == BalloonState.Falling) { balloonMessage.AveAscent.ShouldBe(0.0); balloonMessage.AveDescent.ShouldBe(telemetryMessage.climb); } balloonMessage.State.ShouldBe(expectedState); }
private static void TransmitTimerCallback(object state) { if (moduleClient == null) { Logger.LogFatalError("Invalid Module client in Transmit Timer."); return; } balloonModule.TransmitBalloonMessage(moduleClient).Wait(); }
public void TransmitError() { // arrange var fakeModuleClient = A.Fake <IModuleClient>(); A.CallTo(fakeModuleClient).Throws(new Exception("Fake exception generated for testing")); var telemetryMessage = CreateTelemetryMessage(); var balloonModule = new WeatherBalloon.BalloonModule.BalloonModule(); // act balloonModule.Receive(telemetryMessage); var task = balloonModule.TransmitBalloonMessage(fakeModuleClient); // verify task.Result.ShouldBe(false); }