public T Create <T>(int id, int weightInKilogram) where T : IVehicle { if (typeof(T) == typeof(IStandardCar)) { IVehicle car = new StandardCar(new VehicleFees(new FeeCalculator()), id, weightInKilogram); return(( T )car); } if (typeof(T) == typeof(ILuxuryCar)) { IVehicle car = new LuxuryCar(new VehicleFees(new FeeCalculator()), id, weightInKilogram); return(( T )car); } if (typeof(T) == typeof(IMotorbike)) { IVehicle car = new Motorbike(new VehicleFees(new FeeCalculator()), id, weightInKilogram); return(( T )car); } if (typeof(T) == typeof(ITruck)) { IVehicle car = new Truck(new VehicleFees(new FeeCalculator()), id, weightInKilogram); return(( T )car); } throw new ArgumentException("Unknown vehicle type '{0}'!".Inject(typeof(T))); }
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 IsTollFreeVehicleTest() { var tc = new TollCalculator(); var act = new Motorbike(); Assert.IsTrue(tc.IsTollFreeVehicle(act)); }
public string InsertMotorbike(Motorbike motorbike, int sector, int place, DateTime time) { if (sector > this.layout.Sectors) { return($"There is no sector {sector} in the park"); } if (place > this.layout.PlacesSec) { return($"There is no place {place} in sector {sector}"); } if (this.repository.Park.ContainsKey($"({sector},{place})")) { return($"The place ({sector},{place}) is occupied"); } if (this.repository.Numbers.ContainsKey(motorbike.LicensePlate)) { return($"There is already a vehicle with license plate {motorbike.LicensePlate} in the park"); } this.repository.CarsInPark[motorbike] = $"({sector},{place})"; this.repository.Park[$"({sector},{place})"] = motorbike; this.repository.Numbers[motorbike.LicensePlate] = motorbike; this.repository.DateParkDictionary[motorbike] = time; this.repository.OwnersMultiDictionary[motorbike.Owner].Add(motorbike); this.repository.Count[sector - 1]++; return($"{motorbike.GetType().Name} parked successfully at place ({sector},{place})"); }
public ActionResult AddVehicle(string vehicle, string type) { try { switch (type) { //Deserialize object myself since it can be multiple cases case "Truck": Truck truck = JsonConvert.DeserializeObject <Truck>(vehicle); _vehicleService.AddVehicle(truck); break; case "Car": Car car = JsonConvert.DeserializeObject <Car>(vehicle); _vehicleService.AddVehicle(car); break; case "Motorbike": Motorbike motorbike = JsonConvert.DeserializeObject <Motorbike>(vehicle); _vehicleService.AddVehicle(motorbike); break; default: return(BadRequest("Not Accepted Type")); } return(Ok()); } catch (Exception ex) { return(BadRequest("Error occurred :" + ex.Message)); } }
private void PayFeesForAllOtherCars() { // 8. Pay the outstanding fees for the remaining cars StandardCar.PaysFee(); Motorbike.PaysFee(); Truck.PaysFee(); }
private static void Demo1() { using (var db = new MyDbContext()) { var person = new Person { Name = "Leo", Motorbikes = new List <Motorbike>(), }; var motorbike1 = new Motorbike { Brand = "Honda", ReleaseYear = 2018, Owner = person, }; var motorbike2 = new Motorbike { Brand = "Yamaha", ReleaseYear = 2018, Owner = person, }; person.Motorbikes.Add(motorbike1); person.Motorbikes.Add(motorbike2); db.Persons.Add(person); db.SaveChanges(); } }
private void getMotorbikeProperties(ref Motorbike io_MotorbikeToUpdate) { bool isInputValid = false; int userInput = 0; while (!isInputValid) { try { OutputManager.ShowScreen <Motorbike.eLicenseType>("Please enter the number of the desired licence type:"); userInput = InputManager.GetInputAndConvertToInt(); isInRange(userInput, 1, Enum.GetValues(typeof(Motorbike.eLicenseType)).Length); io_MotorbikeToUpdate.License = (Motorbike.eLicenseType)userInput; OutputManager.ShowMessage("Please enter the motorbike engine volume."); io_MotorbikeToUpdate.EngineVolume = InputManager.GetInputAndConvertToInt(); isInputValid = true; } catch (FormatException ex) { OutputManager.ShowErrorMessage(string.Format("Invalid input. {0}", ex.Message)); pressToContinue(); } catch (ValueOutOfRangeException ex) { OutputManager.ShowErrorMessage(string.Format("Input out of range. {0}", ex.Message)); pressToContinue(); } } }
public string InsertMotorbike(Motorbike motorbike, int sector, int place, DateTime time) { if (sector > this.parkSize.NumberOfSectors) { return(string.Format("There is no sector {0} in the park", sector)); } if (place > this.parkSize.PlacesPerSector) { return(string.Format("There is no place {0} in sector {1}", place, sector)); } if (this.vehicleDatabase.Park.ContainsKey(string.Format("({0},{1})", sector, place))) { return(string.Format("The place ({0},{1}) is occupied", sector, place)); } if (this.vehicleDatabase.VehiclesRegistrationNumber.ContainsKey(motorbike.LicensePlate)) { return(string.Format("There is already a vehicle with license plate {0} in the park", motorbike.LicensePlate)); } this.vehicleDatabase.VehiclesPark[motorbike] = string.Format("({0},{1})", sector, place); this.vehicleDatabase.Park[string.Format("({0},{1})", sector, place)] = motorbike; this.vehicleDatabase.VehiclesRegistrationNumber[motorbike.LicensePlate] = motorbike; this.vehicleDatabase.DateAndTime[motorbike] = time; this.vehicleDatabase.VehicleOwner[motorbike.Owner].Add(motorbike); this.vehicleDatabase.VehiclesCount[sector - 1]++; return(string.Format("{0} parked successfully at place ({1},{2})", motorbike.GetType().Name, sector, place)); }
public string InsertMotorbike(Motorbike motorbike, int s, int p, DateTime t) { if (s > this.layout.sectors) { return(string.Format("There is no sector {0} in the park", s)); } if (p > this.layout.places) { return(string.Format("There is no place {0} in sector {1}", p, s)); } if (this.data.ParkPlace.ContainsKey(string.Format("({0},{1})", s, p))) { return(string.Format("The place ({0},{1}) is occupied", s, p)); } if (this.data.LicensePlate.ContainsKey(motorbike.LicensePlate)) { return(string.Format("There is already a vehicle with license plate {0} in the park", motorbike.LicensePlate)); } this.data.AllCarsInPark[motorbike] = string.Format("({0},{1})", s, p); this.data.ParkPlace[string.Format("({0},{1})", s, p)] = motorbike; this.data.LicensePlate[motorbike.LicensePlate] = motorbike; this.data.D[motorbike] = t; this.data.Owner[motorbike.Owner].Add(motorbike); this.data.count[s - 1]++; return(string.Format("{0} parked successfully at place ({1},{2})", motorbike.GetType().Name, s, p)); }
private void Setup() { var mock = new Mock <IVehicleParkData>(); ////mock.Setup(v => v.PlaceByVehicles[It.IsAny<IVehicle>()]).Returns("(0,1)"); ////mock.Setup(v => v.EntryDateTimesByVehicle[It.IsAny<IVehicle>()]); string peshoOwner = "Pesho"; string goshoOwner = "Gosho"; string toshoOwner = "Tosho"; string emoOwner = "Emo"; var firstCar = new Car("CA0000AH", peshoOwner, 2); var secondCar = new Car("CA0001AH", goshoOwner, 2); var firstTruck = new Truck("TA0000AH", goshoOwner, 2); var secondTruck = new Truck("TA0001AH", toshoOwner, 3); var firstMotorbike = new Motorbike("MA0000AH", goshoOwner, 4); var secondMotorbike = new Motorbike("MA0001AH", emoOwner, 1); this.VehiclesByLicensePlates.Add(firstCar.LicensePlate, firstCar); this.VehiclesByLicensePlates.Add(secondCar.LicensePlate, secondCar); this.VehiclesByLicensePlates.Add(firstTruck.LicensePlate, firstTruck); this.VehiclesByLicensePlates.Add(secondTruck.LicensePlate, secondTruck); this.VehiclesByLicensePlates.Add(firstMotorbike.Owner, firstMotorbike); this.VehiclesByLicensePlates.Add(secondMotorbike.Owner, secondMotorbike); // Initializing vehicle per owner data. this.VehicleByOwners.Add(firstCar.Owner, firstCar); this.VehicleByOwners.Add(secondCar.Owner, secondCar); this.VehicleByOwners.Add(firstTruck.Owner, firstTruck); this.VehicleByOwners.Add(secondTruck.Owner, secondTruck); this.VehicleByOwners.Add(firstMotorbike.Owner, firstMotorbike); this.VehicleByOwners.Add(secondMotorbike.Owner, secondMotorbike); // By place this.VehicleByPlace.Add("(0,0)", firstCar); this.VehicleByPlace.Add("(0,1)", secondCar); this.VehicleByPlace.Add("(0,2)", firstTruck); this.VehicleByPlace.Add("(0,3)", secondTruck); this.VehicleByPlace.Add("(0,4)", firstMotorbike); this.VehicleByPlace.Add("(0,5)", secondMotorbike); this.PlaceByVehicles.Add(firstCar, "(0,0)"); this.PlaceByVehicles.Add(secondCar, "(0,1)"); this.PlaceByVehicles.Add(firstTruck, "(0,2)"); this.PlaceByVehicles.Add(secondTruck, "(0,3)"); this.PlaceByVehicles.Add(firstMotorbike, "(0,4)"); this.PlaceByVehicles.Add(secondMotorbike, "(0,5)"); }
static void Main(string[] args) { BuildConfiguration(); IAppConfiguration appConfiguration = new AppConfiguration(_configuration); File.AppendAllText(Globals.AppConfiguration.LogFilePath, $"Windows Service Started {DateTime.Now.ToString()}\n"); ITollFeeCalculatorService tollFreeForAVehicle = new TollFeeCalculatorService(); var car = new Car(); car.RegNo = "APE813"; var totalCostFee = tollFreeForAVehicle.GetTollFee(car, new DateTime[] { new DateTime(2019, 05, 8, 10, 30, 0), new DateTime(2019, 05, 9, 10, 30, 0), new DateTime(2019, 05, 9, 10, 56, 0) }); var motorbike = new Motorbike(); motorbike.RegNo = "APE888"; totalCostFee = tollFreeForAVehicle.GetTollFee(motorbike, new DateTime[] { new DateTime(2019, 05, 8, 10, 30, 0), new DateTime(2019, 05, 9, 10, 30, 0), new DateTime(2019, 05, 9, 10, 56, 0) }); Console.ReadKey(); }
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 void Test_InsertMotorbike_IncorrectPlace_ShouldReturnErrorMessage() { var park = new VehiclePark(2, 2); var motorbike = new Motorbike("CA1011AH", "John Smith", 1); string message = park.InsertMotorbike(motorbike, 1, 10, new DateTime(2015, 5, 10, 10, 30, 0)); Assert.AreEqual("There is no place 10 in sector 1", message); }
public void ShouldReturnNoFeeOnEmptyDates() { var motorbike = new Motorbike(); var tollFee = _tollCalculator.GetTollFee(motorbike, new DateTime[0]); Assert.Equal(0, tollFee); }
public ActionResult DeleteConfirmed(int id) { Motorbike motorbike = db.Motorbike.Find(id); db.Motorbike.Remove(motorbike); db.SaveChanges(); return(RedirectToAction("Index")); }
static void Main() { Motorbike m1 = new Motorbike(); Motorbike m2 = new Motorbike(); Console.WriteLine("m1 has {0} wheels", m1.GetWheels()); Console.WriteLine("m2 has {0} wheels", m2.GetWheels()); }
public void Test_InsertMotorbike_CorrectParameters_ShouldInsertTheMotorbike() { var park = new VehiclePark(2, 2); var motorbike = new Motorbike("CA1011AH", "John Smith", 1); string message = park.InsertMotorbike(motorbike, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0)); Assert.AreEqual("Motorbike parked successfully at place (1,1)", message); }
static void Main(string[] args) { var bike = new Motorbike(new GasEngine(100)); bike.RunAtHalfSpeed(); bike = new Motorbike(new DieselEngine(30)); bike.RunAtHalfSpeed(); }
public ActionResult Edit(string plate) { Motorbike moTor = MotorBusiness.Select(plate); ViewBag.MotorType = new SelectList(MotorTypeBusiness.ListMotorTypes(), "Id", "Description", moTor.MotorType); SelectList sList = new SelectList(MotorTypeBusiness.ListMotorTypes(), "Id", "Description", moTor.MotorType); ViewBag.MotorTypes = sList; return(PartialView("EditForm", moTor)); }
static void Main(string[] args) { IEngine eng1 = new GasEngine(20); IEngine eng2 = new DieselEngine(50); Motorbike m = new Motorbike(eng1); Motorbike m2 = new Motorbike(eng2); m.RunAtHalfSpeed(); m2.RunAtHalfSpeed(); }
public void Delete() { Console.WriteLine("Delete passenger"); Console.Write("Id: "); Guid motorbikeId = Guid.Parse(Console.ReadLine()); Passenger passengerToDelete = selectedMotorbike.passengers.SingleOrDefault(x => x.Id == motorbikeId); selectedMotorbike.passengers.Remove(passengerToDelete); selectedMotorbike = motorbikeServiceObj.Update(selectedMotorbike); }
public ActionResult Edit([Bind(Include = "Year,Model,Mileage,Description,Manufacturer")] Motorbike motorbike) { if (ModelState.IsValid) { db.Entry(motorbike).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(motorbike)); }
public string InsertMotorbike(Motorbike motorbike, int sector, int place, DateTime dateTime) { string validationResult = ValidateVehicle(motorbike, sector, place); if (validationResult != string.Empty) { return(validationResult); } return(AddVehicleToParkData(motorbike, sector, place, dateTime)); }
private string ExecuteParkMotorbikeCommand(ICommand command) { var motorbike = new Motorbike(command.Parameters["licensePlate"], command.Parameters["owner"], int.Parse(command.Parameters["hours"])); string commandResult = this.VehiclePark.InsertMotorbike( motorbike, int.Parse(command.Parameters["sector"]), int.Parse(command.Parameters["place"]), DateTimeUtilities.ParseISODateTime(command.Parameters["time"])); return(commandResult); }
public void TestReciveMotorbike() { var motorbike = new Motorbike() { Placa = "III222", IsAltoCilindraje = false }; var result = _parkingManager.ReceiveVehicle(motorbike); Assert.IsTrue(result.Item1); }
public void Delete(Motorbike motorbikeToDelete) { using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Delete(motorbikeToDelete); tx.Commit(); } } }
static void Main() { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; Car car = new Car("CA2564HH", "Ivan", 2); Motorbike motorbike = new Motorbike("H2299AH", "Pesho", 4); Truck truck = new Truck("A2442KK", "Gosho", 1); IVehiclePark park = new VehiclePark(2, 2); Console.WriteLine(park.InsertCar(car, 1, 1, DateTime.Now)); Console.WriteLine(park.InsertMotorbike(motorbike, 1, 1, DateTime.Now)); }
public Motorbike Update(Motorbike motorbikeToUpdate) { using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { session.Update(motorbikeToUpdate); tx.Commit(); } } return(motorbikeToUpdate); }
public void Test_InsertMotorbike_OccupiedPlace_ShouldReturnErrorMessage() { var park = new VehiclePark(2, 2); var motorbike = new Motorbike("CA1011AH", "John Smith", 1); park.InsertMotorbike(motorbike, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0)); var otherMotorbike = new Motorbike("CA1022AH", "Jane Smith", 1); string message = park.InsertMotorbike(otherMotorbike, 1, 1, new DateTime(2015, 5, 10, 12, 30, 0)); Assert.AreEqual("The place (1,1) is occupied", message); }
public void Test_InsertMotorbike_WithSameLicensePlate_ShouldReturnErrorMessage() { var park = new VehiclePark(2, 2); var motorbike = new Motorbike("CA1011AH", "John Smith", 1); park.InsertMotorbike(motorbike, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0)); var otherMotorbike = new Motorbike("CA1011AH", "Jane Smith", 1); string message = park.InsertMotorbike(otherMotorbike, 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); }
static void Main(string[] args) { Vehicle vCar = new Car("Diesel","Fiat","600"); Vehicle vMoto = new Motorbike("1500","Ducatti","1500"); Vehicle vBoat = new Boat("10000","Vasque","3",3); ArrayList Vehicles = new ArrayList(); Vehicles.add(vCar); Vehicles.add(vMoto); Vehicles.add(vBoat); list(Vehicles); }
private string ParkCommand(string type, string owner, string licensePlate, int reservedHours, int sector, int place, DateTime time) { switch (type) { case "car": var car = new Car(licensePlate, owner, reservedHours); return this.vehiclePark.InsertCar(car, sector, place, time); case "motorbike": var motorbike = new Motorbike(licensePlate, owner, reservedHours); return this.vehiclePark.InsertMotorbike(motorbike, sector, place, time); case "truck": var truck = new Truck(licensePlate, owner, reservedHours); return this.vehiclePark.InsertTruck(truck, sector, place, time); } return string.Empty; }
public string InsertMotorbike(Motorbike motorbike, int sector, int placeNumber, DateTime startTime) { return this.InsertVehicle(motorbike, sector, placeNumber, startTime); }
public string InsertMotorbike(Motorbike motorbike, int sector, int place, DateTime time) { var message = this.InsertVehicle(motorbike, sector, place, time); return message; }
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; }