Esempio n. 1
0
        private void buttonModify_Click(object sender, EventArgs e)
        {
            try
            {
                var selectedVehicleToModify         = this.comboBoxSelectVehicleToModify.SelectedItem as Vehicle;
                var newCapacity                     = (int)this.numericUpDownCapacity.Value;
                var newFuelConsumption              = (int)this.numericUpDownFuelConsumption.Value;
                ModifyVehicleInput newVehicleValues = new ModifyVehicleInput
                {
                    Registration             = selectedVehicleToModify.Registration,
                    NewCapacity              = newCapacity,
                    FuelConsumptionKmsPerLtr = newFuelConsumption
                };

                IVehicleLogic vehicleOperations = Provider.GetInstance.GetVehicleOperations();
                vehicleOperations.ModifyVehicle(newVehicleValues);
                this.labelSuccess.Visible = true;
                this.labelSuccess.Text    = "The vehicle was succesfully modified.";
                this.ClearForm();
                this.ReloadComboBoxSelectVehicleToModify();
            }
            catch (CoreException ex)
            {
                this.labelError.Visible = true;
                this.labelSuccess.Text  = ex.Message;
            }
            catch (Exception ex)
            {
                this.labelError.Visible = true;
                this.labelSuccess.Text  = ex.Message;
            }
        }
        public void ModifyVehicle(ModifyVehicleInput input)
        {
            Vehicle vehicleToModify = GetVehicleByRegistration(input.Registration);

            if (input.NewCapacity <= 0)
            {
                throw new CoreException("Capacity should be greater than 0.");
            }
            else if (input.FuelConsumptionKmsPerLtr <= 0)
            {
                throw new CoreException("Fuel consumption should be greater than 0.");
            }
            else
            {
                vehicleToModify.SetCapacity(input.NewCapacity);
                vehicleToModify.FuelConsumptionKmsPerLtr = input.FuelConsumptionKmsPerLtr;
                this.persistanceProvider.ModifyVehicle(vehicleToModify);
            }
        }
Esempio n. 3
0
        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);
        }