예제 #1
0
파일: ShipTests.cs 프로젝트: Swiftey63/EDDI
        public void TestShipMonitorDeserialization()
        {
            // Read from our test item "shipMonitor.json"
            ShipMonitorConfiguration configuration = new ShipMonitorConfiguration();

            try
            {
                string data = System.IO.File.ReadAllText("shipMonitor.json");
                if (data != null)
                {
                    configuration = JsonConvert.DeserializeObject <ShipMonitorConfiguration>(data);
                }
            }
            catch (Exception)
            {
                Assert.Fail("Failed to read ship configuration");
            }

            // Start a ship monitor
            ShipMonitor shipMonitor   = new ShipMonitor();
            var         privateObject = new PrivateObject(shipMonitor);

            // Build a new shipyard
            List <Ship> newShiplist = configuration.shipyard.OrderBy(s => s.model).ToList();

            // Update the shipyard
            privateObject.SetFieldOrProperty("shipyard", new ObservableCollection <Ship>(newShiplist));
            privateObject.SetFieldOrProperty("updateDat", DateTime.MinValue);

            shipMonitor.SetCurrentShip(configuration.currentshipid);
            Assert.AreEqual(81, shipMonitor.GetCurrentShip().LocalId);

            Ship ship1 = shipMonitor.GetShip(0);
            Ship ship2 = shipMonitor.GetShip(81);

            Assert.IsNotNull(ship1);
            Assert.AreEqual("Cobra Mk. III", ship1.model);
            Assert.AreEqual(0, ship1.LocalId);
            Assert.AreEqual("The Dynamo", ship1.name);
            Assert.AreEqual("Laksak", ship1.starsystem);
            Assert.AreEqual("Stjepan Seljan Hub", ship1.station);
            Assert.AreEqual(8605684, ship1.value);

            Assert.IsNotNull(ship2);
            Assert.AreEqual("Krait Mk. II", ship2.model);
            Assert.AreEqual(81, ship2.LocalId);
            Assert.AreEqual("The Impact Kraiter", ship2.name);
            Assert.AreEqual(16, ship2.cargocapacity);
            Assert.AreEqual(8, ship2.compartments.Count());
            Assert.AreEqual("Slot01_Size6", ship2.compartments[0].name);
            Assert.AreEqual(6, ship2.compartments[0].size);
            Assert.IsNotNull(ship2.compartments[0].module);
            Assert.AreEqual("Int_ShieldGenerator_Size6_Class3_Fast", ship2.compartments[0].module.EDName);
            Assert.AreEqual("Bi-Weave Shield Generator", ship2.compartments[0].module.invariantName);
            Assert.AreEqual("SRV", ship2.launchbays[0].type);
            Assert.AreEqual(2, ship2.launchbays[0].vehicles.Count());
        }
예제 #2
0
        public void TestShipMonitorDeserializationDoesntMutateStatics()
        {
            // Read from our test item "shipMonitor.json"
            ShipMonitorConfiguration configuration = new ShipMonitorConfiguration();

            try
            {
                string data = System.IO.File.ReadAllText("shipMonitor.json");
                if (data != null)
                {
                    configuration = JsonConvert.DeserializeObject <ShipMonitorConfiguration>(data);
                }
            }
            catch (Exception)
            {
                Assert.Fail("Failed to read ship configuration");
            }

            Assert.AreEqual("Multipurpose", Role.MultiPurpose.edname);
        }