public void reporting_a_plugs_consumption() { var pinheiro = new PlugActivated(Guid.NewGuid(), "Pinheiro de Natal"); using (var session = _documentStore.OpenSession()) { session.Events.Append(pinheiro.PlugId, pinheiro); session.SaveChanges(); } using (var session = _documentStore.OpenSession()) { session.Events.Append(pinheiro.PlugId, new PlugTurnedOn(), new ConsumptionReadingReceived(2.3, 220, 20), new ConsumptionReadingReceived(2.3, 220, 20), new ConsumptionReadingReceived(2.3, 220, 22), new ConsumptionReadingReceived(2.3, 220, 23), new ConsumptionReadingReceived(2.3, 220, 24), new ConsumptionReadingReceived(2.3, 220, 20), new ConsumptionReadingReceived(2.3, 220, 21), new ConsumptionReadingReceived(2.3, 220, 22), new ConsumptionReadingReceived(2.3, 220, 20), new ConsumptionReadingReceived(2.3, 220, 21), new PlugTurnedOff(), new PlugTurnedOn(), new ConsumptionReadingReceived(2.2, 220, 21) ); session.SaveChanges(); } var reporter = new ConsumptionReporter(_documentStore); var consumptionReport = reporter.GetConsumptionReport(pinheiro.PlugId); consumptionReport.Select(x => x.ConsumptionInWatts).Should().BeEquivalentTo(new [] { 20.0, 20.0, 22.0, 23.0, 24.0, 20.0, 21.0, 22.0, 20.0, 21.0, 21.0 }); using (var session = _documentStore.OpenSession()) { session.Load <Plug>(pinheiro.PlugId).LastConsumptionInWatts.Should().Be(21); } }
public P1Reader(DataParser parser, ConsumptionReporter reporter) { _parser = parser; _reporter = reporter; }