public void SerializeValueOutOfRangeException() { string message = "Serialized ValueOutOfRangeException"; var exception = new ValueOutOfRangeException(message); var deserializedException = ExceptionSerialiseHelper(exception, typeof(ValueOutOfRangeException)) as ValueOutOfRangeException; // ValueOutOfRangeException appends 'out of range' to the end of the message Assert.That(deserializedException.Message, Is.EqualTo($"{message} out of range"), "should have expected message"); }
// This method charge the engine battery, only if it is less than MaxCap. public void Charge(float i_NumHoursCharged) { if (this.MaxCapacity >= this.CurrAmount + i_NumHoursCharged) { this.CurrAmount += i_NumHoursCharged; } else { // Charged Amount is too big. var voore = new ValueOutOfRangeException(0, this.MaxCapacity); voore.Source = this.GetType().Name; throw voore; } }
public void Inflating(float i_AirToAdd) { if (i_AirToAdd == MaxAirPressure) { CurrentAirPressure = i_AirToAdd; } else if (CurrentAirPressure + i_AirToAdd <= MaxAirPressure) { CurrentAirPressure += i_AirToAdd; } else { ValueOutOfRangeException i_ValueOutOfRangeException = new ValueOutOfRangeException(MaxAirPressure, 0); throw i_ValueOutOfRangeException; } }
public Tire(string i_ManufacturerName, float i_MaxAirPressure) { r_ManufacturerName = i_ManufacturerName; r_MaxAirPressure = i_MaxAirPressure; r_CheckRange = new ValueOutOfRangeException(0, i_MaxAirPressure); }
protected EnergyStorage(float i_MaxCapacity) { r_MaxCapacity = i_MaxCapacity; r_CheckRange = new ValueOutOfRangeException(0, i_MaxCapacity); }