public void RoundTripRifle()
        {
            Rifle rifle = new Rifle()
            {
                Rifling = new Rifling()
                {
                    Direction   = TwistDirection.Right,
                    RiflingStep = new Measurement <DistanceUnit>(12, DistanceUnit.Inch)
                },
                Sight = new Sight()
                {
                    SightHeight     = new Measurement <DistanceUnit>(3.2, DistanceUnit.Inch),
                    VerticalClick   = new Measurement <AngularUnit>(0.5, AngularUnit.MOA),
                    HorizontalClick = new Measurement <AngularUnit>(0.25, AngularUnit.MOA),
                },
                Zero = new ZeroingParameters()
                {
                    Ammunition = new Ammunition()
                    {
                        BallisticCoefficient = new BallisticCoefficient(0.375, DragTableId.G7),
                        MuzzleVelocity       = new Measurement <VelocityUnit>(2700, VelocityUnit.FeetPerSecond),
                        Weight = new Measurement <WeightUnit>(168, WeightUnit.Grain)
                    },
                    Atmosphere = new Atmosphere(new Measurement <DistanceUnit>(123, DistanceUnit.Meter),
                                                new Measurement <PressureUnit>(30.02, PressureUnit.InchesOfMercury),
                                                new Measurement <TemperatureUnit>(16, TemperatureUnit.Celsius),
                                                0.57),
                    Distance = new Measurement <DistanceUnit>(100, DistanceUnit.Yard)
                }
            };
            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml    = serializer.Serialize(rifle);
            var rifle2 = serializer.Deserialize <Rifle>(xml);

            rifle2.Rifling.Should().NotBeNull();
            rifle2.Sight.Should().NotBeNull();
            rifle2.Zero.Should().NotBeNull();

            rifle2.Rifling.RiflingStep.Should().Be(rifle.Rifling.RiflingStep);
            rifle2.Rifling.Direction.Should().Be(rifle.Rifling.Direction);

            rifle2.Sight.SightHeight.Should().Be(rifle.Sight.SightHeight);
            rifle2.Sight.VerticalClick.Should().Be(rifle.Sight.VerticalClick);
            rifle2.Sight.HorizontalClick.Should().Be(rifle.Sight.HorizontalClick);

            rifle2.Zero.Ammunition.Should().NotBeNull();
            rifle2.Zero.Ammunition.BallisticCoefficient.Should().Be(rifle.Zero.Ammunition.BallisticCoefficient);
            rifle2.Zero.Ammunition.Weight.Should().Be(rifle.Zero.Ammunition.Weight);
            rifle2.Zero.Ammunition.MuzzleVelocity.Should().Be(rifle.Zero.Ammunition.MuzzleVelocity);

            rifle2.Zero.Distance.Should().Be(rifle.Zero.Distance);

            rifle2.Zero.Atmosphere.Should().NotBeNull();
            rifle2.Zero.Atmosphere.Altitude.Should().Be(rifle.Zero.Atmosphere.Altitude);
            rifle2.Zero.Atmosphere.Pressure.Should().Be(rifle.Zero.Atmosphere.Pressure);
            rifle2.Zero.Atmosphere.Temperature.Should().Be(rifle.Zero.Atmosphere.Temperature);
            rifle2.Zero.Atmosphere.Humidity.Should().Be(rifle.Zero.Atmosphere.Humidity);
            rifle2.Zero.Atmosphere.SoundVelocity.Should().Be(rifle.Zero.Atmosphere.SoundVelocity);
            rifle2.Zero.Atmosphere.Density.Should().Be(rifle.Zero.Atmosphere.Density);
        }
        public void RoundTrip_Ammunition2()
        {
            Ammunition ammo = new Ammunition()
            {
                BallisticCoefficient = new BallisticCoefficient(0.295, DragTableId.G1),
                Weight         = new Measurement <WeightUnit>(9.1, WeightUnit.Gram),
                MuzzleVelocity = new Measurement <VelocityUnit>(2956.5, VelocityUnit.FeetPerSecond),
            };

            SerializerRoundtrip serializer = new SerializerRoundtrip();

            var node = serializer.Serialize(ammo);

            node.Should().NotBeNull();

            var ammo1 = serializer.Deserialize <Ammunition>(node);

            ammo1.Should().NotBeNull();

            ammo1.BallisticCoefficient.Should().Be(ammo.BallisticCoefficient);
            ammo1.Weight.Should().Be(ammo.Weight);
            ammo1.MuzzleVelocity.Should().Be(ammo.MuzzleVelocity);
            ammo1.BulletDiameter.Should().Be(ammo.BulletDiameter);
            ammo1.BulletLength.Should().Be(ammo.BulletLength);
        }
        public void TestTrajectoryPoint()
        {
            var point = new TrajectoryPoint(TimeSpan.FromMilliseconds(0.5),
                                            new Measurement <WeightUnit>(55, WeightUnit.Grain),
                                            new Measurement <DistanceUnit>(100, DistanceUnit.Yard),
                                            new Measurement <VelocityUnit>(2430, VelocityUnit.FeetPerSecond),
                                            2.15937,
                                            new Measurement <DistanceUnit>(1.54, DistanceUnit.Inch),
                                            new Measurement <DistanceUnit>(-2.55, DistanceUnit.Inch));

            point.OptimalGameWeight.In(WeightUnit.Pound).Should().BeApproximately(65, 0.5);
            point.DropAdjustment.Should().Be(new Measurement <AngularUnit>(1.54, AngularUnit.InchesPer100Yards));
            point.WindageAdjustment.Should().Be(new Measurement <AngularUnit>(-2.55, AngularUnit.InchesPer100Yards));

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml    = serializer.Serialize(point);
            var point2 = serializer.Deserialize <TrajectoryPoint>(xml);

            point2.Time.Should().Be(point.Time);
            point2.Distance.Should().Be(point.Distance);
            point2.Velocity.Should().Be(point.Velocity);
            point2.Mach.Should().Be(point.Mach);
            point2.Energy.Should().Be(point.Energy);
            point2.OptimalGameWeight.Should().Be(point.OptimalGameWeight);
            point2.Drop.Should().Be(point.Drop);
            point2.DropAdjustment.Should().Be(point.DropAdjustment);
            point2.Windage.Should().Be(point.Windage);
            point2.WindageAdjustment.Should().Be(point.WindageAdjustment);
        }
        public void RoundTripPath()
        {
            var path = new ReticlePath()
            {
                Fill      = true,
                Color     = "red",
                LineWidth = AngularUnit.MOA.New(5),
            };

            path.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition()
                {
                    X = AngularUnit.MOA.New(10), Y = AngularUnit.MOA.New(20)
                }
            });
            path.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition()
                {
                    X = AngularUnit.MOA.New(15), Y = AngularUnit.MOA.New(25)
                }
            });
            path.Elements.Add(new ReticlePathElementArc()
            {
                Position = new ReticlePosition()
                {
                    X = AngularUnit.MOA.New(25), Y = AngularUnit.MOA.New(35)
                },
                Radius             = AngularUnit.MOA.New(5),
                ClockwiseDirection = false,
                MajorArc           = false
            });

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml   = serializer.Serialize(path);
            var path2 = serializer.Deserialize <ReticlePath>(xml);

            path2.Should().NotBeNull();
            path2.Fill.Should().BeTrue();
            path2.Color.Should().Be("red");
            path2.LineWidth.Should().Be(AngularUnit.MOA.New(5));

            path2.Elements.Should().HaveCount(3);
            path2.Elements[0].ElementType.Should().Be(ReticlePathElementType.MoveTo);
            path2.Elements[0].As <ReticlePathElementMoveTo>().Position.X.Should().Be(AngularUnit.MOA.New(10));
            path2.Elements[0].As <ReticlePathElementMoveTo>().Position.Y.Should().Be(AngularUnit.MOA.New(20));

            path2.Elements[1].ElementType.Should().Be(ReticlePathElementType.LineTo);
            path2.Elements[1].As <ReticlePathElementLineTo>().Position.X.Should().Be(AngularUnit.MOA.New(15));
            path2.Elements[1].As <ReticlePathElementLineTo>().Position.Y.Should().Be(AngularUnit.MOA.New(25));

            path2.Elements[2].ElementType.Should().Be(ReticlePathElementType.Arc);
            path2.Elements[2].As <ReticlePathElementArc>().Position.X.Should().Be(AngularUnit.MOA.New(25));
            path2.Elements[2].As <ReticlePathElementArc>().Position.Y.Should().Be(AngularUnit.MOA.New(35));
            path2.Elements[2].As <ReticlePathElementArc>().Radius.Should().Be(AngularUnit.MOA.New(5));
            path2.Elements[2].As <ReticlePathElementArc>().ClockwiseDirection.Should().BeFalse();
            path2.Elements[2].As <ReticlePathElementArc>().MajorArc.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void SerializedXmlTest2()
        {
            SerializerRoundtrip serializer = new SerializerRoundtrip();

            MainClass main = new MainClass()
            {
                Name = "main name",
                Int  = 123,
                BallisticCoefficient = new BallisticCoefficient(0.345, DragTableId.G1),
                Real     = 1.234,
                Bool     = true,
                Length   = new Measurement <DistanceUnit>(1.23, DistanceUnit.Meter),
                TimeSpan = TimeSpan.FromMilliseconds(123.456),
                DateTime = new DateTime(2010, 5, 27, 11, 30, 25),
            };

            XmlElement element = serializer.Serialize(main);

            element.Should().NotBeNull();
            element.Name.Should().Be("main");
            element.Should().HaveAttribute("name", "main name");
            element.Attributes["subname"].Should().BeNull();

            element.Should().HaveAttribute("int", "123");
            element.Attributes["subint"].Should().BeNull();

            element.Should().HaveAttribute("coefficient", "0.345G1");
            element.Should().HaveAttribute("length", "1.23m");

            element.Should().HaveAttribute("real", "1.234");
            element.Should().HaveAttribute("bool", "true");

            element.Should().HaveAttribute("span", "123.456");
            element.Should().HaveAttribute("date", "2010-05-27 11:30:25");
            element.ChildNodes.Count.Should().Be(0);

            var main1 = serializer.Deserialize <MainClass>(element);

            main1.Should().NotBeNull();

            main1.Name.Should().Be("main name");
            main1.SubName.Should().BeNull();
            main1.Int.Should().Be(123);
            main1.SubInt.Should().BeNull();
            main1.Real.Should().Be(1.234);
            main1.Bool.Should().Be(true);
            main1.TimeSpan.TotalMilliseconds.Should().Be(123.456);
            main1.DateTime.Should().Be(new DateTime(2010, 5, 27, 11, 30, 25));
            main1.Length.Should().Be(new Measurement <DistanceUnit>(1.23, DistanceUnit.Meter));
            main1.BallisticCoefficient.Should().Be(new BallisticCoefficient(0.345, DragTableId.G1));

            main1.Child.Should().BeNull();
        }
        public void RoundTripWind2()
        {
            var wind = new Wind()
            {
                Direction = new Measurement <AngularUnit>(45, AngularUnit.Degree),
                Velocity  = new Measurement <VelocityUnit>(10, VelocityUnit.Knot),
            };

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml   = serializer.Serialize(wind);
            var wind2 = serializer.Deserialize <Wind>(xml);

            wind2.Direction.Should().Be(wind.Direction);
            wind2.Velocity.Should().Be(wind.Velocity);
            wind2.MaximumRange.Should().BeNull();
        }
        public void RoundTripBDC()
        {
            ReticleBulletDropCompensatorPoint bdc = new ReticleBulletDropCompensatorPoint()
            {
                Position = new ReticlePosition()
                {
                    X = new Measurement <AngularUnit>(1, AngularUnit.MOA), Y = new Measurement <AngularUnit>(2, AngularUnit.MOA)
                },
                TextOffset = new Measurement <AngularUnit>(5, AngularUnit.Mil)
            };

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml  = serializer.Serialize(bdc);
            var bdc2 = serializer.Deserialize <ReticleBulletDropCompensatorPoint>(xml);

            bdc2.Position.X.Should().Be(bdc.Position.X);
            bdc2.Position.Y.Should().Be(bdc.Position.Y);
            bdc2.TextOffset.Should().Be(bdc.TextOffset);
        }
        public void RoundTripAtmosphere()
        {
            var atmo = new Atmosphere(new Measurement <DistanceUnit>(123, DistanceUnit.Meter),
                                      new Measurement <PressureUnit>(30.02, PressureUnit.InchesOfMercury),
                                      new Measurement <TemperatureUnit>(16, TemperatureUnit.Celsius),
                                      0.57);

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml   = serializer.Serialize(atmo);
            var atmo2 = serializer.Deserialize <Atmosphere>(xml);

            atmo2.Should().NotBeNull();
            atmo2.Altitude.Should().Be(atmo.Altitude);
            atmo2.Pressure.Should().Be(atmo.Pressure);
            atmo2.Temperature.Should().Be(atmo.Temperature);
            atmo2.Humidity.Should().Be(atmo.Humidity);
            atmo2.SoundVelocity.Should().Be(atmo.SoundVelocity);
            atmo2.Density.Should().Be(atmo.Density);
        }
