Beispiel #1
0
        public void ProximityGadgetAircraftJson_ToModel_Returns_The_Closest_Aircraft()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var originLatitude  = worksheet.NDouble("GadgetLat");
            var originLongitude = worksheet.NDouble("GadgetLng");

            var aircraft = CreateAircraft(2);

            for (int i = 1; i <= 2; ++i)
            {
                aircraft[i - 1].Callsign  = i.ToString();
                aircraft[i - 1].Latitude  = worksheet.NFloat(String.Format("AC{0}Lat", i));
                aircraft[i - 1].Longitude = worksheet.NFloat(String.Format("AC{0}Lng", i));
            }

            var model = ProximityGadgetAircraftJson.ToModel(aircraft, originLatitude, originLongitude);

            var closestCallsign = worksheet.String("Closest");

            if (closestCallsign == null)
            {
                Assert.IsNull(model.ClosestAircraft);
            }
            else
            {
                Assert.AreEqual(closestCallsign, model.ClosestAircraft.Callsign);
            }
        }
        public void BaseStationMessageTranslator_Translate_Translates_Messages_Correctly()
        {
            ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext);

            BaseStationMessage translated = _Implementation.Translate(worksheet.String("Text"), 123);

            Assert.AreEqual(Enum.Parse(typeof(BaseStationMessageType), worksheet.String("MessageType")), translated.MessageType);
            Assert.AreEqual(Enum.Parse(typeof(BaseStationTransmissionType), worksheet.String("TransmissionType")), translated.TransmissionType);
            Assert.AreEqual(Enum.Parse(typeof(BaseStationStatusCode), worksheet.String("StatusCode")), translated.StatusCode);
            Assert.AreEqual(worksheet.Int("SessionId"), translated.SessionId);
            Assert.AreEqual(worksheet.Int("AircraftId"), translated.AircraftId);
            Assert.AreEqual(worksheet.String("Icao24"), translated.Icao24);
            Assert.AreEqual(worksheet.Int("FlightId"), translated.FlightId);
            Assert.AreEqual(worksheet.DateTime("MessageGenerated"), translated.MessageGenerated);
            Assert.AreEqual(worksheet.DateTime("MessageLogged"), translated.MessageLogged);
            Assert.AreEqual(worksheet.String("Callsign"), translated.Callsign);
            Assert.AreEqual(worksheet.NFloat("Altitude"), translated.Altitude);
            Assert.AreEqual(worksheet.NFloat("GroundSpeed"), translated.GroundSpeed);
            Assert.AreEqual(worksheet.NFloat("Track"), translated.Track);
            Assert.AreEqual(worksheet.NDouble("Latitude"), translated.Latitude);
            Assert.AreEqual(worksheet.NDouble("Longitude"), translated.Longitude);
            Assert.AreEqual(worksheet.NFloat("VerticalRate"), translated.VerticalRate);
            Assert.AreEqual(worksheet.NInt("Squawk"), translated.Squawk);
            Assert.AreEqual(worksheet.NBool("SquawkHasChanged"), translated.SquawkHasChanged);
            Assert.AreEqual(worksheet.NBool("Emergency"), translated.Emergency);
            Assert.AreEqual(worksheet.NBool("IdentActive"), translated.IdentActive);
            Assert.AreEqual(worksheet.NBool("OnGround"), translated.OnGround);
            Assert.AreEqual(worksheet.Bool("IsMlat"), translated.IsMlat);
        }
