Ejemplo n.º 1
0
        public void PolarPlotsSliceJson_ToModel_Converts_PolarPlotSlice()
        {
            var polarPlotSlice = new PolarPlotSlice()
            {
                AltitudeLower  = 12000,
                AltitudeHigher = 13499,
            };

            polarPlotSlice.PolarPlots.Add(10, new PolarPlot()
            {
                Altitude  = 12000,
                Angle     = 10,
                Distance  = 0,
                Latitude  = 1.23,
                Longitude = 4.56,
            });

            var model = PolarPlotsSliceJson.ToModel(polarPlotSlice);

            Assert.AreEqual(12000, model.StartAltitude);
            Assert.AreEqual(13499, model.FinishAltitude);
            Assert.AreEqual(1, model.Plots.Count);
            Assert.AreEqual(1.23F, model.Plots[0].Latitude);
            Assert.AreEqual(4.56F, model.Plots[0].Longitude);
        }
Ejemplo n.º 2
0
        public void PolarPlotSlice_Constructor_Initialises_To_Known_Values_And_Properties_Work()
        {
            var slice = new PolarPlotSlice();

            TestUtilities.TestProperty(slice, r => r.AltitudeHigher, 0, int.MaxValue);
            TestUtilities.TestProperty(slice, r => r.AltitudeLower, 0, int.MinValue);
            Assert.AreEqual(0, slice.PolarPlots.Count);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a new <see cref="PolarPlotsSliceJson"/> built from a listener's polar plot slice.
        /// </summary>
        /// <param name="slice"></param>
        /// <returns></returns>
        public static PolarPlotsSliceJson ToModel(PolarPlotSlice slice)
        {
            PolarPlotsSliceJson result = null;

            if (slice != null)
            {
                result = new PolarPlotsSliceJson()
                {
                    StartAltitude  = slice.AltitudeLower,
                    FinishAltitude = slice.AltitudeHigher,
                };
                result.Plots.AddRange(slice.PolarPlots.OrderBy(r => r.Key).Select(r => PolarPlotJson.ToModel(r.Value)));
            }

            return(result);
        }
Ejemplo n.º 4
0
        public void PolarPlotSlice_Clone_Deep_Copies_All_Properties()
        {
            foreach (var property in typeof(PolarPlotSlice).GetProperties())
            {
                var original = new PolarPlotSlice();
                switch (property.Name)
                {
                case "PolarPlots":  original.PolarPlots.Add(17, new PolarPlot()
                    {
                        Altitude = 1
                    }); break;

                default:            TestUtilities.AssignPropertyValue(original, property, true); break;
                }

                var copy = original.Clone();

                foreach (var compareProperty in typeof(PolarPlotSlice).GetProperties())
                {
                    var originalValue = compareProperty.GetValue(original, null);
                    var newValue      = compareProperty.GetValue(copy, null);

                    switch (compareProperty.Name)
                    {
                    case "PolarPlots":
                        var originalDict = (Dictionary <int, PolarPlot>)originalValue;
                        var newDict      = (Dictionary <int, PolarPlot>)newValue;
                        Assert.IsFalse(Object.ReferenceEquals(originalDict, newDict));
                        Assert.AreEqual(originalDict.Count, newDict.Count);
                        for (var i = 0; i < originalDict.Count; ++i)
                        {
                            var originalPlot = originalDict[17];
                            var newPlot      = newDict[17];
                            Assert.IsFalse(object.ReferenceEquals(originalPlot, newPlot));
                            Assert.AreEqual(originalPlot.Altitude, newPlot.Altitude);
                        }
                        break;

                    default:
                        Assert.AreEqual(originalValue, newValue, compareProperty.Name);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void PolarPlotsSliceJson_ToModel_Returns_Plots_In_Angle_Order()
        {
            var polarPlotSlice = new PolarPlotSlice();

            polarPlotSlice.PolarPlots.Add(99, new PolarPlot()
            {
                Angle = 99, Latitude = 99, Longitude = 99,
            });
            polarPlotSlice.PolarPlots.Add(30, new PolarPlot()
            {
                Angle = 30, Latitude = 30, Longitude = 30,
            });
            polarPlotSlice.PolarPlots.Add(45, new PolarPlot()
            {
                Angle = 45, Latitude = 45, Longitude = 45,
            });

            var model = PolarPlotsSliceJson.ToModel(polarPlotSlice);

            Assert.AreEqual(30F, model.Plots[0].Latitude);
            Assert.AreEqual(45F, model.Plots[1].Latitude);
            Assert.AreEqual(99F, model.Plots[2].Latitude);
        }