/// <summary> /// Adds a new observer to be notified when a specific temperature drop or rise threshold has been reached /// </summary> /// <param name="name">The name of this notification and threshold</param> /// <param name="thresholdTemperature">The temperature reading to be notified at</param> /// <param name="sensitivity">The sensitivity of when to notify</param> /// <param name="observer">The client to be notified that implements <see cref="IObserver{T}"/></param> /// <returns>An <see cref="IDisposable" />to enable cancellation of notificaiton for that observer</returns> public IDisposable NotifyOnTemperatureChange( TemperatureChangeType changeType, string name, double thresholdTemperature, double sensitivity, Action <ThresholdInfo> callBack ) { if (changeType == TemperatureChangeType.Drop) { return(_temperatureDropped.Add( new ThresholdObservation( callBack, new ThresholdInfo(name, thresholdTemperature, _scale, sensitivity, _reading)))); } if (changeType == TemperatureChangeType.Rise) { return(_temperatureRose.Add( new ThresholdObservation( callBack, new ThresholdInfo(name, thresholdTemperature, _scale, sensitivity, _reading)))); } throw new ArgumentOutOfRangeException("Temperature change type was not recognized."); }
public void NotifyOnTemperatureChange_ShouldNotify(double triggerReading, double threshold, double sensitivityVariance, TemperatureChangeType changeType, double result) { // Act var actualReading = default(ThresholdInfo); _thermometer.NotifyOnTemperatureChange(changeType, "Boiling", threshold, sensitivityVariance, (t) => { actualReading = t; }); _thermometer.SetReading(triggerReading); // Assert // Should be null and should not have been called Assert.AreEqual(triggerReading, actualReading.CurrentReading); }
public void NotifyOnTemperatureChange_ShouldNotNotify(double triggerReading, double threshold, double sensitivityVariance, TemperatureChangeType changeType, ThresholdInfo result) { // Arrange // Set the reading before we request a notfication so it's not the first time _thermometer.SetReading(triggerReading); // Act var actualReading = default(ThresholdInfo); _thermometer.NotifyOnTemperatureChange(changeType, "Boiling", threshold, sensitivityVariance, (t) => { actualReading = t; }); _thermometer.SetReading(triggerReading); // Assert // Should be null and should not have been called Assert.AreEqual(result, actualReading); }