private static DateTime NextMeasurement(DateTime fakeDate, ChargingSession t, SocketMeasurement sm, int duration, double energy, Mode3State state, Tariff tariff = null) { using (new DateTimeProviderContext(fakeDate)) { sm.Mode3State = state; t.UpdateSession(sm, tariff); } fakeDate = fakeDate.AddSeconds(duration); using (new DateTimeProviderContext(fakeDate)) { sm.RealEnergyDeliveredSum += energy; t.UpdateSession(sm, tariff); } return(fakeDate); }
public void HandlesSimpleChargingSession() { var fakeDate = new DateTime(2021, 4, 1, 13, 14, 30); var tariff = new Tariff(fakeDate, 0.23d, 0.08d); using (new DateTimeProviderContext(fakeDate)) { var t = new ChargingSession(); var sm = new SocketMeasurement { Mode3State = Mode3State.E, RealEnergyDeliveredSum = 1000 }; t.UpdateSession(sm, tariff); fakeDate = fakeDate.AddSeconds(30); using (new DateTimeProviderContext(fakeDate)) { sm.Mode3State = Mode3State.A; t.UpdateSession(sm, tariff); sm.Mode3State = Mode3State.B1; t.UpdateSession(sm, tariff); sm.Mode3State = Mode3State.B2; t.UpdateSession(sm, tariff); sm.Mode3State = Mode3State.C1; t.UpdateSession(sm, tariff); sm.Mode3State = Mode3State.C2; t.UpdateSession(sm, tariff); Assert.False(t.ChargeSessionInfo.SessionEnded); fakeDate = fakeDate.AddSeconds(65); using (new DateTimeProviderContext(fakeDate)) { sm.Mode3State = Mode3State.E; sm.RealEnergyDeliveredSum += 50; t.UpdateSession(sm, tariff); // session has ended, let's see the result of this simple charging session Assert.Equal <uint>(65, t.ChargeSessionInfo.ChargingTime); Assert.Equal <double>(50, t.ChargeSessionInfo.EnergyDelivered); Assert.True(t.ChargeSessionInfo.SessionEnded); Assert.Equal <double>(11.5d, t.ChargeSessionInfo.Cost); } } } }