-
Notifications
You must be signed in to change notification settings - Fork 470
/
Issue389_Tests.cs
78 lines (61 loc) · 1.61 KB
/
Issue389_Tests.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
75
76
77
78
using CommandLine.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
namespace CommandLine.Tests.Unit
{
public class Issue389_Tests
{
private const int ERROR_SUCCESS = 0;
// Test method (xUnit) which fails
[Fact]
public void CallMain_GiveHelpArgument_ExpectSuccess()
{
var result = Program.__Main(new[] { "--help" });
Assert.Equal(ERROR_SUCCESS, result);
}
// main program
internal class Program
{
internal static int __Main(string[] args)
{
bool hasError = false;
bool helpOrVersionRequested = false;
ParserResult<Options> parsedOptions = Parser.Default.ParseArguments<Options>(args)
.WithNotParsed(errors => {
helpOrVersionRequested = errors.Any(
x => x.Tag == ErrorType.HelpRequestedError
|| x.Tag == ErrorType.VersionRequestedError);
hasError = true;
});
if(helpOrVersionRequested)
{
return ERROR_SUCCESS;
}
// Execute as a normal call
// ...
return ERROR_SUCCESS;
}
}
// Options
internal class Options
{
[Option('c', "connectionString", Required = true, HelpText = "Texts.ExplainConnection")]
public string ConnectionString { get; set; }
[Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")]
public int JobId { get; set; }
[Usage(ApplicationAlias = "Importer.exe")]
public static IEnumerable<Example> Examples
{
get => new[] {
new Example("Texts.ExplainExampleExecution", new Options() {
ConnectionString="Server=MyServer;Database=MyDatabase",
JobId = 5
}),
};
}
}
}
}