public void Test_FindVehiclesByOwner_SomeVehiclesMatch_ShouldSortCorrectly()
        {
            var park  = new VehiclePark(3, 3);
            var first = new Car("CA1011AH", "John Smith", 1);

            park.InsertCar(first, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            var second = new Truck("CA2022AH", "John Smith", 1);

            park.InsertTruck(second, 1, 2, new DateTime(2015, 5, 10, 11, 30, 0));
            var third = new Truck("CA9999AH", "John Smith", 1);

            park.InsertTruck(third, 2, 1, new DateTime(2015, 5, 8, 11, 30, 0));
            var fourth = new Motorbike("CA1111AH", "John Smith", 1);

            park.InsertMotorbike(fourth, 2, 2, new DateTime(2015, 5, 8, 11, 30, 0));

            string message = park.FindVehiclesByOwner("John Smith");

            Assert.AreEqual(
                "Motorbike [CA1111AH], owned by John Smith\r\n" +
                "Parked at (2,2)\r\n" +
                "Truck [CA9999AH], owned by John Smith\r\n" +
                "Parked at (2,1)\r\n" +
                "Car [CA1011AH], owned by John Smith\r\n" +
                "Parked at (1,1)\r\n" +
                "Truck [CA2022AH], owned by John Smith\r\n" +
                "Parked at (1,2)",
                message);
        }
Exemplo n.º 2
0
        public void Test_InsertTruck_WithSameLicensePlate_ShouldReturnErrorMessage()
        {
            var park = new VehiclePark(2, 2);
            var truck = new Truck("CA1011AH", "John Smith", 1);
            park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            var otherTruck = new Truck("CA1011AH", "Jane Smith", 1);
            var message = park.InsertTruck(otherTruck, 1, 2, new DateTime(2015, 5, 10, 12, 30, 0));
            Assert.AreEqual("There is already a vehicle with license plate CA1011AH in the park", message);
        }
Exemplo n.º 3
0
        public void Test_InsertTruck_OccupiedPlace_ShouldReturnErrorMessage()
        {
            var park = new VehiclePark(2, 2);
            var truck = new Truck("CA1011AH", "John Smith", 1);
            park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            var othertruck = new Truck("CA1022AH", "Jane Smith", 1);
            var message = park.InsertTruck(othertruck, 1, 1, new DateTime(2015, 5, 10, 12, 30, 0));
            Assert.AreEqual("The place (1,1) is occupied", message);
        }
Exemplo n.º 4
0
        public void Test_InsertTruck_FillPark_ShouldInsertAllTrucks()
        {
            var park = new VehiclePark(2, 1);
            var truck = new Truck("CA1011AH", "John Smith", 1);
            var message = park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            Assert.AreEqual("Truck parked successfully at place (1,1)", message);

            var otherTruck = new Truck("CA1022AH", "Jane Smith", 1);
            message = park.InsertTruck(otherTruck, 2, 1, new DateTime(2015, 5, 10, 12, 30, 0));
            Assert.AreEqual("Truck parked successfully at place (2,1)", message);
        }
        public void Test_InsertTruck_WithSameLicensePlate_ShouldReturnErrorMessage()
        {
            var park  = new VehiclePark(2, 2);
            var truck = new Truck("CA1011AH", "John Smith", 1);

            park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            var    otherTruck = new Truck("CA1011AH", "Jane Smith", 1);
            string message    = park.InsertTruck(otherTruck, 1, 2, new DateTime(2015, 5, 10, 12, 30, 0));

            Assert.AreEqual("There is already a vehicle with license plate CA1011AH in the park", message);
        }
        public void Test_InsertTruck_OccupiedPlace_ShouldReturnErrorMessage()
        {
            var park  = new VehiclePark(2, 2);
            var truck = new Truck("CA1011AH", "John Smith", 1);

            park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            var    othertruck = new Truck("CA1022AH", "Jane Smith", 1);
            string message    = park.InsertTruck(othertruck, 1, 1, new DateTime(2015, 5, 10, 12, 30, 0));

            Assert.AreEqual("The place (1,1) is occupied", message);
        }
        public void Test_InsertTruck_FillPark_ShouldInsertAllTrucks()
        {
            var    park    = new VehiclePark(2, 1);
            var    truck   = new Truck("CA1011AH", "John Smith", 1);
            string message = park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            Assert.AreEqual("Truck parked successfully at place (1,1)", message);

            var otherTruck = new Truck("CA1022AH", "Jane Smith", 1);

            message = park.InsertTruck(otherTruck, 2, 1, new DateTime(2015, 5, 10, 12, 30, 0));
            Assert.AreEqual("Truck parked successfully at place (2,1)", message);
        }
Exemplo n.º 8
0
 public void Test_InsertTruck_IncorrectPlace_ShouldReturnErrorMessage()
 {
     var park = new VehiclePark(2, 2);
     var truck = new Truck("CA1011AH", "John Smith", 1);
     var message = park.InsertTruck(truck, 1, 10, new DateTime(2015, 5, 10, 10, 30, 0));
     Assert.AreEqual("There is no place 10 in sector 1", message);
 }
Exemplo n.º 9
0
 public void Test_InsertTruck_CorrectParameters_ShouldInsertTheTruck()
 {
     var park = new VehiclePark(2, 2);
     var truck = new Truck("CA1011AH", "John Smith", 1);
     var message = park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
     Assert.AreEqual("Truck parked successfully at place (1,1)", message);
 }
Exemplo n.º 10
0
        public string[] Execute(VehiclePark vehiclePark)
        {
            switch (Parameters["type"])
            {
            case "car":
                return(vehiclePark.InsertCar(
                           new Car(Parameters["licensePlate"],
                                   Parameters["owner"],
                                   Convert.ToInt32(Parameters["hours"])),
                           Convert.ToInt32(Parameters["sector"]),
                           Convert.ToInt32(Parameters["place"]),
                           Convert.ToDateTime(Parameters["time"])));

            case "motorbike":
                return(vehiclePark.InsertMotorbike(
                           new Motorbike(Parameters["licensePlate"],
                                         Parameters["owner"],
                                         Convert.ToInt32(Parameters["hours"])),
                           Convert.ToInt32(Parameters["sector"]),
                           Convert.ToInt32(Parameters["place"]),
                           Convert.ToDateTime(Parameters["time"])));

            case "truck":
                return(vehiclePark.InsertTruck(
                           new Truck(Parameters["licensePlate"],
                                     Parameters["owner"],
                                     Convert.ToInt32(Parameters["hours"])),
                           Convert.ToInt32(Parameters["sector"]),
                           Convert.ToInt32(Parameters["place"]),
                           Convert.ToDateTime(Parameters["time"])));

            default:
                return(new [] { "There is no such type vehicle" });
            }
        }
        public void Test_InsertTruck_IncorrectPlace_ShouldReturnErrorMessage()
        {
            var    park    = new VehiclePark(2, 2);
            var    truck   = new Truck("CA1011AH", "John Smith", 1);
            string message = park.InsertTruck(truck, 1, 10, new DateTime(2015, 5, 10, 10, 30, 0));

            Assert.AreEqual("There is no place 10 in sector 1", message);
        }
        public void Test_InsertTruck_CorrectParameters_ShouldInsertTheTruck()
        {
            var    park    = new VehiclePark(2, 2);
            var    truck   = new Truck("CA1011AH", "John Smith", 1);
            string message = park.InsertTruck(truck, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            Assert.AreEqual("Truck parked successfully at place (1,1)", message);
        }
        public void Test_FindVehiclesByOwner_SomeVehiclesMatch_ShouldSortCorrectly()
        {
            var park = new VehiclePark(3, 3);
            var first = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(first, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            var second = new Truck("CA2022AH", "John Smith", 1);
            park.InsertTruck(second, 1, 2, new DateTime(2015, 5, 10, 11, 30, 0));
            var third = new Truck("CA9999AH", "John Smith", 1);
            park.InsertTruck(third, 2, 1, new DateTime(2015, 5, 8, 11, 30, 0));
            var fourth = new Motorbike("CA1111AH", "John Smith", 1);
            park.InsertMotorbike(fourth, 2, 2, new DateTime(2015, 5, 8, 11, 30, 0));

            string message = park.FindVehiclesByOwner("John Smith");
            Assert.AreEqual(
                "Motorbike [CA1111AH], owned by John Smith\r\n" +
                "Parked at (2,2)\r\n" +
                "Truck [CA9999AH], owned by John Smith\r\n" +
                "Parked at (2,1)\r\n" +
                "Car [CA1011AH], owned by John Smith\r\n" +
                "Parked at (1,1)\r\n" +
                "Truck [CA2022AH], owned by John Smith\r\n" +
                "Parked at (1,2)",
                message);
        }
Exemplo n.º 14
0
        public void TestPartialyFullPark()
        {
            IVehiclePark vehiclePark  = new VehiclePark(1, 3);
            var          firstVehicle = new Car("CA1001HH", "Jay Margareta", 1);

            vehiclePark.InsertCar(firstVehicle, 1, 1, new DateTime(2015, 05, 04, 10, 30, 00));
            var thirdVehicle = new Truck("C5842CH", "Jessie Raul", 5);

            vehiclePark.InsertTruck(thirdVehicle, 1, 3, new DateTime(2015, 05, 04, 10, 50, 00));
            string message = vehiclePark.GetStatus();

            var result = new StringBuilder();

            result.Append("Sector 1: 2 / 3 (67% full)");

            Assert.AreEqual(result.ToString(), message);
        }
Exemplo n.º 15
0
        public string Execute(ICommand command)
        {
            if (command.Name != "SetupPark" && VehiclePark == null)
            {
                return("The vehicle park has not been set up");
            }

            var parameters = command.Parameters;

            switch (command.Name)
            {
            case "SetupPark":
                if (int.Parse(parameters["sectors"]) < 0)
                {
                    return("The number of sectors must be positive");
                }

                if (int.Parse(parameters["placesPerSector"]) < 0)
                {
                    return("The number of places per sector must be positive");
                }

                this.VehiclePark = new VehiclePark(
                    int.Parse(parameters["sectors"]),
                    int.Parse(parameters["placesPerSector"]));
                return("Vehicle park created");

            case "Park":
                string   licensePlate  = parameters["licensePlate"];
                string   owner         = parameters["owner"];
                int      reservedHours = int.Parse(parameters["hours"]);
                int      sector        = int.Parse(parameters["sector"]);
                int      place         = int.Parse(parameters["place"]);
                DateTime dateTime      = DateTime.Parse(
                    parameters["time"],
                    null,
                    System.Globalization.DateTimeStyles.RoundtripKind);

                switch (command.Parameters["type"])
                {
                case "car":
                    return(VehiclePark.InsertCar(
                               new Car(licensePlate, owner, reservedHours),
                               sector,
                               place,
                               dateTime));

                case "motorbike":
                    return(VehiclePark.InsertMotorbike(
                               new Motorbike(licensePlate, owner, reservedHours),
                               sector,
                               place,
                               dateTime));

                case "truck":
                    return(VehiclePark.InsertTruck(
                               new Truck(licensePlate, owner, reservedHours),
                               sector,
                               place,
                               dateTime));
                }

                break;

            case "Exit":
                return(VehiclePark.ExitVehicle(
                           parameters["licensePlate"],
                           DateTime.Parse(parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind),
                           decimal.Parse(parameters["paid"])));

            case "Status":
                return(VehiclePark.GetStatus());

            case "FindVehicle":
                return(VehiclePark.FindVehicle(
                           parameters["licensePlate"]));

            case "VehiclesByOwner":
                return(VehiclePark.FindVehiclesByOwner(
                           parameters["owner"]));

            default:
                throw new IndexOutOfRangeException("Invalid command.");
            }

            return(string.Empty);
        }