public string ExcecuteCommand(ref IVehiclePark vehiclePark) { try { this.ValidateEnvironment(vehiclePark); } catch (InvalidOperationException ex) { return(ex.Message); } if (this.Vehicle.GetType().Equals(typeof(Car))) { // Vehicle is a car return(vehiclePark.InsertCar(this.Vehicle as Car, this.Sector, this.Spot, this.EntryTime)); } else if (this.Vehicle.GetType().Equals(typeof(Motorbike))) { // Vehicle is a motorbike return(vehiclePark.InsertMotorbike(this.Vehicle as Motorbike, this.Sector, this.Spot, this.EntryTime)); } else { // Vehicle is a truck return(vehiclePark.InsertTruck(this.Vehicle as Truck, this.Sector, this.Spot, this.EntryTime)); } }
protected void ValidateEnvironment(IVehiclePark vehiclePark) { if (this.Name != "SetupPark" && vehiclePark == null) { throw new InvalidOperationException("The vehicle park has not been set up"); } }
public string Execute(ICommand command) { if (command.Name != "SetupPark" && this.VehiclePark == null) { return "The vehicle park has not been set up"; } switch (command.Name) { case "SetupPark": int sectors = int.Parse(command.Parameters["sectors"]); int placesPerSector = int.Parse(command.Parameters["placesPerSector"]); this.VehiclePark = new VehiclePark(sectors, placesPerSector); return "Vehicle park created"; case "Park": IVehicle vehicle = null; string licensePlate = command.Parameters["licensePlate"]; string owner = command.Parameters["owner"]; int reservedHours = int.Parse(command.Parameters["hours"]); int sector = int.Parse(command.Parameters["sector"]); int placeInSector = int.Parse(command.Parameters["place"]); DateTime timeOfEntry = DateTime.Parse(command.Parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind); switch (command.Parameters["type"]) { case "car": vehicle = new Car(licensePlate, owner, reservedHours); break; case "motorbike": vehicle = new Motorbike(licensePlate, owner, reservedHours); break; case "truck": vehicle = new Truck(licensePlate, owner, reservedHours); break; } string result = this.VehiclePark.InsertVehicle(vehicle, sector, placeInSector, timeOfEntry); return result; case "Exit": string licensePlateExit = command.Parameters["licensePlate"]; DateTime timeOfEntryExit = DateTime.Parse(command.Parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind); decimal amountPaid = decimal.Parse(command.Parameters["paid"]); // BUG: parameter name is "paid", not "money" string exitResult = this.VehiclePark.ExitVehicle(licensePlateExit, timeOfEntryExit, amountPaid); return exitResult; case "Status": return this.VehiclePark.GetStatus(); case "FindVehicle": return this.VehiclePark.FindVehicle(command.Parameters["licensePlate"]); case "VehiclesByOwner": return this.VehiclePark.FindVehiclesByOwner(command.Parameters["owner"]); default: throw new InvalidOperationException("Invalid command."); } }
public string ExcecuteCommand(ref IVehiclePark vehiclePark) { try { this.ValidateEnvironment(vehiclePark); } catch (InvalidOperationException ex) { return(ex.Message); } return(vehiclePark.FindVehiclesByOwner(this.Owner)); }
/// <summary> /// Excecutes the command on the specified vehicle park. /// </summary> /// <param name="vehiclePark"></param> /// <returns></returns> public string ExcecuteCommand(ref IVehiclePark vehiclePark) { try { this.ValidateEnvironment(vehiclePark); } catch (InvalidOperationException ex) { return(ex.Message); } return(vehiclePark.ExitVehicle(this.LicensePlate, this.AmountPaid, this.ExitTime)); }
public string ExecuteCommand(string commandArguments) { var commandName = commandArguments.Substring(0, commandArguments.IndexOf(' ')); var commandParameters = new JavaScriptSerializer() .Deserialize<Dictionary<string, string>>( commandArguments.Substring(commandArguments.IndexOf(' ') + 1)); if (commandName != "SetupPark" && this.VehiclePark == null) { return "The vehicle park has not been set up"; } ICommand command = null; switch (commandName) { case "SetupPark": command = new SetupParkCommand(commandName, commandParameters, this.VehiclePark); break; case "Park": command = new ParkCommand(commandName, commandParameters, this.VehiclePark); break; case "Exit": command = new ExitCommand(commandName, commandParameters, this.VehiclePark); break; case "Status": command = new StatusCommand(commandName, commandParameters, this.VehiclePark); break; case "FindVehicle": command = new FindVehicleCommand(commandName, commandParameters, this.VehiclePark); break; case "VehiclesByOwner": command = new VehiclesByOwner(commandName, commandParameters, this.VehiclePark); break; default: throw new InvalidOperationException("Invalid command."); } var commandOutput = string.Empty; if (commandName == "SetupPark") { this.VehiclePark = command.Execute() as IVehiclePark; commandOutput = "Vehicle park created"; } else { commandOutput = command.Execute() as string; } return commandOutput; }
public void InitializeTest() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; this.park = new VehiclePark(2, 2); var car = new Car("CA1011AH", "John Smith", 1); this.park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0)); var truck = new Truck("CA1010AH", "Sarah Smith", 1); this.park.InsertTruck(truck, 1, 2, new DateTime(2015, 5, 10, 10, 30, 0)); var motorbike = new Motorbike("CA1012AH", "Linda Smith", 1); this.park.InsertMotorbike(motorbike, 2, 1, new DateTime(2015, 5, 10, 10, 30, 0)); var car2 = new Car("CA1013AH", "Linda Cloe", 1); this.park.InsertCar(car2, 2, 2, new DateTime(2015, 5, 10, 10, 30, 0)); }
public void InitializeTest() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; this.park = new VehicleParkSystem(); }
public string Execute(ICommand command) { if (command.Name != "SetupPark" && this.vehiclePark == null) { return(Message.VehicleParkNotSetUp); } var message = string.Empty; switch (command.Name) { case "SetupPark": this.vehiclePark = new VehiclePark( int.Parse(command.Parameters["sectors"]), int.Parse(command.Parameters["placesPerSector"])); message = Message.VehicleParkCreated; break; case "Park": var licensePlate = command.Parameters["licensePlate"]; var owner = command.Parameters["owner"]; var reservedHours = int.Parse(command.Parameters["hours"]); var place = int.Parse(command.Parameters["place"]); var sector = int.Parse(command.Parameters["sector"]); var time = DateTime.Parse(command.Parameters["time"]); switch (command.Parameters["type"]) { case "car": var car = new Car(licensePlate, owner, reservedHours); message = this.vehiclePark.InsertCar(car, sector, place, time); break; case "motorbike": var bike = new Motorbike(licensePlate, owner, reservedHours); message = this.vehiclePark.InsertMotorbike(bike, sector, place, time); break; case "truck": var truck = new Truck(licensePlate, owner, reservedHours); message = this.vehiclePark.InsertTruck(truck, sector, place, time); break; } break; case "Exit": var exitLicesencePlate = command.Parameters["licensePlate"]; var exitTime = DateTime.Parse(command.Parameters["time"]); var moneyOwed = decimal.Parse(command.Parameters["paid"]); message = this.vehiclePark.ExitVehicle( exitLicesencePlate, exitTime, moneyOwed); break; case "Status": message = this.vehiclePark.GetStatus(); break; case "FindVehicle": message = this.vehiclePark.FindVehicle(command.Parameters["licensePlate"]); break; case "VehiclesByOwner": message = this.vehiclePark.FindVehiclesByOwner(command.Parameters["owner"]); break; default: throw new InvalidOperationException("Invalid command"); } return(message); }
private string SetupParkCommand(int sectorsCount, int placesPerSectorCount) { this.vehiclePark = new VehiclePark(sectorsCount, placesPerSectorCount); return "Vehicle park created"; }
public void VehicleParkInitialize() { //Arrange this.layout = new Layout(5, 5); this.database = new Database(5); this.vehiclePark = new VehiclePark(this.layout, this.database); // this.databaseMock.Setup(m => m.OwnerNames.ContainsKey(It.IsAny<string>())).Returns(true); this.databaseMock.Setup(d => d.OwnerNames[It.IsAny<string>()]).Returns(new List<IVehicle>{ this.testCar}); }
protected CommandBase(string name, IDictionary<string, string> parameters, IVehiclePark vehiclePark) { this.Name = name; this.Parameters = parameters; this.VehiclePark = vehiclePark; }
public string Execute(ICommand command) { if (command.CommandName != "SetupPark" && this.VehiclePark == null) { throw new InvalidOperationException("The vehicle park has not been set up"); } string message = string.Empty; switch (command.CommandName) { case "SetupPark": this.VehiclePark = new VehiclePark( int.Parse(command.Parameters["sectors"]), int.Parse(command.Parameters["placesPerSector"])); message = "Vehicle park created"; break; case "Park": switch (command.Parameters["type"]) { case "car": message = this.VehiclePark.InsertCar( new Car( command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]), int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind)); break; case "motorbike": message = this.VehiclePark.InsertMotorbike( new Motorbike( command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]), int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind)); break; case "truck": message = this.VehiclePark.InsertTruck( new Truck( command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]), int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind)); break; } break; case "Exit": message = this.VehiclePark.ExitVehicle( command.Parameters["licensePlate"], DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind), decimal.Parse(command.Parameters["paid"])); break; case "Status": message = this.VehiclePark.GetStatus(); break; case "FindVehicle": message = this.VehiclePark.FindVehicle(command.Parameters["licensePlate"]); break; case "VehiclesByOwner": message = this.VehiclePark.FindVehiclesByOwner(command.Parameters["owner"]); break; default: throw new InvalidOperationException("Invalid command."); } return(message); }
public void InitializeTest() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; this.park = new VehiclePark(2, 2); }
public void TestInit() { this.parkingSystem = new VehiclePark(numberOfSectors, placesPerSector); }
public void InitializeVehiclePark() { this.vehiclePark = new VehiclePark(DefaultParkSectors, DefaultParkPlacesPerSector, new VehicleParkData(DefaultParkSectors)); this.arrivalDateTime = DateTime.Parse(DefaultDateTimeToParse, null, DateTimeStyles.RoundtripKind); }
public VehiclesByOwner(string name, IDictionary<string, string> parameters, IVehiclePark vehiclePark) : base(name, parameters, vehiclePark) { }
public ParkCommand(string name, IDictionary<string, string> parameters, IVehiclePark vehiclePark) : base(name, parameters, vehiclePark) { }
public string Execute(ICommand command) { if (command.Name != "SetupPark" && this.vehiclePark == null) { return Message.VehicleParkNotSetUp; } var message = string.Empty; switch (command.Name) { case "SetupPark": this.vehiclePark = new VehiclePark( int.Parse(command.Parameters["sectors"]), int.Parse(command.Parameters["placesPerSector"])); message = Message.VehicleParkCreated; break; case "Park": var licensePlate = command.Parameters["licensePlate"]; var owner = command.Parameters["owner"]; var reservedHours = int.Parse(command.Parameters["hours"]); var place = int.Parse(command.Parameters["place"]); var sector = int.Parse(command.Parameters["sector"]); var time = DateTime.Parse(command.Parameters["time"]); switch (command.Parameters["type"]) { case "car": var car = new Car(licensePlate, owner, reservedHours); message = this.vehiclePark.InsertCar(car, sector, place, time); break; case "motorbike": var bike = new Motorbike(licensePlate, owner, reservedHours); message = this.vehiclePark.InsertMotorbike(bike, sector, place, time); break; case "truck": var truck = new Truck(licensePlate, owner, reservedHours); message = this.vehiclePark.InsertTruck(truck, sector, place, time); break; } break; case "Exit": var exitLicesencePlate = command.Parameters["licensePlate"]; var exitTime = DateTime.Parse(command.Parameters["time"]); var moneyOwed = decimal.Parse(command.Parameters["paid"]); message = this.vehiclePark.ExitVehicle( exitLicesencePlate, exitTime, moneyOwed); break; case "Status": message = this.vehiclePark.GetStatus(); break; case "FindVehicle": message = this.vehiclePark.FindVehicle(command.Parameters["licensePlate"]); break; case "VehiclesByOwner": message = this.vehiclePark.FindVehiclesByOwner(command.Parameters["owner"]); break; default: throw new InvalidOperationException("Invalid command"); } return message; }
public string Execute(ICommand command) { if (command.CommandName != "SetupPark" && this.VehiclePark == null) { throw new InvalidOperationException("The vehicle park has not been set up"); } string message = string.Empty; switch (command.CommandName) { case "SetupPark": this.VehiclePark = new VehiclePark( int.Parse(command.Parameters["sectors"]), int.Parse(command.Parameters["placesPerSector"])); message = "Vehicle park created"; break; case "Park": switch (command.Parameters["type"]) { case "car": message = this.VehiclePark.InsertCar( new Car( command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]), int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind)); break; case "motorbike": message = this.VehiclePark.InsertMotorbike( new Motorbike( command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]), int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind)); break; case "truck": message = this.VehiclePark.InsertTruck( new Truck( command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"])), int.Parse(command.Parameters["sector"]), int.Parse(command.Parameters["place"]), DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind)); break; } break; case "Exit": message = this.VehiclePark.ExitVehicle( command.Parameters["licensePlate"], DateTime.Parse(command.Parameters["time"], null, DateTimeStyles.RoundtripKind), decimal.Parse(command.Parameters["paid"])); break; case "Status": message = this.VehiclePark.GetStatus(); break; case "FindVehicle": message = this.VehiclePark.FindVehicle(command.Parameters["licensePlate"]); break; case "VehiclesByOwner": message = this.VehiclePark.FindVehiclesByOwner(command.Parameters["owner"]); break; default: throw new InvalidOperationException("Invalid command."); } return message; }
public string ExcecuteCommand(ref IVehiclePark vehiclePark) { vehiclePark = new VehiclePark(new Layout(this.Sectors, this.PlacesPerSector, new Database(this.Sectors))); return("Vehicle park created!"); }