Exemplo n.º 9
0
        public void TestCollector2()
        {
            CollectorClass collector = new CollectorClass()
            {
                Array  = Array.Empty <ChildClass>(),
                List   = new List <ChildClass>(),
                Array2 = null,
            };

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml        = serializer.Serialize(collector);
            var collector2 = serializer.Deserialize <CollectorClass>(xml);

            collector2.Array.Should().NotBeNull();
            collector2.Array2.Should().BeNull();
            collector2.List.Should().NotBeNull();

            collector2.Array.Should().HaveCount(0);
            collector2.List.Should().HaveCount(0);
        }
Exemplo n.º 10
0
        public void TestCollector1()
        {
            CollectorClass collector = new CollectorClass()
            {
                Array = new ChildClass[] { new ChildClass("array1_1"), new ChildClass("array1_2") },
                List  = new List <ChildClass>()
                {
                    new ChildClass("list_1"), new ChildClass("list_2"), new ChildClass("list_3")
                },
                Array2 = new ChildClass[] { new ChildClass("array2_1"), new ChildClass("array2_2") },
            };

            collector.List1.AddRange(new ChildClass[] { new ChildClass("list1_1"), new ChildClass("list1_2"), new ChildClass("list1_3") });

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml        = serializer.Serialize(collector);
            var collector2 = serializer.Deserialize <CollectorClass>(xml);

            collector2.Array.Should().NotBeNull();
            collector2.Array2.Should().NotBeNull();
            collector2.List.Should().NotBeNull();
            collector2.List1.Should().NotBeNull();

            collector2.Array.Should().HaveCount(collector.Array.Length);
            collector2.Array2.Should().HaveCount(collector.Array2.Length);
            collector2.List.Should().HaveCount(collector.List.Count);

            collector2.Array[0].Name.Should().Be(collector.Array[0].Name);
            collector2.Array[1].Name.Should().Be(collector.Array[1].Name);

            collector2.Array2[0].Name.Should().Be(collector.Array2[0].Name);
            collector2.Array2[1].Name.Should().Be(collector.Array2[1].Name);

            collector2.List[0].Name.Should().Be(collector.List[0].Name);
            collector2.List[1].Name.Should().Be(collector.List[1].Name);
            collector2.List[2].Name.Should().Be(collector.List[2].Name);

            collector2.List1[0].Name.Should().Be(collector.List1[0].Name);
            collector2.List1[1].Name.Should().Be(collector.List1[1].Name);
            collector2.List1[2].Name.Should().Be(collector.List1[2].Name);
        }
        public void RoundTrip_AmmuntionLibraryEntry()
        {
            AmmunitionLibraryEntry entry = new AmmunitionLibraryEntry()
            {
                Name           = "Entry name",
                Source         = "Entry source",
                Caliber        = "Entry caliber",
                AmmunitionType = "BTHP",
                BarrelLength   = new Measurement <DistanceUnit>(410, DistanceUnit.Millimeter),
                Ammunition     = new Ammunition()
                {
                    BallisticCoefficient = new BallisticCoefficient(0.295, DragTableId.G1),
                    Weight         = new Measurement <WeightUnit>(9.1, WeightUnit.Gram),
                    MuzzleVelocity = new Measurement <VelocityUnit>(2956.5, VelocityUnit.FeetPerSecond),
                    BulletDiameter = new Measurement <DistanceUnit>(0.224, DistanceUnit.Inch),
                    BulletLength   = new Measurement <DistanceUnit>(0.98, DistanceUnit.Inch)
                }
            };

            SerializerRoundtrip serializer = new SerializerRoundtrip();

            var node = serializer.Serialize(entry);

            node.Should().NotBeNull();

            var entry1 = serializer.Deserialize <AmmunitionLibraryEntry>(node);

            entry1.Should().NotBeNull();

            entry1.Name.Should().Be(entry.Name);
            entry1.Source.Should().Be(entry.Source);
            entry1.Caliber.Should().Be(entry.Caliber);
            entry1.AmmunitionType.Should().Be(entry.AmmunitionType);
            entry1.BarrelLength.Should().Be(entry.BarrelLength);

            entry1.Ammunition.BallisticCoefficient.Should().Be(entry.Ammunition.BallisticCoefficient);
            entry1.Ammunition.Weight.Should().Be(entry.Ammunition.Weight);
            entry1.Ammunition.MuzzleVelocity.Should().Be(entry.Ammunition.MuzzleVelocity);
            entry1.Ammunition.BulletDiameter.Should().Be(entry.Ammunition.BulletDiameter);
            entry1.Ammunition.BulletLength.Should().Be(entry.Ammunition.BulletLength);
        }
