Files
schmidt.florian 5977c81002 M2: German CSV importer + reconciliation of all 4 fixtures
- German-dialect scalar parsers in Core (GermanNumber/Money/Date, ValueCell):
  decimal comma, thousands dot, unit suffixes, € currency, both date shapes.
- Declarative MappingProfile + RowClassifier (skip summary/blank/all-zero rows) +
  CsvImporter (CsvHelper) staging readings/events/manual-costs, with auto swap
  detection on register decreases and month-end anchoring for interleaved oil dates.
- Four built-in ReferenceProfiles (Strom/Wasser/Heizöl/Kosten).
- ImportService: commit as revertible import_batch + wholesale consumption recompute
  per affected meter (NormalizationService/MeterConfigFactory), revert by batch.
- Reconciliation tests: all 4 CSVs match the sheet's own columns within tolerance
  (electricity 5 meters + Netz Einsparung, water swap→12, oil tank incl. deliveries +
  burner hours, cost category totals). Commit/revert round-trip verified on Timescale.

69 tests green (53 Core + 16 integration).

Known follow-up (polish): historical imports can contend with the 30-day compression
policy's background job; tests pause it. Consider retry-on-deadlock or deferred
compression for large historical imports in production.

Claude-Session: https://claude.ai/code/session_01WujdMtMJPbxDpDnMeK22rr
2026-07-13 11:35:54 +02:00

42 lines
1.6 KiB
C#

using MeterVault.Infrastructure.Import;
using static MeterVault.Integration.Tests.Reconciliation.ReconciliationSupport;
namespace MeterVault.Integration.Tests.Reconciliation;
/// <summary>
/// The Kosten sheet is pre-computed category costs (SDD §2.1). The importer stages one manual
/// cost per category column; their monthly sum must equal the sheet's total Kosten column, and
/// the meterless "Pool Betrieb" column becomes manual costs with no meter.
/// </summary>
public sealed class CostsReconciliationTests
{
[Fact]
public void Category_costs_sum_to_the_monthly_total()
{
var staged = Stage(ReferenceProfiles.Costs(), Costs);
var computed = staged.ManualCosts
.GroupBy(c => new DateOnly(c.PeriodStart.Year, c.PeriodStart.Month, 1))
.ToDictionary(g => g.Key, g => g.Sum(c => c.Amount));
var oracle = OracleByMonth(ReadRows(Costs), dateColumn: 0, valueColumn: 2, firstDataRow: 1);
AssertReconciles(computed, oracle, tolerance: 0.02, "category totals", minMatches: 20);
}
[Fact]
public void Manual_costs_are_staged_meterless_by_category()
{
var staged = Stage(ReferenceProfiles.Costs(), Costs);
Assert.NotEmpty(staged.ManualCosts);
Assert.All(staged.ManualCosts, c => Assert.Null(c.MeterId));
// Wasser Dez 2022 = 70,00 € (SDD §2.1: categories decoupled from meters).
var wasserDec = staged.ManualCosts.Single(c =>
c.CategoryId == ReferenceProfiles.CategoryWasser
&& c.PeriodStart == new DateOnly(2022, 12, 1));
Assert.Equal(70d, wasserDec.Amount, 2);
}
}