using MeterVault.Core.Domain; using MeterVault.Core.Normalization; using MeterVault.Infrastructure.Import; using static MeterVault.Integration.Tests.Reconciliation.ReconciliationSupport; namespace MeterVault.Integration.Tests.Reconciliation; /// /// Reconciles the water meter against the Wasser sheet's Wasserverbrauch column, exercising the /// mid-series register swap …861 → 2 (SDD §2.3). The importer detects the register drop and seeds /// a swap event whose consumption override comes from the sheet's own column. /// public sealed class WaterReconciliationTests { [Fact] public void Water_consumption_matches_the_sheet_across_the_swap() { var staged = Stage(ReferenceProfiles.Water(), Water); // A swap event must have been auto-detected at the 861→2 drop. Assert.Contains(staged.Events, e => e.EventType == MeterEventType.MeterSwap); var config = new MeterConfig { MeterId = ReferenceProfiles.Wasser, Mode = MeterMode.CumulativeCounter, Unit = "m3", InitialBaseline = 820, // pre-existing meter's register when tracking began (Nov 2022). }; var computed = ByMonth(Normalize(staged, config)); var oracle = OracleByMonth(ReadRows(Water), dateColumn: 0, valueColumn: 2, firstDataRow: 1); AssertReconciles(computed, oracle, tolerance: 1.0, "water", minMatches: 12); // Explicitly assert the swap month reconciles to 12. Assert.Equal(12d, computed[new DateOnly(2023, 3, 1)], 3); } }