5977c81002
- 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
82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using MeterVault.Core.Parsing;
|
|
|
|
namespace MeterVault.Core.Tests;
|
|
|
|
public sealed class GermanParsingTests
|
|
{
|
|
[Theory]
|
|
[InlineData("411kWh", 411)]
|
|
[InlineData("2.940,19", 2940.19)]
|
|
[InlineData("180,8244706", 180.8244706)]
|
|
[InlineData("-90kWh", -90)]
|
|
[InlineData("0,31", 0.31)]
|
|
[InlineData("49", 49)]
|
|
[InlineData("2287", 2287)]
|
|
[InlineData("1.295,19 €", 1295.19)]
|
|
[InlineData("5,98", 5.98)]
|
|
[InlineData("0kWh", 0)]
|
|
public void GermanNumber_parses_dialect(string raw, double expected)
|
|
{
|
|
Assert.True(GermanNumber.TryParse(raw, out var value));
|
|
Assert.Equal(expected, value, 6);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
[InlineData("kWh")]
|
|
[InlineData("abc")]
|
|
public void GermanNumber_rejects_non_numeric(string raw) =>
|
|
Assert.False(GermanNumber.TryParse(raw, out _));
|
|
|
|
[Theory]
|
|
[InlineData("120,00 €", 120.00, "EUR")]
|
|
[InlineData("2.940,19 €", 2940.19, "EUR")]
|
|
[InlineData("70 €", 70, "EUR")]
|
|
[InlineData("-0,80 €", -0.80, "EUR")]
|
|
public void GermanMoney_parses_currency(string raw, decimal expected, string currency)
|
|
{
|
|
Assert.True(GermanMoney.TryParse(raw, out var amount, out var cur));
|
|
Assert.Equal(expected, amount);
|
|
Assert.Equal(currency, cur);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("2287L", 2287, "L")]
|
|
[InlineData("411kWh", 411, "kWh")]
|
|
[InlineData("49", 49, null)]
|
|
[InlineData("35 cm", 35, "cm")]
|
|
public void ValueCell_splits_value_and_unit(string raw, double value, string? unit)
|
|
{
|
|
var result = ValueCell.Split(raw);
|
|
Assert.NotNull(result);
|
|
Assert.Equal(value, result!.Value.Value, 6);
|
|
Assert.Equal(unit, result.Value.Unit);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("September 2022", 2022, 9)]
|
|
[InlineData("März 2023", 2023, 3)]
|
|
[InlineData("Dezember 2026", 2026, 12)]
|
|
public void GermanDate_parses_month_tables(string raw, int year, int month)
|
|
{
|
|
Assert.True(GermanDate.TryParseMonth(raw, out var date));
|
|
Assert.Equal(new DateOnly(year, month, 1), date);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("10.06.1997", 1997, 6, 10)]
|
|
[InlineData("13.07.2026", 2026, 7, 13)]
|
|
public void GermanDate_parses_event_rows(string raw, int year, int month, int day)
|
|
{
|
|
Assert.True(GermanDate.TryParseDay(raw, out var date));
|
|
Assert.Equal(new DateOnly(year, month, day), date);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("10.06.1997")]
|
|
[InlineData("September 2022")]
|
|
public void GermanDate_auto_detects_both_shapes(string raw) =>
|
|
Assert.True(GermanDate.TryParse(raw, out _));
|
|
}
|