Beispiel #3
0
        private void Do_BaseStationMessage_ToBaseStationString_Builds_Valid_BaseStation_Messages_From_A_BaseStationMessage_Object()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            _Implementation.MessageType      = worksheet.ParseEnum <BaseStationMessageType>("MessageType");
            _Implementation.TransmissionType = worksheet.ParseEnum <BaseStationTransmissionType>("TransmissionType");
            _Implementation.StatusCode       = worksheet.ParseEnum <BaseStationStatusCode>("StatusCode");
            _Implementation.SessionId        = worksheet.Int("SessionId");
            _Implementation.AircraftId       = worksheet.Int("AircraftId");
            _Implementation.Icao24           = worksheet.String("Icao24");
            _Implementation.FlightId         = worksheet.Int("FlightId");
            _Implementation.MessageGenerated = worksheet.DateTime("MessageGenerated");
            _Implementation.MessageLogged    = worksheet.DateTime("MessageLogged");
            _Implementation.Callsign         = worksheet.String("Callsign");
            _Implementation.Altitude         = worksheet.NInt("Altitude");
            _Implementation.GroundSpeed      = worksheet.NFloat("GroundSpeed");
            _Implementation.Track            = worksheet.NFloat("Track");
            _Implementation.Latitude         = worksheet.NDouble("Latitude");
            _Implementation.Longitude        = worksheet.NDouble("Longitude");
            _Implementation.VerticalRate     = worksheet.NInt("VerticalRate");
            _Implementation.Squawk           = worksheet.NInt("Squawk");
            _Implementation.SquawkHasChanged = worksheet.NBool("SquawkHasChanged");
            _Implementation.Emergency        = worksheet.NBool("Emergency");
            _Implementation.IdentActive      = worksheet.NBool("IdentActive");
            _Implementation.OnGround         = worksheet.NBool("OnGround");

            Assert.AreEqual(worksheet.String("Text"), _Implementation.ToBaseStationString());
        }
        public void GreatCircleMaths_Distance_Calculates_Correct_Distances()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var startLatitude = worksheet.NDouble("StartLatitude");
            var startLongitude = worksheet.NDouble("StartLongitude");
            var endLatitude = worksheet.NDouble("EndLatitude");
            var endLongitude = worksheet.NDouble("EndLongitude");
            var expected = worksheet.NDouble("Distance");

            var actual = GreatCircleMaths.Distance(startLatitude, startLongitude, endLatitude, endLongitude);

            if(expected == null) Assert.IsNull(actual);
            else                 Assert.AreEqual((double)expected, (double)actual, 0.0001);
        }
        public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly_For_Non_UK_Cultures()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            foreach (var culture in new string[] { "en-US", "de-DE", "fr-FR", "ru-RU" })
            {
                using (var cultureSwitcher = new CultureSwitcher(culture)) {
                    TestCleanup();
                    TestInitialise();

                    var obj = new ValueTypes()
                    {
                        BoolValue        = worksheet.Bool("BoolValue"),
                        UnusedBool       = worksheet.Bool("UnusedBool"),
                        NullableBool     = worksheet.NBool("NullableBool"),
                        Int              = worksheet.Int("Int"),
                        NullableInt      = worksheet.NInt("NullableInt"),
                        Long             = worksheet.Long("Long"),
                        NullableLong     = worksheet.NLong("NullableLong"),
                        Float            = worksheet.Float("Float"),
                        NullableFloat    = worksheet.NFloat("NullableFloat"),
                        Double           = worksheet.Double("Double"),
                        NullableDouble   = worksheet.NDouble("NullableDouble"),
                        DateTime         = worksheet.DateTime("DateTime"),
                        NullableDateTime = worksheet.NDateTime("NullableDateTime"),
                    };

                    _JsonSerialiser.Initialise(typeof(ValueTypes));
                    _JsonSerialiser.WriteObject(_Stream, obj);

                    var message = String.Format("when culture is {0}", culture);
                    Assert.AreEqual(worksheet.EString("Json"), GetJson(), message);
                }
            }
        }
        public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var obj = new ValueTypes()
            {
                BoolValue        = worksheet.Bool("BoolValue"),
                UnusedBool       = worksheet.Bool("UnusedBool"),
                NullableBool     = worksheet.NBool("NullableBool"),
                Int              = worksheet.Int("Int"),
                NullableInt      = worksheet.NInt("NullableInt"),
                Long             = worksheet.Long("Long"),
                NullableLong     = worksheet.NLong("NullableLong"),
                Float            = worksheet.Float("Float"),
                NullableFloat    = worksheet.NFloat("NullableFloat"),
                Double           = worksheet.Double("Double"),
                NullableDouble   = worksheet.NDouble("NullableDouble"),
                DateTime         = worksheet.DateTime("DateTime"),
                NullableDateTime = worksheet.NDateTime("NullableDateTime"),
            };

            _JsonSerialiser.Initialise(typeof(ValueTypes));
            _JsonSerialiser.WriteObject(_Stream, obj);

            Assert.AreEqual(worksheet.EString("Json"), GetJson());
        }
Beispiel #7
0
        public void PolarPlotter_AddCoordinate_Adds_Plot_To_All_Applicable_Slices()
        {
            var worksheet = new ExcelWorksheetData(TestContext);
            var comment   = worksheet.String("Comments");

            //if(comment != "comment here") return;

            StandardInitialise();

            for (var i = 1; i <= 2; ++i)
            {
                var altitude  = worksheet.NInt(String.Format("Altitude{0}", i));
                var latitude  = worksheet.NDouble(String.Format("Latitude{0}", i));
                var longitude = worksheet.NDouble(String.Format("Longitude{0}", i));
                if (altitude != null && latitude != null && longitude != null)
                {
                    _Plotter.AddCoordinate(1, altitude.Value, latitude.Value, longitude.Value);
                }
            }

            foreach (var slice in _Plotter.TakeSnapshot())
            {
                string suffix;
                switch (slice.AltitudeHigher)
                {
                case 9:     suffix = "-09"; break;

                case 19:    suffix = slice.AltitudeLower == 10 ? "-19" : "-RG"; break;

                default:    suffix = "-ALL"; break;
                }
                var nonZeroPolarPlots = slice.PolarPlots.Where(r => r.Value.Distance != 0).ToDictionary(r => r.Key, r => r.Value);
                Assert.AreEqual(worksheet.Int(String.Format("Count{0}", suffix)), nonZeroPolarPlots.Count, suffix);
                for (var i = 1; i <= nonZeroPolarPlots.Count; ++i)
                {
                    var bearing = worksheet.Int(String.Format("Ang{0}{1}", i, suffix));
                    var plot    = nonZeroPolarPlots[bearing];
                    Assert.AreEqual(worksheet.Int(String.Format("Alt{0}{1}", i, suffix)), plot.Altitude, suffix);
                    Assert.AreEqual(worksheet.Double(String.Format("Dist{0}{1}", i, suffix)), plot.Distance, 0.0001, suffix);
                    Assert.AreEqual(bearing, plot.Angle, suffix);
                }
            }
        }
Beispiel #8
0
        public void GreatCircleMaths_Distance_Calculates_Correct_Distances()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var startLatitude  = worksheet.NDouble("StartLatitude");
            var startLongitude = worksheet.NDouble("StartLongitude");
            var endLatitude    = worksheet.NDouble("EndLatitude");
            var endLongitude   = worksheet.NDouble("EndLongitude");
            var expected       = worksheet.NDouble("Distance");

            var actual = GreatCircleMaths.Distance(startLatitude, startLongitude, endLatitude, endLongitude);

            if (expected == null)
            {
                Assert.IsNull(actual);
            }
            else
            {
                Assert.AreEqual((double)expected, (double)actual, 0.0001);
            }
        }
