Ejemplo n.º 1
0
        public void Takeoff()
        {
            // Null argument exception should be thrown if vehicle is null.
            // Arrange.
            airport = new Airport(string.Empty, 10);
            // Assert.
            Assert.ThrowsException <ArgumentNullException>(() =>
            {
                // Act.
                airport.TakeOff(null);
            });

            // Verify message formatting for no planes able to takeoff.
            // Arrange.
            airport = new Airport(string.Empty, 10);
            // Act.
            string message = airport.AllTakeOff();

            // Assert.
            Assert.AreEqual($"No vehicles are at {airport} with code {airport.AirportCode}.", message);

            // Verify that all planes that have landed take off.
            // Arrange.
            airport = new Airport(string.Empty, 10);
            // Act.
            airport.Land(new Airplane(new Engine()));
            airport.Land(new AerialVehicle[]
            {
                new Helicopter(new Engine()), new Drone(new Engine())
            });
            message = airport.AllTakeOff();
            // Assert.
            Assert.AreEqual(3, message.Split(Environment.NewLine).Length);

            // Vehicles not at the airport should not be able to take off.
            // Arrange.
            airport = new Airport(string.Empty, 10);
            Drone drone = new Drone(new Engine());

            airport.Land(new AerialVehicle[]
            {
                new Helicopter(new Engine()), new Drone(new Engine())
            });
            // Act.
            message = airport.TakeOff(drone);
            Assert.AreEqual($"{drone} can't takeoff because it is not at this airport.", message);

            // Vehicles at the airport should be able to take off.
            // Arrange.
            airport = new Airport(string.Empty, 10);
            drone   = new Drone(new Engine());
            // Act.
            airport.Land(new AerialVehicle[]
            {
                new Helicopter(new Engine()), drone, new Drone(new Engine())
            });
            message = airport.TakeOff(drone);
            // Assert.
            Assert.AreNotEqual($"{drone} can't takeoff because it is not at this airport.", message);
        }
        public void TestAirport()
        {
            // Arrange
            terminal = new Airport("115");
            boeing   = new Airplane();
            apache   = new Helicopter();
            uav      = new Drone();
            toy      = new ToyPlane();

            List <AerialVehicle> testVehicles = new List <AerialVehicle>()
            {
                boeing,
                apache,
                uav,
                toy
            };

            // Act
            boeing.StartEngine();
            boeing.TakeOff();
            boeing.FlyUp();
            foreach (AerialVehicle a in testVehicles)
            {
                a.StartEngine();
                a.TakeOff();
                a.FlyUp();
            }


            string landPlane    = terminal.Land(boeing);
            string landVehicles = terminal.Land(testVehicles);
            string takeoffPlane = terminal.TakeOff(boeing);
            string takeoffAll   = terminal.AllTakeOff();



            // Assert
            Assert.AreEqual(terminal.AirportCode, "115");
            Assert.AreEqual(terminal.MaxVehicles, 5);
            Assert.AreEqual(takeoffPlane, boeing.ToString() + " has taken off. ");
            Assert.AreEqual(takeoffAll, testVehicles[0].ToString() + " has taken off. " + testVehicles[1].ToString() + " has taken off. " +
                            testVehicles[2].ToString() + " has taken off. " + testVehicles[3].ToString() + " has taken off. ");
            Assert.AreEqual(landPlane, boeing.ToString() + " has landed. ");
            Assert.AreEqual(landVehicles, testVehicles[0].ToString() + " has landed. " + testVehicles[1].ToString() + " has landed. " +
                            testVehicles[2].ToString() + " has landed. " + testVehicles[3].ToString() + " has landed. ");


            terminal = new Airport("ORD", 48);
            Assert.AreEqual("ORD", terminal.AirportCode);
            Assert.AreEqual(48, terminal.MaxVehicles);
        }