public void GetVehiclesOrderedByCapacityPerFuelConsumption() { IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations(); Vehicle vehicle1 = new Vehicle("SBA0001", 10, 10); Vehicle vehicle2 = new Vehicle("SBA1015", 10, 100); vehicleOperations.AddVehicle(vehicle1); vehicleOperations.AddVehicle(vehicle2); var vehiclesOrdered = vehicleOperations.GetVehiclesOrderedByCapacityPerFuelConsumption(); Assert.AreEqual(vehiclesOrdered[0], vehicle2); Assert.AreEqual(vehiclesOrdered[1], vehicle1); }
public void ListVehicles() { IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations(); Vehicle vehicleOne = new Vehicle("SBA1234", 10); Vehicle vehicleTwo = new Vehicle("SBA5678", 15); Vehicle vehicleThree = new Vehicle("SBA9012", 20); vehicleOperations.AddVehicle(vehicleOne); vehicleOperations.AddVehicle(vehicleTwo); vehicleOperations.AddVehicle(vehicleThree); var vehicles = vehicleOperations.GetVehicles(); Assert.IsTrue(vehicles.Count == 3); }
public void ModifyVehicleCapacityInSystem() { IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations(); Vehicle newVehicle = new Vehicle("SBA1234", 10, 10); vehicleOperations.AddVehicle(newVehicle); ModifyVehicleInput input = new ModifyVehicleInput(); input.Registration = "SBA1234"; input.NewCapacity = 20; input.FuelConsumptionKmsPerLtr = 10; vehicleOperations.ModifyVehicle(input); Vehicle modifiedVehicle = vehicleOperations.GetVehicleByRegistration("SBA1234"); Assert.AreEqual(modifiedVehicle.GetCapacity(), input.NewCapacity); }
public void DeleteVehicle() { try { IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations(); string registration = "SBA1234"; int capacity = 10; Vehicle vehicle = new Vehicle(registration, capacity); vehicleOperations.AddVehicle(vehicle); vehicleOperations.DeleteVehicle(vehicle); Assert.IsNull(this.FindVehicleOnSystem(vehicle.Registration)); } catch (Exception ex) { Assert.Fail(ex.Message); } }
private void buttonAdd_Click(object sender, EventArgs e) { this.labelSuccess.Visible = false; this.labelError.Visible = false; var registration = this.textBoxRegistration.Text; var capacity = (int)this.numericUpDownCapacity.Value; var fuelConsumption = (int)this.numericUpDownFuelConsumption.Value; try { Vehicle vehicle = new Vehicle(registration, capacity, fuelConsumption); IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations(); vehicleOperations.AddVehicle(vehicle); this.labelSuccess.Visible = true; this.labelSuccess.Text = "Vehicle " + vehicle + " was successfully added."; } catch (CoreException ex) { this.labelError.Visible = true; this.labelError.Text = ex.Message; } }
public IActionResult AddVehicle([FromBody] VehicleModel model) { try { if (model == null) { return(BadRequest("Body content is not valid!")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = model.Map <VehicleEntity>(); entity.ManufactureDate = entity.ManufactureDate.ToLocalTime(); entity = _vehicleLogic.AddVehicle(entity); if (entity == null) { throw new Exception("Somthing went wrong while adding model to DB!"); } return(Ok(entity)); } catch (Exception e) { return(StatusCode(500, e)); } }
public void CalculateDistanceToCoverByVehicle() { IVehicleLogic vehicleOperations = DummyProvider.GetInstance.GetVehicleOperations(); IStudentLogic studentOperations = DummyProvider.GetInstance.GetStudentOperations(); Vehicle vehicle = new Vehicle("SBA0001", 10, 10); vehicleOperations.AddVehicle(vehicle); Student studentOne = new Student(); studentOne.Document = "1234567-1"; studentOne.Name = "John"; studentOne.Location = new Location(2.00000, 2.000000); studentOne.HavePickUpService = true; studentOne.StudentNumber = 1; Student studentTwo = new Student(); studentTwo.Document = "1234567-2"; studentTwo.Name = "George"; studentTwo.Location = new Location(1.00000, 1.000000); studentTwo.HavePickUpService = true; studentTwo.StudentNumber = 2; Student studentThree = new Student(); studentThree.Document = "1234567-3"; studentThree.Name = "Paul"; studentThree.Location = new Location(3.00000, 3.000000); studentThree.HavePickUpService = true; studentThree.StudentNumber = 3; Student studentFour = new Student(); studentFour.Document = "1234567-4"; studentFour.Name = "Ringo"; studentFour.Location = new Location(20.00000, 20.000000); studentFour.HavePickUpService = true; studentFour.StudentNumber = 4; studentOperations.AddStudent(studentOne); studentOperations.AddStudent(studentTwo); studentOperations.AddStudent(studentThree); studentOperations.AddStudent(studentFour); List <Tuple <Vehicle, List <Student> > > vehiclesWithStudents = vehicleOperations.GetVehiclesOrderedByEfficiencyConsideringStudentsNumber(); var expectedDistance = 0.0; expectedDistance += Utils.Distance(new Location(), studentTwo.Location); expectedDistance += Utils.Distance(studentTwo.Location, studentOne.Location); expectedDistance += Utils.Distance(studentOne.Location, studentThree.Location); expectedDistance += Utils.Distance(studentThree.Location, studentFour.Location); expectedDistance += Utils.Distance(studentFour.Location, new Location()); var distance = vehicleOperations.CalculateDistanceToCoverByVehicle(vehiclesWithStudents[0]); Assert.IsTrue(distance == expectedDistance); }