Beispiel #9
0
        public void ProximityGadgetClosestAircraftJson_ToModel_Fills_Calculated_Details_Correctly()
        {
            var worksheet       = new ExcelWorksheetData(TestContext);
            var originLatitude  = worksheet.NDouble("GadgetLat");
            var originLongitude = worksheet.NDouble("GadgetLng");

            var aircraft = TestUtilities.CreateMockInstance <IAircraft>();

            bool hasPosition = worksheet.String("AircraftLat") != null;

            if (hasPosition)
            {
                aircraft.Object.Latitude  = worksheet.NFloat("AircraftLat");
                aircraft.Object.Longitude = worksheet.NFloat("AircraftLng");
            }

            var model = ProximityGadgetClosestAircraftJson.ToModel(aircraft.Object, originLatitude, originLongitude);

            Assert.AreEqual(worksheet.EString("Bearing"), model.BearingFromHere);
            Assert.AreEqual(worksheet.EString("Distance"), model.DistanceFromHere);
        }
Beispiel #10
0
        public void AircraftSanityChecker_FirstGoodPosition_Returns_Correct_Values()
        {
            var worksheet = new ExcelWorksheetData(TestContext);
            //if(!worksheet.NBool("JustThis").GetValueOrDefault()) continue;

            var comments = worksheet.String("Comments");

            for (var i = 1; i <= 5; ++i)
            {
                var distance = worksheet.NDouble(String.Format("Distance{0}", i));
                if (distance != null)
                {
                    var seconds        = worksheet.Double(String.Format("Seconds{0}", i));
                    var time           = new DateTime(2014, 8, 3).AddSeconds(seconds);
                    var expectedResult = worksheet.NDouble(String.Format("1stGood{0}", i));

                    double?latitude, longitude;
                    GreatCircleMaths.Destination(51.0, -0.6, 90.0, distance, out latitude, out longitude);

                    _Checker.CheckPosition(1, time, latitude.Value, longitude.Value);
                    var globalCoordinates = _Checker.FirstGoodPosition(1);

                    double?actualResult = null;
                    if (globalCoordinates != null)
                    {
                        actualResult = GreatCircleMaths.Distance(51.0, -0.6, globalCoordinates.Latitude, globalCoordinates.Longitude);
                    }

                    var message = String.Format("Column {0} {1}", i, comments);
                    if (expectedResult == null)
                    {
                        Assert.IsNull(actualResult, message);
                    }
                    else
                    {
                        Assert.AreEqual(expectedResult.Value, actualResult ?? double.MinValue, 0.001, message);
                    }
                }
            }
        }
Beispiel #11
0
        public void GreatCircleMaths_Destination_Calculates_Correct_Destination()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var startLatitude  = worksheet.NDouble("StartLatitude");
            var startLongitude = worksheet.NDouble("StartLongitude");
            var bearing        = worksheet.NDouble("Bearing");
            var distance       = worksheet.NDouble("Distance");

            double?endLatitude, endLongitude;

            GreatCircleMaths.Destination(startLatitude, startLongitude, bearing, distance, out endLatitude, out endLongitude);

            var expectedLatitude  = worksheet.NDouble("EndLatitude");
            var expectedLongitude = worksheet.NDouble("EndLongitude");

            if (expectedLatitude == null || expectedLongitude == null)
            {
                Assert.AreEqual(expectedLatitude, endLatitude);
                Assert.AreEqual(expectedLongitude, endLongitude);
            }
            else
            {
                Assert.AreEqual(expectedLatitude.Value, endLatitude.Value, 0.0001);
                Assert.AreEqual(expectedLongitude.Value, endLongitude.Value, 0.0001);
            }
        }
        public void GreatCircleMaths_Bearing_Calculates_Correct_Bearing()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var startLatitude = worksheet.NDouble("StartLatitude");
            var startLongitude = worksheet.NDouble("StartLongitude");
            var endLatitude = worksheet.NDouble("EndLatitude");
            var endLongitude = worksheet.NDouble("EndLongitude");
            var currentTrack = worksheet.NDouble("CurrentTrack");
            var expected = worksheet.NDouble("Bearing");

            var actual = GreatCircleMaths.Bearing(startLatitude, startLongitude, endLatitude, endLongitude, currentTrack, worksheet.Bool("ReverseBearing"), worksheet.Bool("IgnoreCurrentTrack"));

            if(expected == null) Assert.IsNull(actual);
            else                 Assert.AreEqual((double)expected, (double)actual, 0.0001);
        }
Beispiel #13
0
        public void AircraftSanityChecker_CheckPosition_Returns_Correct_Values()
        {
            var worksheet = new ExcelWorksheetData(TestContext);
            //if(!worksheet.NBool("JustThis").GetValueOrDefault()) continue;

            var comments = worksheet.String("Comments");

            for (var i = 1; i <= 5; ++i)
            {
                var distance = worksheet.NDouble(String.Format("Distance{0}", i));
                if (distance != null)
                {
                    var seconds        = worksheet.Double(String.Format("Seconds{0}", i));
                    var time           = new DateTime(2014, 8, 3).AddSeconds(seconds);
                    var expectedResult = worksheet.ParseEnum <Certainty>(String.Format("Result{0}", i));

                    double?latitude, longitude;
                    GreatCircleMaths.Destination(51.0, -0.6, 90.0, distance, out latitude, out longitude);

                    var actualResult = _Checker.CheckPosition(1, time, latitude.Value, longitude.Value);
                    Assert.AreEqual(expectedResult, actualResult, String.Format("Column {0} {1}", i, comments));
                }
            }
        }
