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);
        }
        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);
        }
        public void ReceiveTelemetryMessageTest()
        {
            // arrange
            var telemetryMessage = CreateTelemetryMessage();

            var balloonModule = new WeatherBalloon.BalloonModule.BalloonModule();

            // act
            balloonModule.Receive(telemetryMessage);

            // verify
            balloonModule.Location.track.ShouldBe(telemetryMessage.track);
            [email protected](telemetryMessage.@long);
            balloonModule.Location.lat.ShouldBe(telemetryMessage.lat);
            balloonModule.Location.mode.ShouldBe(telemetryMessage.mode);
            balloonModule.Location.time.ShouldBe(telemetryMessage.time);
            balloonModule.Location.speed.ShouldBe(telemetryMessage.speed);
            balloonModule.Location.climb.ShouldBe(telemetryMessage.climb);
        }
Example #5
0
        /// <summary>
        /// Process input message from the Telemetry input message source.
        /// </summary>
        private static async Task <MessageResponse> ProcessTelemetry(Message message, object userContext)
        {
            await Task.Run(() =>
            {
                try
                {
                    var telemetryMessage = MessageHelper.ParseMessage <TelemetryMessage>(message);

                    balloonModule.Receive(telemetryMessage);
                    Logger.LogInfo("Telemetry Message Processed.");
                }
                catch (Exception ex)
                {
                    byte[] messageBytes  = message.GetBytes();
                    string messageString = Encoding.UTF8.GetString(messageBytes);

                    Logger.LogWarning("Invalid Telemetry message: " + messageString);
                    Logger.LogException(ex);
                }
            });

            return(MessageResponse.Completed);
        }