Exemplo n.º 12
0
        public void FlatenningContainer()
        {
            FlatteningContainer container = new FlatteningContainer()
            {
                Value1 = new Implementation1()
                {
                    Name = "123"
                },
                Value2 = new Implementation2()
                {
                    ID = 456
                },
            };
            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml = serializer.Serialize(container);

            xml.ChildNodes.Count.Should().Be(0);
            var container2 = serializer.Deserialize <FlatteningContainer>(xml);

            container2.Value1.Name.Should().Be("123");
            container2.Value2.ID.Should().Be(456);
        }
Exemplo n.º 13
0
        public void TestSelect()
        {
            {
                var container = new InterfaceContainer()
                {
                    Property = new Implementation1()
                    {
                        Name = "Text1"
                    }
                };

                SerializerRoundtrip serializer = new SerializerRoundtrip();
                var xml        = serializer.Serialize(container);
                var container2 = serializer.Deserialize <InterfaceContainer>(xml);

                container2.Property.Should().NotBeNull();
                container2.Property.Should().BeOfType <Implementation1>();
                (container2.Property as Implementation1).Name.Should().Be("Text1");
            }

            {
                var container = new InterfaceContainer()
                {
                    Property = new Implementation2()
                    {
                        ID = 10
                    }
                };

                SerializerRoundtrip serializer = new SerializerRoundtrip();
                var xml        = serializer.Serialize(container);
                var container2 = serializer.Deserialize <InterfaceContainer>(xml);

                container2.Property.Should().NotBeNull();
                container2.Property.Should().BeOfType <Implementation2>();
                (container2.Property as Implementation2).ID.Should().Be(10);
            }

            {
                var container = new InterfaceContainer()
                {
                    Property = null
                };

                container.Elements.AddRange(new IClassInterface[]
                {
                    new Implementation1()
                    {
                        Name = "Item1"
                    },
                    new Implementation2()
                    {
                        ID = 1
                    },
                    new Implementation1()
                    {
                        Name = "Item2"
                    },
                    new Implementation2()
                    {
                        ID = 2
                    },
                });

                SerializerRoundtrip serializer = new SerializerRoundtrip();
                var xml        = serializer.Serialize(container);
                var container2 = serializer.Deserialize <InterfaceContainer>(xml);

                container2.Property.Should().BeNull();
                container2.Elements.Should().NotBeNull();
                container2.Elements.Should().HaveCount(4);
                container2.Elements[0].Should().BeOfType(typeof(Implementation1));
                (container2.Elements[0] as Implementation1).Name.Should().Be("Item1");
                container2.Elements[1].Should().BeOfType(typeof(Implementation2));
                (container2.Elements[1] as Implementation2).ID.Should().Be(1);
                container2.Elements[2].Should().BeOfType(typeof(Implementation1));
                (container2.Elements[2] as Implementation1).Name.Should().Be("Item2");
                container2.Elements[3].Should().BeOfType(typeof(Implementation2));
                (container2.Elements[3] as Implementation2).ID.Should().Be(2);
            }
        }
        public void RoundTripReticleElements()
        {
            var reticle = new ReticleDefinition()
            {
                Size = new ReticlePosition(150, 175, AngularUnit.MOA),
                Name = "Test Reticle",
                Zero = new ReticlePosition(75, 100, AngularUnit.MOA)
            };

            reticle.BulletDropCompensator.Add(new ReticleBulletDropCompensatorPoint()
            {
                Position   = new ReticlePosition(0, -5, AngularUnit.MOA),
                TextOffset = AngularUnit.MOA.New(2),
            });

            reticle.Elements.Add(new ReticleLine()
            {
                Start     = new ReticlePosition(1, 2, AngularUnit.Mil),
                End       = new ReticlePosition(3, 4, AngularUnit.Mil),
                Color     = "gray",
                LineWidth = AngularUnit.Mil.New(1.5),
            });

            reticle.Elements.Add(new ReticleRectangle()
            {
                TopLeft   = new ReticlePosition(7, 8, AngularUnit.Mil),
                Size      = new ReticlePosition(0.5, 0.75, AngularUnit.Mil),
                Color     = "gray",
                Fill      = true,
                LineWidth = AngularUnit.Mil.New(1.5),
            });

            reticle.Elements.Add(new ReticleText()
            {
                Position   = new ReticlePosition(0, -7, AngularUnit.MOA),
                Text       = "Text",
                Color      = "black",
                TextHeight = AngularUnit.MOA.New(1),
            });

            reticle.Elements.Add(new ReticleCircle()
            {
                Center    = new ReticlePosition(5, 6, AngularUnit.MOA),
                Radius    = AngularUnit.MOA.New(1.5),
                Fill      = false,
                LineWidth = AngularUnit.MOA.New(0.25),
                Color     = "black",
            });

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml      = serializer.Serialize(reticle);
            var reticle2 = serializer.Deserialize <ReticleDefinition>(xml);

            reticle2.Should().NotBeNull();
            reticle2.Name.Should().Be("Test Reticle");
            reticle2.Size.X.Should().Be(AngularUnit.MOA.New(150));
            reticle2.Size.Y.Should().Be(AngularUnit.MOA.New(175));
            reticle2.Zero.X.Should().Be(AngularUnit.MOA.New(75));
            reticle2.Zero.Y.Should().Be(AngularUnit.MOA.New(100));

            reticle2.BulletDropCompensator.Should().HaveCount(1);
            reticle2.BulletDropCompensator[0].Position.X.Should().Be(AngularUnit.MOA.New(0));
            reticle2.BulletDropCompensator[0].Position.Y.Should().Be(AngularUnit.MOA.New(-5));
            reticle2.BulletDropCompensator[0].TextOffset.Should().Be(AngularUnit.MOA.New(2));

            reticle2.Elements.Should().HaveCount(4);

            reticle2.Elements[0].ElementType.Should().Be(ReticleElementType.Line);

            reticle2.Elements[1].ElementType.Should().Be(ReticleElementType.Rectangle);

            reticle2.Elements[2].ElementType.Should().Be(ReticleElementType.Text);

            reticle2.Elements[3].ElementType.Should().Be(ReticleElementType.Circle);
        }