public void Test_InsertCar_IncorrectSector_ShouldReturnErrorMessage()
 {
     var park = new VehiclePark(2, 2);
     var car = new Car("CA1011AH", "John Smith", 1);
     string message = park.InsertCar(car, 10, 1, new DateTime(2015, 5, 10, 10, 30, 0));
     Assert.AreEqual("There is no sector 10 in the park", message);
 }
 public void Test_InsertCar_CorrectParameters_ShouldInsertTheCar()
 {
     var park = new VehiclePark(2, 2);
     var car = new Car("CA1011AH", "John Smith", 1);
     string message = park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
     Assert.AreEqual("Car parked successfully at place (1,1)", message);
 }
 public void Test_GetStatus_FullPark_SinglePlaceOnly_ShouldBeCorrect()
 {
     var park = new VehiclePark(1, 1);
     var car = new Car("CA1011AH", "John Smith", 1);
     park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
     string message = park.GetStatus();
     Assert.AreEqual("Sector 1: 1 / 1 (100% full)", message);
 }
 public void Test_ExitVehicle_InvalidLicensePlate_ShouldReturnErrorMessage()
 {
     var park = new VehiclePark(1, 2);
     var car = new Car("CA1011AH", "John Smith", 1);
     DateTime insertDate = new DateTime(2015, 5, 10, 10, 0, 0);
     string message = park.ExitVehicle("CA1011AH", insertDate.AddHours(2), 10.0M);
     Assert.AreEqual("There is no vehicle with license plate CA1011AH in the park", message);
 }
        public void Test_InsertCar_WithSameLicensePlate_ShouldReturnErrorMessage()
        {
            var park = new VehiclePark(2, 2);
            var car = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            var otherCar = new Car("CA1011AH", "Jane Smith", 1);
            string message = park.InsertCar(otherCar, 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_InsertCar_OccupiedPlace_ShouldReturnErrorMessage()
        {
            var park = new VehiclePark(2, 2);
            var car = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            var otherCar = new Car("CA1022AH", "Jane Smith", 1);
            string message = park.InsertCar(otherCar, 1, 1, new DateTime(2015, 5, 10, 12, 30, 0));
            Assert.AreEqual("The place (1,1) is occupied", message);
        }
Esempio n. 7
0
 private string ExecuteParkCarCommand(ICommand command)
 {
     var car = new Car(command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"]));
     string commandResult = this.VehiclePark.InsertCar(
         car,
         int.Parse(command.Parameters["sector"]),
         int.Parse(command.Parameters["place"]),
         DateTimeUtilities.ParseISODateTime(command.Parameters["time"]));
     return commandResult;
 }
        public void Test_InsertCar_FillPark_ShouldInsertAllCars()
        {
            var park = new VehiclePark(2, 1);
            var car = new Car("CA1011AH", "John Smith", 1);
            string message = park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            Assert.AreEqual("Car parked successfully at place (1,1)", message);

            var otherCar = new Car("CA1022AH", "Jane Smith", 1);
            message = park.InsertCar(otherCar, 2, 1, new DateTime(2015, 5, 10, 12, 30, 0));
            Assert.AreEqual("Car parked successfully at place (2,1)", message);
        }
        public void Test_FindVehiclesByOwner_NoVehiclesMatch_ShouldReturnErrorMessage()
        {
            var park = new VehiclePark(2, 2);
            var car = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA3035AH", "Jane Smith", 1);
            park.InsertCar(car, 2, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            string message = park.FindVehiclesByOwner("Jane Austen");
            Assert.AreEqual("No vehicles by Jane Austen", message);
        }
        public void Test_FindVehiclesByOwner_SingleVehicle_ShouldReturnTheVehicle()
        {
            var park = new VehiclePark(1, 1);
            var car = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            string message = park.FindVehiclesByOwner("John Smith");
            Assert.AreEqual(
                "Car [CA1011AH], owned by John Smith\r\n" +
                "Parked at (1,1)",
                message);
        }
Esempio n. 11
0
        public void Test_GetStatus_PartiallyFullPark_Big_ShouldBeCorrect()
        {
            var park = new VehiclePark(3, 3);
            var car = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA1012AH", "John Smith", 1);
            park.InsertCar(car, 2, 2, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA1013AH", "John Smith", 1);
            park.InsertCar(car, 2, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            string message = park.GetStatus();
            Assert.AreEqual(
                "Sector 1: 1 / 3 (33% full)\r\n" +
                "Sector 2: 2 / 3 (67% full)\r\n" +
                "Sector 3: 0 / 3 (0% full)",
                message);
        }
 public void Test_ExitVehicle_MoreTimeThanReserved_ShouldChargeOvertime()
 {
     var park = new VehiclePark(1, 2);
     var car = new Car("CA1011AH", "John Smith", 1);
     DateTime insertDate = new DateTime(2015, 5, 10, 10, 0, 0);
     park.InsertCar(car, 1, 1, insertDate);
     string message = park.ExitVehicle("CA1011AH", insertDate.AddHours(2), 10.0M);
     Assert.AreEqual(
         "********************\r\n" +
         "Car [CA1011AH], owned by John Smith\r\n" +
         "at place (1,1)\r\n" +
         "Rate: $2.00\r\n" +
         "Overtime rate: $3.50\r\n" +
         "--------------------\r\n" +
         "Total: $5.50\r\n" +
         "Paid: $10.00\r\n" +
         "Change: $4.50\r\n" +
         "********************",
         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);
        }
        public void Test_ExitVehicle_ShouldRemoveTheVehicle()
        {
            var park = new VehiclePark(1, 2);
            var car = new Car("CA1011AH", "John Smith", 1);
            DateTime insertDate = new DateTime(2015, 5, 10, 10, 30, 0);
            park.InsertCar(car, 1, 1, insertDate);
            park.ExitVehicle("CA1011AH", insertDate.AddHours(1), 10.0M);

            string message = park.GetStatus();
            Assert.AreEqual("Sector 1: 0 / 2 (0% full)", message);
        }