public void TestUnload() { Port.Model.Port port = new Port.Model.Port("Port", 1000); Ship ship = new Ship("Ship", port); port.Unload(ship); Assert.IsTrue(port.InPort.Contains(ship)); }
public void TestSum() { Port.Model.Port port = new Port.Model.Port("Port", 1000); Route route = new Route(port); route.Sum(123456); Assert.AreEqual(123456, route.Sums); }
public void TestShipDepartures() { Port.Model.Port port = new Port.Model.Port("Port", 1000); Ship ship = new Ship("Ship", port); port.ShipDepartures(ship); Assert.IsFalse(port.InPort.Contains(ship)); }
public void TestShipArrives() { Port.Model.Port port1 = new Port.Model.Port("Port1", 1000); Port.Model.Port port2 = new Port.Model.Port("Port2", 2000); Ship ship = new Ship("Ship", port1); port2.ShipArrives(ship); Assert.IsTrue(port2.InPort.Contains(ship)); }
public void TestFill() { Port.Model.Port port = new Port.Model.Port("Port", 1000); Ship ship = new Ship("Ship", port); Fuel fuel = new Fuel(45); ship.Fill(fuel); Assert.AreEqual(fuel, ship.Fuel); }
public void TestLoad() { Port.Model.Port port = new Port.Model.Port("Port", 1000); Ship ship = new Ship("Ship", port); var cargo = new Cargo(100000); ship.Load(cargo); Assert.IsTrue(ship.Cargos.Contains(cargo)); }
public void TestSetDeparture() { Port.Model.Port port1 = new Port.Model.Port("Port1", 1000); Port.Model.Port port2 = new Port.Model.Port("Port2", 2000); Route route = new Route(port1); route.SetDeparture(port2); Assert.AreEqual(port2, route.Departure); }
public void TestSetRoute() { Port.Model.Port port1 = new Port.Model.Port("Port1", 1000); Port.Model.Port port2 = new Port.Model.Port("Port2", 2000); Ship ship = new Ship("Ship", port1); Route route = new Route(port2); ship.SetRoute(route); Assert.AreEqual(route, ship.Route); }
public void TestRemoveRoute() { Port.Model.Port port1 = new Port.Model.Port("Port1", 1000); Port.Model.Port port2 = new Port.Model.Port("Port2", 2000); Ship ship = new Ship("Ship", port1); Route route = new Route(port2); ship.SetRoute(route); ship.RemoveRoute(); Assert.IsNull(ship.Route); }
public void TestCost() { Port.Model.Port port1 = new Port.Model.Port("Port1", 1000); Port.Model.Port port2 = new Port.Model.Port("Port2", 2000); Route route = new Route(port1); route.SetDeparture(port2); Fuel fuel = new Fuel(45); route.Cost(fuel); Assert.AreEqual(45000, route.Costs); }
public void TestSend() { Port.Model.Port port1 = new Port.Model.Port("Port1", 1000); Port.Model.Port port2 = new Port.Model.Port("Port2", 2000); Route route = new Route(port2); Fuel fuel = new Fuel(45); Ship ship = new Ship("Ship", port1); ship.SetRoute(route); ship.Fill(fuel); ship.Send(); Assert.AreEqual(port2, ship.Port); }
public void TestReady() { Port.Model.Port port1 = new Port.Model.Port("Port1", 1000); Port.Model.Port port2 = new Port.Model.Port("Port2", 2000); Ship ship = new Ship("Ship", port1); Fuel fuel = new Fuel(45); ship.Fill(fuel); Route route = new Route(port2); ship.SetRoute(route); Assert.IsTrue(ship.Ready()); }
static void Main(string[] args) { Console.WriteLine("Создаём порт Новороссийск"); var novorossiysk = new Model.Port("Новороссийск", 1000); Console.WriteLine("Создаём порт Усть-Луга"); var ustluga = new Model.Port("Усть-Луга", 2000); Console.WriteLine("Создаём дизельное топливо"); var diesel = new Fuel(50); Console.WriteLine("Создаём грузы"); var cargo1 = new Cargo(100000); var cargo2 = new Cargo(120000); var cargo3 = new Cargo(350000); var cargo4 = new Cargo(160000); var cargo5 = new Cargo(140000); var cargo6 = new Cargo(170000); var cargo7 = new Cargo(150000); var cargo8 = new Cargo(150000); Console.WriteLine("Создаём корабль Труженник"); var worker = new Ship("Труженник", novorossiysk); Console.WriteLine("Заправляем Труженника"); worker.Fill(diesel); Console.WriteLine("Загружаем Труженника"); worker.Load(cargo1); worker.Load(cargo2); worker.Load(cargo3); worker.Load(cargo4); Console.WriteLine("Создаём маршрут для Труженника"); var routeForWorker = new Route(ustluga); worker.SetRoute(routeForWorker); Console.WriteLine("Отправляем Труженника по маршруту"); try { worker.Send(); Console.WriteLine("Проверяем какие корабли находятся в порту Усть-Луга"); foreach (var s in ustluga.InPort) { Console.WriteLine(s.Title); } Console.WriteLine("Выводим стоимости маршрутов корабля Труженник"); foreach (var r in worker.Routes) { Console.WriteLine($"{r.Departure.Title}-{r.Arrival.Title} стоимость {r.Costs}"); Console.WriteLine($"Стоимость грузов {r.Sums}"); } } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } Console.WriteLine("Создаём корабль Большой"); var big = new Ship("Большой", ustluga); /*Console.WriteLine("Заправляем Большого"); * big.Fill(diesel);*/ Console.WriteLine("Загружаем Большого"); big.Load(cargo5); big.Load(cargo6); big.Load(cargo7); big.Load(cargo8); Console.WriteLine("Создаём маршрут для Большого"); var routeForBig = new Route(novorossiysk); big.SetRoute(routeForBig); Console.WriteLine("Отправляем Большого по маршруту"); try { big.Send(); Console.WriteLine("Проверяем какие корабли находятся в порту Новороссийск"); foreach (var s in novorossiysk.InPort) { Console.WriteLine(s.Title); } Console.WriteLine("Выводим стоимости маршрутов корабля Большой"); foreach (var r in big.Routes) { Console.WriteLine($"{r.Departure.Title}-{r.Arrival.Title} стоимость {r.Costs}"); Console.WriteLine($"Стоимость грузов {r.Sums}"); } } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } XmlSerializer formatter = new XmlSerializer(typeof(Fuel)); using (FileStream fs = new FileStream("fuel.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs, diesel); Console.WriteLine("Объект сериализован"); } using (FileStream fs = new FileStream("fuel.xml", FileMode.OpenOrCreate)) { Fuel newDiesel = (Fuel)formatter.Deserialize(fs); Console.WriteLine("Объект десериализован"); Console.WriteLine("Цена: {0}", newDiesel.Cost); } BinaryFormatter bformatter = new BinaryFormatter(); using (FileStream fs = new FileStream("ship.dat", FileMode.OpenOrCreate)) { bformatter.Serialize(fs, worker); Console.WriteLine("Объект сериализован"); } using (FileStream fs = new FileStream("ship.dat", FileMode.OpenOrCreate)) { Ship newWorker = (Ship)bformatter.Deserialize(fs); Console.WriteLine("Объект десериализован"); Console.WriteLine("Название корабля: {0}, порт: {1}", newWorker.Title, newWorker.Port.Title); } }