Exemple #1
0
        public void FillTank(string i_LicenseNumber, FuelEngine.eGasType i_GasType, float i_AmountToFill)
        {
            bool vehicleExists = r_AllVehicles.TryGetValue(i_LicenseNumber, out Vehicle requestedVehicle);

            if (vehicleExists)
            {
                FuelEngine thisFuelEngine = requestedVehicle.VehicleEngine as FuelEngine;
                if (thisFuelEngine != null)
                {
                    if (thisFuelEngine.MaxEnergyCapacity > thisFuelEngine.CurrentEnergyCapacity)
                    {
                        if (thisFuelEngine.GasType != i_GasType)
                        {
                            string errorMessage = string.Format(
                                @"This car takes {0} fuel",
                                thisFuelEngine.GasType);
                            throw new ArgumentException(errorMessage);
                        }
                        else if (thisFuelEngine.MaxEnergyCapacity <= thisFuelEngine.CurrentEnergyCapacity + i_AmountToFill || i_AmountToFill <= 0)
                        {
                            float maxAmountToFill =
                                thisFuelEngine.MaxEnergyCapacity - thisFuelEngine.CurrentEnergyCapacity;
                            throw new ValueOutOfRangeException(@"Invalid amount to fill", 0, maxAmountToFill);
                        }
                        else
                        {
                            thisFuelEngine.AddFuel(i_AmountToFill, i_GasType);
                        }
                    }
                }
                else
                {
                    throw new KeyNotFoundException(@"This is not an fuel vehicle");
                }
            }
            else
            {
                throw new KeyNotFoundException(@"This vehicle is not it the garage");
            }
        }