public void SensorValueReached_Trigger() { var sensor = new TestTemperatureSensor(ComponentIdFactory.EmptyId, new TestNumericValueSensorEndpoint()); var trigger = new SensorValueReachedTrigger(sensor); trigger.Target = 10.2F; trigger.Delta = 3.0F; int triggerCount = 0; trigger.Attach(() => triggerCount++); sensor.Endpoint.UpdateValue(5); triggerCount.ShouldBeEquivalentTo(0); sensor.Endpoint.UpdateValue(10); triggerCount.ShouldBeEquivalentTo(0); sensor.Endpoint.UpdateValue(10.2F); triggerCount.ShouldBeEquivalentTo(1); sensor.Endpoint.UpdateValue(9.0F); triggerCount.ShouldBeEquivalentTo(1); sensor.Endpoint.UpdateValue(13.0F); triggerCount.ShouldBeEquivalentTo(1); sensor.Endpoint.UpdateValue(5.0F); triggerCount.ShouldBeEquivalentTo(1); sensor.Endpoint.UpdateValue(10.2F); triggerCount.ShouldBeEquivalentTo(2); }
public void SensorValueUnderran_Trigger() { var sensor = new TestTemperatureSensor(ComponentIdGenerator.EmptyId, new SettingsService(new BackupService(), new StorageService()), new TestNumericValueSensorEndpoint()); var trigger = new SensorValueUnderranTrigger(sensor); trigger.Target = 10F; trigger.Delta = 3F; int triggerCount = 0; trigger.Attach(() => triggerCount++); sensor.Endpoint.UpdateValue(5); triggerCount.ShouldBeEquivalentTo(1); sensor.Endpoint.UpdateValue(10); triggerCount.ShouldBeEquivalentTo(1); sensor.Endpoint.UpdateValue(13.1F); triggerCount.ShouldBeEquivalentTo(1); sensor.Endpoint.UpdateValue(9F); triggerCount.ShouldBeEquivalentTo(2); sensor.Endpoint.UpdateValue(13.0F); triggerCount.ShouldBeEquivalentTo(2); sensor.Endpoint.UpdateValue(5F); triggerCount.ShouldBeEquivalentTo(2); sensor.Endpoint.UpdateValue(13.1F); triggerCount.ShouldBeEquivalentTo(2); sensor.Endpoint.UpdateValue(9.9F); triggerCount.ShouldBeEquivalentTo(3); }