public Processor(IActorRef listener, IAverageService averageService) { this.listener = listener; Context.System.Scheduler.ScheduleTellRepeatedly(averageSendInterval, averageSendInterval, Self, new CalculateAverage(), Self); Receive <DeviceTemperature>(msg => averageService.AddValue(msg.DeviceId, new TemperatureValue(msg.Value, DateTime.UtcNow), (exceeded) => { if (exceeded) { listener.Tell(new ThresholdExceeded(msg.DeviceId)); } else { listener.Tell(new ValueNormalized(msg.DeviceId)); } }) ); Receive <CalculateAverage>(msg => listener.Tell(new AverageTemperature(averageService.Average(DateTime.UtcNow)))); }
public Task AddTemperature(DeviceTemperature data) { averageService.AddValue(data.DeviceId, new TemperatureValue(data.Value, DateTime.UtcNow), (exceeded) => { if (exceeded) { printer.ThresholdExceeded(new ThresholdExceeded(data.DeviceId)); } else { printer.ValueNormalized(new ValueNormalized(data.DeviceId)); } }); return(Done); }
public void AddValue_AddValueIntoAverage() { //arrange Sut.Average(UtcNow).Should().NotHaveValue(); //act Sut.AddValue(1, new TemperatureValue(2.0, UtcNow), null); //assert Sut.Average(UtcNow).Should().Be(2.0); }