-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy pathIssue830Tests.cs
65 lines (54 loc) · 1.94 KB
/
Issue830Tests.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
using System.Collections.Generic;
using System.IO;
using CommandLine.Text;
using FluentAssertions;
using Xunit;
// Issue #830
// Allow private properties as options and usage
namespace CommandLine.Tests.Unit
{
public class Issue830Tests
{
[Fact]
public void Parse_options_with_private_value_and_option()
{
var expectedOptions = new Options
{
Option = "a",
Value = "b"
};
var result = Parser.Default.ParseArguments<Options>(
new[] { "b", "--opt", "a" });
((Parsed<Options>)result).Value.Should().BeEquivalentTo(expectedOptions);
}
[Fact]
public void Print_private_usage()
{
var help = new StringWriter();
var sut = new Parser(config => config.HelpWriter = help);
sut.ParseArguments<Options>(new string[] { "--help" });
var result = help.ToString();
var lines = result.ToLines().TrimStringArray();
lines[3].Should().BeEquivalentTo("Do something very cool:");
lines[4].Should().BeEquivalentTo("myApp.txt --opt test1 test2");
}
private class Options
{
public string Option { get => PrivateOption; set => PrivateOption = value; }
public string Value { get => PrivateValue; set => PrivateValue = value; }
[Option("opt", Required = true)]
private string PrivateOption { get; set; }
[Value(0, Required = true)]
private string PrivateValue { get; set; }
[Usage(ApplicationAlias = "myApp.txt")]
private static IEnumerable<Example> PrivateUsage { get; } = new List<Example>
{
new Example("Do something very cool", new Options
{
PrivateOption = "test1",
PrivateValue = "test2"
})
};
}
}
}