Beispiel #14
0
        public void GreatCircleMaths_Bearing_Calculates_Correct_Bearing()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var startLatitude  = worksheet.NDouble("StartLatitude");
            var startLongitude = worksheet.NDouble("StartLongitude");
            var endLatitude    = worksheet.NDouble("EndLatitude");
            var endLongitude   = worksheet.NDouble("EndLongitude");
            var currentTrack   = worksheet.NDouble("CurrentTrack");
            var expected       = worksheet.NDouble("Bearing");

            var actual = GreatCircleMaths.Bearing(startLatitude, startLongitude, endLatitude, endLongitude, currentTrack, worksheet.Bool("ReverseBearing"), worksheet.Bool("IgnoreCurrentTrack"));

            if (expected == null)
            {
                Assert.IsNull(actual);
            }
            else
            {
                Assert.AreEqual((double)expected, (double)actual, 0.0001);
            }
        }
        public void GreatCircleMaths_Destination_Calculates_Correct_Destination()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var startLatitude = worksheet.NDouble("StartLatitude");
            var startLongitude = worksheet.NDouble("StartLongitude");
            var bearing = worksheet.NDouble("Bearing");
            var distance = worksheet.NDouble("Distance");

            double? endLatitude, endLongitude;
            GreatCircleMaths.Destination(startLatitude, startLongitude, bearing, distance, out endLatitude, out endLongitude);

            var expectedLatitude = worksheet.NDouble("EndLatitude");
            var expectedLongitude = worksheet.NDouble("EndLongitude");

            if(expectedLatitude == null || expectedLongitude == null) {
                Assert.AreEqual(expectedLatitude, endLatitude);
                Assert.AreEqual(expectedLongitude, endLongitude);
            } else {
                Assert.AreEqual(expectedLatitude.Value, endLatitude.Value, 0.0001);
                Assert.AreEqual(expectedLongitude.Value, endLongitude.Value, 0.0001);
            }
        }
        public void RawMessageTranslator_Translate_Extracts_Position_From_ADSB_Messages_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            _Translator.ReceiverLocation = ParseGlobalPosition(worksheet.String("ReceiverPosn"));
            _Translator.ReceiverRangeKilometres = worksheet.Int("Range");
            _Translator.GlobalDecodeAirborneThresholdMilliseconds = worksheet.Int("GATS");
            _Translator.GlobalDecodeFastSurfaceThresholdMilliseconds = worksheet.Int("GFSTS");
            _Translator.GlobalDecodeSlowSurfaceThresholdMilliseconds = worksheet.Int("GSSTS");
            _Translator.LocalDecodeMaxSpeedAirborne = worksheet.Double("LAMS");
            _Translator.LocalDecodeMaxSpeedTransition = worksheet.Double("LTMS");
            _Translator.LocalDecodeMaxSpeedSurface = worksheet.Double("LSMS");
            _Translator.SuppressReceiverRangeCheck = worksheet.Bool("SRRC");
            _Translator.UseLocalDecodeForInitialPosition = worksheet.Bool("ULD");

            DateTime now = DateTime.UtcNow;
            for(var i = 1;i <= 4;++i) {
                var millisecondsColumn = String.Format("MSec{0}", i);
                var cprColumn = String.Format("CPR{0}", i);
                var speedColumn = String.Format("Spd{0}", i);
                var positionColumn = String.Format("Posn{0}", i);

                if(worksheet.String(cprColumn) == null) continue;
                var cpr = ParseCpr(worksheet.String(cprColumn));
                var speed = worksheet.NDouble(speedColumn);
                var expectedPosition = ParseGlobalPosition(worksheet.String(positionColumn));

                if(i != 1 && worksheet.String(millisecondsColumn) != null) {
                    now = now.AddMilliseconds(worksheet.Int(millisecondsColumn));
                }

                var modeSMessage = new ModeSMessage() { DownlinkFormat = DownlinkFormat.ExtendedSquitter, Icao24 = 0x112233, ParityInterrogatorIdentifier = 0 };
                var adsbMessage = new AdsbMessage(modeSMessage);
                switch(cpr.NumberOfBits) {
                    case 17:
                        adsbMessage.MessageFormat = MessageFormat.AirbornePosition;
                        adsbMessage.AirbornePosition = new AirbornePositionMessage() { CompactPosition = cpr };
                        break;
                    case 19:
                        adsbMessage.MessageFormat = MessageFormat.SurfacePosition;
                        adsbMessage.SurfacePosition = new SurfacePositionMessage() { CompactPosition = cpr, GroundSpeed = speed, };
                        break;
                }

                var baseStationMessage = _Translator.Translate(now, modeSMessage, adsbMessage);

                var failMessage = String.Format("Failed on message {0}", i);
                if(expectedPosition == null) {
                    if(baseStationMessage != null) {
                        if(baseStationMessage.Latitude != null || baseStationMessage.Longitude != null) {
                            Assert.Fail(String.Format("Position decoded to {0}/{1} erroneously. {2}", baseStationMessage.Latitude, baseStationMessage.Longitude, failMessage));
                        }
                    }
                } else {
                    Assert.IsNotNull(baseStationMessage.Latitude, failMessage);
                    Assert.IsNotNull(baseStationMessage.Longitude, failMessage);
                    Assert.AreEqual(expectedPosition.Latitude, baseStationMessage.Latitude.Value, 0.0001, failMessage);
                    Assert.AreEqual(expectedPosition.Longitude, baseStationMessage.Longitude.Value, 0.0001, failMessage);
                }
            }

            Assert.AreEqual(worksheet.Int("ResetCount"), _PositionResetEvent.CallCount);
            Assert.AreEqual(worksheet.Int("ResetCount") > 0 ? 1L : 0L, _Statistics.AdsbPositionsReset);
            Assert.AreEqual(worksheet.Long("BadRange"), _Statistics.AdsbPositionsOutsideRange);
            Assert.AreEqual(worksheet.Long("BadSpeed"), _Statistics.AdsbPositionsExceededSpeedCheck);
        }
        private void Do_BaseStationMessage_ToBaseStationString_Builds_Valid_BaseStation_Messages_From_A_BaseStationMessage_Object()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            _Implementation.MessageType = worksheet.ParseEnum<BaseStationMessageType>("MessageType");
            _Implementation.TransmissionType = worksheet.ParseEnum<BaseStationTransmissionType>("TransmissionType");
            _Implementation.StatusCode = worksheet.ParseEnum<BaseStationStatusCode>("StatusCode");
            _Implementation.SessionId = worksheet.Int("SessionId");
            _Implementation.AircraftId = worksheet.Int("AircraftId");
            _Implementation.Icao24 = worksheet.String("Icao24");
            _Implementation.FlightId = worksheet.Int("FlightId");
            _Implementation.MessageGenerated = worksheet.DateTime("MessageGenerated");
            _Implementation.MessageLogged = worksheet.DateTime("MessageLogged");
            _Implementation.Callsign = worksheet.String("Callsign");
            _Implementation.Altitude = worksheet.NInt("Altitude");
            _Implementation.GroundSpeed = worksheet.NFloat("GroundSpeed");
            _Implementation.Track = worksheet.NFloat("Track");
            _Implementation.Latitude = worksheet.NDouble("Latitude");
            _Implementation.Longitude = worksheet.NDouble("Longitude");
            _Implementation.VerticalRate = worksheet.NInt("VerticalRate");
            _Implementation.Squawk = worksheet.NInt("Squawk");
            _Implementation.SquawkHasChanged = worksheet.NBool("SquawkHasChanged");
            _Implementation.Emergency = worksheet.NBool("Emergency");
            _Implementation.IdentActive = worksheet.NBool("IdentActive");
            _Implementation.OnGround = worksheet.NBool("OnGround");

            Assert.AreEqual(worksheet.String("Text"), _Implementation.ToBaseStationString());
        }
        public void BaseStationMessageCompressor_Compress_And_Decompress_Work_As_Expected()
        {
            ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext);

            var messageIn = new BaseStationMessage();

            messageIn.MessageType      = worksheet.ParseEnum <BaseStationMessageType>("MessageType");
            messageIn.TransmissionType = worksheet.ParseEnum <BaseStationTransmissionType>("TransmissionType");
            messageIn.StatusCode       = worksheet.ParseEnum <BaseStationStatusCode>("StatusCode");
            messageIn.Icao24           = worksheet.EString("Icao24");
            messageIn.SessionId        = worksheet.Int("SessionId");
            messageIn.AircraftId       = worksheet.Int("AircraftId");
            messageIn.FlightId         = worksheet.Int("FlightId");
            messageIn.MessageGenerated = worksheet.DateTime("MessageGenerated");
            messageIn.MessageLogged    = worksheet.DateTime("MessageLogged");
            messageIn.Callsign         = worksheet.String("Callsign");
            messageIn.Altitude         = worksheet.NInt("Altitude");
            messageIn.GroundSpeed      = worksheet.NInt("GroundSpeed");
            messageIn.Track            = worksheet.NFloat("Track");
            messageIn.Latitude         = worksheet.NDouble("Latitude");
            messageIn.Longitude        = worksheet.NDouble("Longitude");
            messageIn.VerticalRate     = worksheet.NInt("VerticalRate");
            messageIn.Squawk           = worksheet.NInt("Squawk");
            messageIn.SquawkHasChanged = worksheet.NBool("SquawkHasChanged");
            messageIn.Emergency        = worksheet.NBool("Emergency");
            messageIn.IdentActive      = worksheet.NBool("IdentActive");
            messageIn.OnGround         = worksheet.NBool("OnGround");

            int expectedLength = worksheet.Int("Length");

            byte[] bytes = _Compressor.Compress(messageIn);
            Assert.AreEqual(expectedLength, bytes.Length);

            DateTime           earliestDate = DateTime.Now;
            BaseStationMessage messageOut   = _Compressor.Decompress(bytes);
            DateTime           latestDate   = DateTime.Now;

            if (bytes.Length == 0)
            {
                Assert.IsNull(messageOut);
            }
            else
            {
                Assert.AreEqual(messageIn.MessageType, messageOut.MessageType);
                Assert.AreEqual(messageIn.TransmissionType, messageOut.TransmissionType);
                Assert.AreEqual(BaseStationStatusCode.None, messageOut.StatusCode);
                Assert.AreEqual(messageIn.Icao24, messageOut.Icao24);
                Assert.AreEqual(0, messageOut.SessionId);
                Assert.AreEqual(0, messageOut.AircraftId);
                Assert.AreEqual(0, messageOut.FlightId);
                Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageGenerated.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks);
                Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageLogged.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks);
                Assert.AreEqual(messageIn.Callsign, messageOut.Callsign);
                Assert.AreEqual(messageIn.Altitude, messageOut.Altitude);
                Assert.AreEqual(messageIn.GroundSpeed, messageOut.GroundSpeed);
                Assert.AreEqual(messageIn.Track, messageOut.Track);
                if (messageIn.Latitude == null)
                {
                    Assert.IsNull(messageOut.Latitude);
                }
                else
                {
                    Assert.AreEqual(messageIn.Latitude.Value, messageOut.Latitude.Value, 0.000001);
                }
                if (messageIn.Longitude == null)
                {
                    Assert.IsNull(messageOut.Longitude);
                }
                else
                {
                    Assert.AreEqual(messageIn.Longitude.Value, messageOut.Longitude.Value, 0.000001);
                }
                Assert.AreEqual(messageIn.VerticalRate, messageOut.VerticalRate);
                Assert.AreEqual(messageIn.Squawk, messageOut.Squawk);
                Assert.AreEqual(messageIn.SquawkHasChanged, messageOut.SquawkHasChanged);
                Assert.AreEqual(messageIn.Emergency, messageOut.Emergency);
                Assert.AreEqual(messageIn.IdentActive, messageOut.IdentActive);
                Assert.AreEqual(messageIn.OnGround, messageOut.OnGround);
            }
        }
        public void BaseStationMessageTranslator_Translate_Translates_Messages_Correctly()
        {
            ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext);

            BaseStationMessage translated = _Implementation.Translate(worksheet.String("Text"));
            Assert.AreEqual(Enum.Parse(typeof(BaseStationMessageType), worksheet.String("MessageType")), translated.MessageType);
            Assert.AreEqual(Enum.Parse(typeof(BaseStationTransmissionType), worksheet.String("TransmissionType")), translated.TransmissionType);
            Assert.AreEqual(Enum.Parse(typeof(BaseStationStatusCode), worksheet.String("StatusCode")), translated.StatusCode);
            Assert.AreEqual(worksheet.Int("SessionId"), translated.SessionId);
            Assert.AreEqual(worksheet.Int("AircraftId"), translated.AircraftId);
            Assert.AreEqual(worksheet.String("Icao24"), translated.Icao24);
            Assert.AreEqual(worksheet.Int("FlightId"), translated.FlightId);
            Assert.AreEqual(worksheet.DateTime("MessageGenerated"), translated.MessageGenerated);
            Assert.AreEqual(worksheet.DateTime("MessageLogged"), translated.MessageLogged);
            Assert.AreEqual(worksheet.String("Callsign"), translated.Callsign);
            Assert.AreEqual(worksheet.NFloat("Altitude"), translated.Altitude);
            Assert.AreEqual(worksheet.NFloat("GroundSpeed"), translated.GroundSpeed);
            Assert.AreEqual(worksheet.NFloat("Track"), translated.Track);
            Assert.AreEqual(worksheet.NDouble("Latitude"), translated.Latitude);
            Assert.AreEqual(worksheet.NDouble("Longitude"), translated.Longitude);
            Assert.AreEqual(worksheet.NFloat("VerticalRate"), translated.VerticalRate);
            Assert.AreEqual(worksheet.NInt("Squawk"), translated.Squawk);
            Assert.AreEqual(worksheet.NBool("SquawkHasChanged"), translated.SquawkHasChanged);
            Assert.AreEqual(worksheet.NBool("Emergency"), translated.Emergency);
            Assert.AreEqual(worksheet.NBool("IdentActive"), translated.IdentActive);
            Assert.AreEqual(worksheet.NBool("OnGround"), translated.OnGround);
        }
        public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var obj = new ValueTypes() {
                BoolValue = worksheet.Bool("BoolValue"),
                UnusedBool = worksheet.Bool("UnusedBool"),
                NullableBool = worksheet.NBool("NullableBool"),
                Int = worksheet.Int("Int"),
                NullableInt = worksheet.NInt("NullableInt"),
                Long = worksheet.Long("Long"),
                NullableLong = worksheet.NLong("NullableLong"),
                Float = worksheet.Float("Float"),
                NullableFloat = worksheet.NFloat("NullableFloat"),
                Double = worksheet.Double("Double"),
                NullableDouble = worksheet.NDouble("NullableDouble"),
                DateTime = worksheet.DateTime("DateTime"),
                NullableDateTime = worksheet.NDateTime("NullableDateTime"),
            };

            _JsonSerialiser.Initialise(typeof(ValueTypes));
            _JsonSerialiser.WriteObject(_Stream, obj);

            Assert.AreEqual(worksheet.EString("Json"), GetJson());
        }
        public void WebSite_BaseStationAircraftList_Builds_Arrays_Of_Trail_Coordinates_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            AddBlankAircraft(1);
            var aircraft = _BaseStationAircraft[0];
            Mock<IAircraft> mockAircraft = Mock.Get(aircraft);

            aircraft.Latitude = worksheet.NFloat("ACLat");
            aircraft.Longitude = worksheet.NFloat("ACLng");
            aircraft.Track = worksheet.NFloat("ACTrk");
            aircraft.FirstCoordinateChanged = worksheet.Long("ACFirstCoCh");
            aircraft.LastCoordinateChanged = worksheet.Long("ACLastCoCh");
            aircraft.PositionTime = new DateTime(1970, 1, 1, 0, 0, 0, worksheet.Int("ACPosTimeCh"));
            mockAircraft.Setup(m => m.PositionTimeChanged).Returns(worksheet.Long("ACPosTimeCh"));

            for(int i = 1;i <= 2;++i) {
                var dataVersion = String.Format("Coord{0}DV", i);
                var tick = String.Format("Coord{0}Tick", i);
                var latitude = String.Format("Coord{0}Lat", i);
                var longitude = String.Format("Coord{0}Lng", i);
                var track = String.Format("Coord{0}Trk", i);
                if(worksheet.String(dataVersion) != null) {
                    DateTime dotNetDate = new DateTime(1970, 1, 1, 0, 0, 0, worksheet.Int(tick));
                    var coordinate = new Coordinate(worksheet.Long(dataVersion), dotNetDate.Ticks, worksheet.Float(latitude), worksheet.Float(longitude), worksheet.NFloat(track));
                    aircraft.FullCoordinates.Add(coordinate);
                    aircraft.ShortCoordinates.Add(coordinate);
                }
            }

            _AircraftListAddress.PreviousDataVersion = worksheet.Long("ArgsPrevDV");
            if(worksheet.Bool("ArgsIsPrevAC")) _AircraftListAddress.PreviousAircraft.Add(0);
            _AircraftListAddress.ShowShortTrail = worksheet.Bool("ArgsShort");
            _AircraftListAddress.ResendTrails = worksheet.Bool("ArgsResend");

            var aircraftJson = SendJsonRequest<AircraftListJson>(_AircraftListAddress.Address).Aircraft[0];

            var count = worksheet.Int("Count");
            if(count == 0) {
                Assert.IsNull(aircraftJson.ShortCoordinates);
                Assert.IsNull(aircraftJson.FullCoordinates);
            } else {
                var list = worksheet.Bool("IsShort") ? aircraftJson.ShortCoordinates : aircraftJson.FullCoordinates;
                Assert.AreEqual(count, list.Count);
                for(int i = 0;i < count;++i) {
                    var column = String.Format("R{0}", i);
                    Assert.AreEqual(worksheet.NDouble(column), list[i], "Element {0}", i);
                }
            }

            Assert.AreEqual(worksheet.Bool("ResetTrail"), aircraftJson.ResetTrail);
        }
        public void WebSite_BaseStationAircraftList_Calculates_Distances_From_Browser_To_Aircraft_Correctly_When_Culture_Is_Not_UK()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            using(var switcher = new CultureSwitcher("de-DE")) {
                var aircraft = new Mock<IAircraft>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
                _BaseStationAircraft.Add(aircraft.Object);

                aircraft.Object.Latitude = worksheet.NFloat("AircraftLatitude");
                aircraft.Object.Longitude = worksheet.NFloat("AircraftLongitude");

                string address = String.Format("{0}?lat={1}&lng={2}", _AircraftListAddress.Page, worksheet.String("BrowserLatitude"), worksheet.String("BrowserLongitude"));

                var list = SendJsonRequest<AircraftListJson>(address);
                Assert.AreEqual(1, list.Aircraft.Count);
                var aircraftJson = list.Aircraft[0];

                double? expected = worksheet.NDouble("Distance");
                if(expected == null) Assert.IsNull(aircraftJson.DistanceFromHere);
                else Assert.AreEqual((double)expected, (double)aircraftJson.DistanceFromHere);
            }
        }
        public void WebSite_BaseStationAircraftList_Calculates_Distances_From_Browser_To_Aircraft_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var aircraft = new Mock<IAircraft>() { DefaultValue = DefaultValue.Mock }.SetupAllProperties();
            _BaseStationAircraft.Add(aircraft.Object);

            aircraft.Object.Latitude = worksheet.NFloat("AircraftLatitude");
            aircraft.Object.Longitude = worksheet.NFloat("AircraftLongitude");

            _AircraftListAddress.BrowserLatitude = worksheet.NDouble("BrowserLatitude");
            _AircraftListAddress.BrowserLongitude = worksheet.NDouble("BrowserLongitude");

            var list = SendJsonRequest<AircraftListJson>(_AircraftListAddress.Address);
            Assert.AreEqual(1, list.Aircraft.Count);
            var aircraftJson = list.Aircraft[0];

            double? expected = worksheet.NDouble("Distance");
            if(expected == null) Assert.IsNull(aircraftJson.DistanceFromHere);
            else Assert.AreEqual((double)expected, (double)aircraftJson.DistanceFromHere);
        }
        public void BaseStationMessageCompressor_Compress_And_Decompress_Work_As_Expected()
        {
            ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext);

            var messageIn = new BaseStationMessage();
            messageIn.MessageType = worksheet.ParseEnum<BaseStationMessageType>("MessageType");
            messageIn.TransmissionType = worksheet.ParseEnum<BaseStationTransmissionType>("TransmissionType");
            messageIn.StatusCode = worksheet.ParseEnum<BaseStationStatusCode>("StatusCode");
            messageIn.Icao24 = worksheet.EString("Icao24");
            messageIn.SessionId = worksheet.Int("SessionId");
            messageIn.AircraftId = worksheet.Int("AircraftId");
            messageIn.FlightId = worksheet.Int("FlightId");
            messageIn.MessageGenerated = worksheet.DateTime("MessageGenerated");
            messageIn.MessageLogged = worksheet.DateTime("MessageLogged");
            messageIn.Callsign = worksheet.String("Callsign");
            messageIn.Altitude = worksheet.NInt("Altitude");
            messageIn.GroundSpeed = worksheet.NInt("GroundSpeed");
            messageIn.Track = worksheet.NFloat("Track");
            messageIn.Latitude = worksheet.NDouble("Latitude");
            messageIn.Longitude = worksheet.NDouble("Longitude");
            messageIn.VerticalRate = worksheet.NInt("VerticalRate");
            messageIn.Squawk = worksheet.NInt("Squawk");
            messageIn.SquawkHasChanged = worksheet.NBool("SquawkHasChanged");
            messageIn.Emergency = worksheet.NBool("Emergency");
            messageIn.IdentActive = worksheet.NBool("IdentActive");
            messageIn.OnGround = worksheet.NBool("OnGround");

            int expectedLength = worksheet.Int("Length");

            byte[] bytes = _Compressor.Compress(messageIn);
            Assert.AreEqual(expectedLength, bytes.Length);

            DateTime earliestDate = DateTime.Now;
            BaseStationMessage messageOut = _Compressor.Decompress(bytes);
            DateTime latestDate = DateTime.Now;

            if(bytes.Length == 0) Assert.IsNull(messageOut);
            else {
                Assert.AreEqual(messageIn.MessageType, messageOut.MessageType);
                Assert.AreEqual(messageIn.TransmissionType, messageOut.TransmissionType);
                Assert.AreEqual(BaseStationStatusCode.None, messageOut.StatusCode);
                Assert.AreEqual(messageIn.Icao24, messageOut.Icao24);
                Assert.AreEqual(0, messageOut.SessionId);
                Assert.AreEqual(0, messageOut.AircraftId);
                Assert.AreEqual(0, messageOut.FlightId);
                Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageGenerated.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks);
                Assert.AreEqual((double)earliestDate.Ticks, (double)messageOut.MessageLogged.Ticks, (double)latestDate.Ticks - (double)earliestDate.Ticks);
                Assert.AreEqual(messageIn.Callsign, messageOut.Callsign);
                Assert.AreEqual(messageIn.Altitude, messageOut.Altitude);
                Assert.AreEqual(messageIn.GroundSpeed, messageOut.GroundSpeed);
                Assert.AreEqual(messageIn.Track, messageOut.Track);
                if(messageIn.Latitude == null) Assert.IsNull(messageOut.Latitude);
                else Assert.AreEqual(messageIn.Latitude.Value, messageOut.Latitude.Value, 0.000001);
                if(messageIn.Longitude == null) Assert.IsNull(messageOut.Longitude);
                else Assert.AreEqual(messageIn.Longitude.Value, messageOut.Longitude.Value, 0.000001);
                Assert.AreEqual(messageIn.VerticalRate, messageOut.VerticalRate);
                Assert.AreEqual(messageIn.Squawk, messageOut.Squawk);
                Assert.AreEqual(messageIn.SquawkHasChanged, messageOut.SquawkHasChanged);
                Assert.AreEqual(messageIn.Emergency, messageOut.Emergency);
                Assert.AreEqual(messageIn.IdentActive, messageOut.IdentActive);
                Assert.AreEqual(messageIn.OnGround, messageOut.OnGround);
            }
        }
        public void WebSite_BaseStationAircraftList_AircraftListFilter_Distance_AircraftListFiltered_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            _AircraftListAddress.Filter = _AircraftListFilter;
            _AircraftListAddress.BrowserLatitude = worksheet.Float("BrowserLatitude");
            _AircraftListAddress.BrowserLongitude = worksheet.Float("BrowserLongitude");

            AddBlankAircraft(1);
            _BaseStationAircraft[0].Latitude = worksheet.NFloat("AircraftLatitude");
            _BaseStationAircraft[0].Longitude = worksheet.NFloat("AircraftLongitude");

            _AircraftListFilter.DistanceLower = worksheet.NDouble("DistanceLower");
            _AircraftListFilter.DistanceUpper = worksheet.NDouble("DistanceUpper");

            bool passed = SendJsonRequest<AircraftListJson>(_AircraftListAddress.Address).Aircraft.Count == 1;

            Assert.AreEqual(worksheet.Bool("Passes"), passed);
        }
        public void JsonSerialiser_WriteObject_Writes_ValueTypes_Correctly_For_Non_UK_Cultures()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            foreach(var culture in new string[] { "en-US", "de-DE", "fr-FR", "ru-RU" }) {
                using(var cultureSwitcher = new CultureSwitcher(culture)) {
                    TestCleanup();
                    TestInitialise();

                    var obj = new ValueTypes() {
                        BoolValue = worksheet.Bool("BoolValue"),
                        UnusedBool = worksheet.Bool("UnusedBool"),
                        NullableBool = worksheet.NBool("NullableBool"),
                        Int = worksheet.Int("Int"),
                        NullableInt = worksheet.NInt("NullableInt"),
                        Long = worksheet.Long("Long"),
                        NullableLong = worksheet.NLong("NullableLong"),
                        Float = worksheet.Float("Float"),
                        NullableFloat = worksheet.NFloat("NullableFloat"),
                        Double = worksheet.Double("Double"),
                        NullableDouble = worksheet.NDouble("NullableDouble"),
                        DateTime = worksheet.DateTime("DateTime"),
                        NullableDateTime = worksheet.NDateTime("NullableDateTime"),
                    };

                    _JsonSerialiser.Initialise(typeof(ValueTypes));
                    _JsonSerialiser.WriteObject(_Stream, obj);

                    var message = String.Format("when culture is {0}", culture);
                    Assert.AreEqual(worksheet.EString("Json"), GetJson(), message);
                }
            }
        }