public void ExitVehicleWithExistingLicensePlateWithoutOvertime() { string expectedResult = "********************\r\nCar [ЕН7697ВН], owned by Dinko Todorov\r\nat place (3,3)\r\nRate: $6.00\r\nOvertime rate: $0.00\r\n--------------------\r\nTotal: $6.00\r\nPaid: $10.00\r\nChange: $4.00\r\n********************"; string result = park.ExitVehicle("ЕН7697ВН", exitDate, paid); Assert.AreEqual(expectedResult, result); }
public void Test_ExitVehicle_AlreadyExited_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); park.InsertCar(car, 1, 1, insertDate); park.ExitVehicle("CA1011AH", insertDate.AddHours(2), 10.0M); 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_ExitVehicle_AlreadyExited_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); park.InsertCar(car, 1, 1, insertDate); park.ExitVehicle("CA1011AH", insertDate.AddHours(2), 10.0M); 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 VehicleExitNonPresentLicensePlate_ShouldThrowExceptionWithCorrectResult() { // Arrange IVehiclePark park = new VehiclePark(2, 2); string licensePlate = "CA1234CA"; IVehicle car = new Car(licensePlate, "Pesho", 3); int sector = 1; int place = 1; // Act park.InsertVehicle(car, sector, place, new DateTime(2015, 10, 17, 10, 30, 0)); string result = string.Empty; try { park.ExitVehicle("CA1234CB", new DateTime(2015, 10, 17, 13, 30, 0), 6M); } catch (Exception ex) { result = ex.Message; } string expected = string.Format(GlobalMessages.VehicleNotPresent, "CA1234CB"); // Assert Assert.AreEqual(expected, result); }
public void TestAVehicleExitWithIncorrectLisenceplateShouldReturnAnErrorMessage() { IVehiclePark vehiclePark = new VehiclePark(3, 5); var vehicle = new Car("CA1001HH", "Jay Margareta", 1); vehiclePark.InsertCar(vehicle, 1, 5, new DateTime(2015, 05, 04, 10, 30, 00)); string message = vehiclePark.ExitVehicle("CA1101HH", new DateTime(2015, 05, 04, 13, 30, 00), 40m); Assert.AreEqual("There is no vehicle with license plate CA1101HH in the park", message); }
public void TestExitNonExistingVehicle() { // Arrange DateTime nowTime = DateTime.Now; VehiclePark vehiclePark = new VehiclePark(new Layout(10, 20, new Database(10))); // Act string message = vehiclePark.ExitVehicle("CA1001HH", 50, nowTime.AddHours(1)); // Assert Assert.AreEqual("There is no vehicle with license plate CA1001HH in the park", 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); }
public void VehicleExitExactlyOnTime_ShouldReturnCorrectResult() { // Arrange IVehiclePark park = new VehiclePark(2, 2); string licensePlate = "CA1234CA"; IVehicle car = new Car(licensePlate, "Pesho", 3); int sector = 1; int place = 1; // Act park.InsertVehicle(car, sector, place, new DateTime(2015, 10, 17, 10, 30, 0)); string result = park.ExitVehicle(licensePlate, new DateTime(2015, 10, 17, 13, 30, 0), 6M); string expected = "********************\r\nCar [CA1234CA], owned by Pesho\nat place (1,1)\nRate: $6,00\nOvertime rate: $0,00\r\n--------------------\r\nTotal: $6,00\nPaid: $6,00\nChange: $0,00\r\n********************"; // Assert Assert.AreEqual(expected, result); }
public void TestExitVehicleSuccess() { // Arrange DateTime nowTime = DateTime.Now; VehiclePark vehiclePark = new VehiclePark(new Layout(10, 20, new Database(10))); Car vehicle = new Car("CA1001HH", "Endi", 1); vehiclePark.InsertCar(vehicle, 5, 5, nowTime.AddHours(-2)); var parkedVehicle = vehiclePark.Layout.Database.VehiclesInPark["CA1001HH"]; Ticket expectedTicket = new Ticket(parkedVehicle, nowTime.AddHours(1), 50); // Act string actualTicketString = vehiclePark.ExitVehicle("CA1001HH", 50, nowTime.AddHours(1)); // Assert Assert.AreEqual(expectedTicket.ToString(), actualTicketString); Assert.IsFalse(vehiclePark.Layout.IsSpotFilled(5, 5)); Assert.IsFalse(vehiclePark.Layout.Database.VehiclesInPark.ContainsKey("CA1001HH")); Assert.IsFalse(vehiclePark.Layout.Database.OwnerVehicles.ContainsKey("Endi"), "Endi still exists in the database"); }
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_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 TestAVehicleExitSuccessWithLessThanTheStayingHoursShouldReturnAnExitTicketWithFullHoursPaid() { IVehiclePark vehiclePark = new VehiclePark(3, 5); var vehicle = new Car("CA1001HH", "Jay Margareta", 1); vehiclePark.InsertCar(vehicle, 1, 5, new DateTime(2015, 05, 04, 10, 30, 00)); string message = vehiclePark.ExitVehicle("CA1001HH", new DateTime(2015, 05, 04, 10, 50, 00), 40m); var ticket = new StringBuilder(); ticket.AppendLine("********************") .AppendLine("Car [CA1001HH], owned by Jay Margareta") .AppendLine("at place (1,5)") .AppendLine("Rate: $2.00") .AppendLine("Overtime rate: $0.00") .AppendLine("--------------------") .AppendLine("Total: $2.00") .AppendLine("Paid: $40.00") .AppendLine("Change: $38.00") .Append("********************"); Assert.AreEqual(ticket.ToString(), 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); }
public string Execution(ICommand command) { if (command.Name != "SetupPark" && VehiclePark == null) { return "The vehicle park has not been set up"; } switch (command.Name) { //SetupPark {"sectors": 3, "placesPerSector": 5} case "SetupPark": { int iniciatedSectors = int.Parse(command.Parameters["sectors"]); int initiatedPlacesPerSector = int.Parse(command.Parameters["placesPerSector"]); if (iniciatedSectors <= 0) { return "The number of sectors must be positive"; } if (initiatedPlacesPerSector <= 0) { return "The number of places per sector must be positive"; } this.VehiclePark = new VehiclePark(iniciatedSectors, initiatedPlacesPerSector); return "Vehicle park created"; break; } case "Park": { switch (command.Parameters["type"]) { case "car": { return this.ExecuteParkCar(command); break; } case "motorbike": { return ExecuteParkMotorbike(command); break; } case "truck": { return ExecuteParkTruck(command); break; } default: throw new IndexOutOfRangeException("Invalid command inside."); } break; } case "Exit": { return VehiclePark.ExitVehicle( command.Parameters["licensePlate"], DateTime.Parse(command.Parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind), decimal.Parse(command.Parameters["paid"])); break; } case "Status": { return VehiclePark.GetStatus(); break; } case "FindVehicle": { return VehiclePark.FindVehicle(command.Parameters["licensePlate"]); break; } case "VehiclesByOwner": { return VehiclePark.FindVehiclesByOwner(command.Parameters["owner"]); break; } default: throw new IndexOutOfRangeException("Invalid command."); } }
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); }
public string[] Execute(VehiclePark current) { return(current.ExitVehicle(Parameters["licensePlate"], DataTimeUtilities.ParseISODateTime(Parameters["time"]), Convert.ToDecimal(Parameters["paid"]))); }