using System.Globalization; using MeterVault.App; namespace MeterVault.Integration.Tests.Localization; /// /// formats against the reader's culture rather than a fixed de-DE (SDD §12, M7). /// /// /// The importer's de-DE parsing is deliberately untouched by this: that dialect is a property of the /// spreadsheet files, not of who is looking at the dashboard, and GermanParsingTests pins it. /// public sealed class FormatCultureTests { [Fact] public void Digit_grouping_follows_the_reader() { Assert.Equal("1.234,5", WithCulture("de", () => Format.Number(1234.5, 1))); Assert.Equal("1,234.5", WithCulture("en", () => Format.Number(1234.5, 1))); Assert.Equal("2.940", WithCulture("de", () => Format.Number(2940))); Assert.Equal("2,940", WithCulture("en", () => Format.Number(2940))); } [Fact] public void The_currency_symbol_stays_the_instances_own() { // Only the grouping is localized. The figures are in the instance's configured currency, so // an English reader must see the same money written their way — not relabelled as dollars. Assert.Equal("1.234,50 €", WithCulture("de", () => Format.Euro(1234.5))); Assert.Equal("1,234.50 €", WithCulture("en", () => Format.Euro(1234.5))); } [Fact] public void Percentages_keep_their_explicit_sign() { Assert.Equal("+12,4 %", WithCulture("de", () => Format.Percent(12.4))); Assert.Equal("+12.4 %", WithCulture("en", () => Format.Percent(12.4))); Assert.Equal("-7,2 %", WithCulture("de", () => Format.Percent(-7.2))); Assert.Equal("-7.2 %", WithCulture("en", () => Format.Percent(-7.2))); } [Fact] public void Month_labels_are_written_in_the_readers_language() { var march = new DateOnly(2025, 3, 1); var german = WithCulture("de", () => Format.MonthLabel(march)); var english = WithCulture("en", () => Format.MonthLabel(march)); // Asserting the exact German abbreviation would pin us to one ICU version ("Mrz" vs "Mär"), // so assert what actually matters: the label is culture-sensitive, not invariant. Assert.Equal("Mar 25", english); Assert.NotEqual(english, german); Assert.EndsWith("25", german, StringComparison.Ordinal); } [Fact] public void Direction_icons_are_language_neutral() { Assert.Equal("▲", Format.DirectionIcon(1)); Assert.Equal("▼", Format.DirectionIcon(-1)); Assert.Equal("—", Format.DirectionIcon(0)); } private static T WithCulture(string culture, Func body) { var previous = CultureInfo.CurrentCulture; try { CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(culture); return body(); } finally { CultureInfo.CurrentCulture = previous; } } }