-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathResourceLocalizationTests.cs
74 lines (58 loc) · 2.54 KB
/
ResourceLocalizationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.CommandLine.Parsing;
using FluentAssertions;
using System.Linq;
using Xunit;
namespace System.CommandLine.Tests
{
public class ResourceLocalizationTests
{
[Fact]
public void Default_validation_messages_can_be_replaced_in_order_to_add_localization_support()
{
var messages = new FakeLocalizationResources("the-message");
var command = new Command("the-command")
{
new Argument<string>()
};
var parser = new Parser(new CommandLineConfiguration(command, resources: messages));
var result = parser.Parse("the-command");
result.Errors
.Select(e => e.Message)
.Should()
.Contain("the-message");
}
[Fact]
public void Default_validation_messages_can_be_replaced_using_CommandLineBuilder_in_order_to_add_localization_support()
{
var messages = new FakeLocalizationResources("the-message");
var parser = new CommandLineBuilder(new Command("the-command")
{
new Argument<string>()
})
.UseLocalizationResources(messages)
.Build();
var result = parser.Parse("the-command");
result.Errors
.Select(e => e.Message)
.Should()
.Contain("the-message");
}
public class FakeLocalizationResources : LocalizationResources
{
private readonly string message;
public FakeLocalizationResources(string message)
{
this.message = message;
}
public override string ExpectsOneArgument(SymbolResult symbolResult) => message;
public override string FileDoesNotExist(string filePath) => message;
public override string RequiredArgumentMissing(Argument argument, SymbolResult symbolResult) => message;
public override string RequiredCommandWasNotProvided() => message;
public override string UnrecognizedArgument(string unrecognizedArg, IReadOnlyCollection<string> allowedValues) => message;
public override string UnrecognizedCommandOrArgument(string arg) => message;
}
}
}