Skip to content

Commit 639624f

Browse files
committed
Add unit test for Culture awareness in abnormal invocations
1 parent a307770 commit 639624f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/System.CommandLine.Tests/CultureDirectiveTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.CommandLine.Builder;
2+
using System.CommandLine.Help;
23
using System.CommandLine.Invocation;
34
using System.CommandLine.Parsing;
45
using System.Globalization;
@@ -149,5 +150,35 @@ public static async Task Sets_CurrentUICulture_to_invariant_culture()
149150

150151
asserted.Should().BeTrue();
151152
}
153+
154+
public class CultureAwareHelpBuilder : HelpBuilder
155+
{
156+
public CultureAwareHelpBuilder(IConsole console, Action cultureAssert)
157+
: base(console)
158+
{
159+
cultureAssert.Invoke();
160+
}
161+
}
162+
163+
[Fact]
164+
public static async Task CurrentCulture_is_set_when_HelpBuilder_runs()
165+
{
166+
bool asserted = false;
167+
// Make sure we're invariant to begin with
168+
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
169+
var parser = new CommandLineBuilder()
170+
.UseCultureDirective()
171+
.UseHelp()
172+
.UseHelpBuilder(ctx => new CultureAwareHelpBuilder(ctx.Console, () =>
173+
{
174+
asserted = true;
175+
CultureInfo.CurrentCulture.Name.Should().Be("de-DE");
176+
}))
177+
.Build();
178+
179+
await parser.InvokeAsync(new[] { "[culture:de-DE]", "--help" });
180+
181+
asserted.Should().BeTrue();
182+
}
152183
}
153184
}

0 commit comments

Comments
 (0)