public void ProximityGadgetClosestAircraftJson_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var json = new ProximityGadgetClosestAircraftJson();

            TestUtilities.TestProperty(json, "Altitude", null, "Abc");
            TestUtilities.TestProperty(json, "BearingFromHere", null, "Abc");
            TestUtilities.TestProperty(json, "Callsign", null, "Abc");
            TestUtilities.TestProperty(json, "Destination", null, "Abc");
            TestUtilities.TestProperty(json, "DistanceFromHere", null, "Abc");
            TestUtilities.TestProperty(json, "Emergency", false);
            TestUtilities.TestProperty(json, "GroundSpeed", null, "Abc");
            TestUtilities.TestProperty(json, "HasPicture", false);
            TestUtilities.TestProperty(json, "Icao24", null, "Abc");
            TestUtilities.TestProperty(json, "Icao24Invalid", false);
            TestUtilities.TestProperty(json, "Latitude", null, "Abc");
            TestUtilities.TestProperty(json, "Longitude", null, "Abc");
            TestUtilities.TestProperty(json, "Manufacturer", null, "Abc");
            TestUtilities.TestProperty(json, "Model", null, "Abc");
            TestUtilities.TestProperty(json, "Operator", null, "Abc");
            TestUtilities.TestProperty(json, "OperatorIcao", null, "Abc");
            TestUtilities.TestProperty(json, "Origin", null, "Abc");
            TestUtilities.TestProperty(json, "Registration", null, "Abc");
            TestUtilities.TestProperty(json, "Squawk", null, "Abc");
            TestUtilities.TestProperty(json, "Track", null, "Abc");
            TestUtilities.TestProperty(json, "Type", null, "Abc");
            TestUtilities.TestProperty(json, "VerticalRate", null, "Abc");
            Assert.AreEqual(0, json.Stopovers.Count);
        }
Пример #2
0
        /// <summary>
        /// Creates an object that represents an aircraft in <see cref="ProximityGadgetAircraftJson"/>.
        /// </summary>
        /// <param name="aircraft"></param>
        /// <param name="distance"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        private ProximityGadgetClosestAircraftJson CreateProximityGadgetClosestAircraftJson(IAircraft aircraft, double?distance, double?latitude, double?longitude)
        {
            var result = new ProximityGadgetClosestAircraftJson()
            {
                Altitude         = FormatNullable(aircraft.Altitude),
                BearingFromHere  = FormatNullable(GreatCircleMaths.Bearing(latitude, longitude, aircraft.Latitude, aircraft.Longitude, null, false, false), null, 1),
                Callsign         = aircraft.Callsign,
                Destination      = aircraft.Destination,
                DistanceFromHere = FormatNullable(distance, null, 2),
                Emergency        = aircraft.Emergency.GetValueOrDefault(),
                GroundSpeed      = FormatNullable(aircraft.GroundSpeed),
                HasPicture       = !String.IsNullOrEmpty(aircraft.PictureFileName),
                Icao24           = aircraft.Icao24 ?? "",
                Icao24Invalid    = aircraft.Icao24Invalid,
                Latitude         = FormatNullable(aircraft.Latitude),
                Longitude        = FormatNullable(aircraft.Longitude),
                Manufacturer     = aircraft.Manufacturer,
                Model            = aircraft.Model,
                Operator         = aircraft.Operator,
                OperatorIcao     = aircraft.OperatorIcao,
                Origin           = aircraft.Origin,
                Registration     = aircraft.Registration,
                Squawk           = aircraft.Squawk.GetValueOrDefault() == 0 ? null : String.Format("{0:0000}", aircraft.Squawk),
                Track            = FormatNullable(aircraft.Track, null, 1),
                Type             = aircraft.Type,
                VerticalRate     = FormatNullable(aircraft.VerticalRate),
            };

            result.Stopovers.AddRange(aircraft.Stopovers);

            return(result);
        }
Пример #3
0
        public void ProximityGadgetClosestAircraftJson_ToModel_Handles_Reference_Origin_Of_Null()
        {
            var aircraft = TestUtilities.CreateMockInstance <IAircraft>();

            aircraft.Object.Latitude  = 1;
            aircraft.Object.Longitude = 1;

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

            Assert.AreEqual("1", model.Latitude);
            Assert.AreEqual("1", model.Longitude);
            Assert.IsNull(model.DistanceFromHere);
            Assert.IsNull(model.BearingFromHere);
        }
Пример #4
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);
        }
Пример #5
0
        public void ProximityGadgetClosestAircraftJson_ToModel_Converts_From_IAircraft_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

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

            aircraft.Object.Latitude  = 1;
            aircraft.Object.Longitude = 1;

            var aircraftProperty = typeof(IAircraft).GetProperty(worksheet.String("AircraftProperty"));
            var aircraftValue    = TestUtilities.ChangeType(worksheet.EString("AircraftValue"), aircraftProperty.PropertyType, new CultureInfo("en-GB"));

            aircraftProperty.SetValue(aircraft.Object, aircraftValue, null);

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

            var modelProperty = typeof(ProximityGadgetClosestAircraftJson).GetProperty(worksheet.String("JsonProperty"));
            var expected      = TestUtilities.ChangeType(worksheet.EString("JsonValue"), modelProperty.PropertyType, new CultureInfo("en-GB"));
            var actual        = modelProperty.GetValue(model, null);

            Assert.AreEqual(expected, actual, modelProperty.Name);
        }
Пример #6
0
 public void ProximityGadgetClosestAircraftJson_ToModel_Returns_Null_If_Passed_Null()
 {
     Assert.IsNull(ProximityGadgetClosestAircraftJson.ToModel(null, 1.0, 1.0));
 }