using MeterVault.Core.Domain; using MeterVault.Infrastructure.Import; namespace MeterVault.Integration.Tests.Import; /// /// The importer is the only place that still sees whether a date cell named a month or a day, so it is /// where a row becomes a month label. Both are stamped at midnight on the 1st; only the month means /// "the register at the end of that month". Pure, so no Docker. /// public sealed class MonthLabelImportTests { [Theory] [InlineData(DateKind.MonthName, "August 2026", true)] [InlineData(DateKind.DayDotMonthYear, "01.08.2026", false)] [InlineData(DateKind.Auto, "August 2026", true)] [InlineData(DateKind.Auto, "01.08.2026", false)] public void A_row_is_a_month_label_only_when_its_date_named_a_month(DateKind kind, string date, bool label) { var reading = Assert.Single(Stage(kind, anchorToEnd: false, $"{date},700").Readings); Assert.Equal(new DateTimeOffset(2026, 8, 1, 0, 0, 0, TimeSpan.Zero), reading.Time); Assert.Equal(label, reading.Flags.HasFlag(ReadingFlags.MonthLabel)); } [Fact] public void A_month_anchored_to_its_last_day_is_stamped_where_it_belongs_and_is_no_label() { var reading = Assert.Single(Stage(DateKind.Auto, anchorToEnd: true, "August 2026,700").Readings); Assert.Equal(new DateTimeOffset(2026, 8, 31, 0, 0, 0, TimeSpan.Zero), reading.Time); Assert.False(reading.Flags.HasFlag(ReadingFlags.MonthLabel)); } private static StagedImport Stage(DateKind kind, bool anchorToEnd, string row) { var profile = new MappingProfile { Name = "test", DateColumn = 0, DateKind = kind, AnchorMonthsToEnd = anchorToEnd, FirstDataRowIndex = 0, Columns = [new ColumnMapping { Index = 1, Role = MappingRole.Reading, MeterId = 1, Unit = "m3" }], }; using var reader = new StringReader(row); return new CsvImporter().Stage(profile, reader); } }