BadScript 2
Loading...
Searching...
No Matches
Issue543Tests.cs
Go to the documentation of this file.
1
using
System.Collections.Generic;
2
using
System.Linq;
3
using
Xunit;
4
using
CommandLine.Text
;
5
6
namespace
CommandLine.Tests.Unit
7
{
8
//Reference: PR# 634
9
public
class
Issue543Tests
10
{
11
12
private
const
int
ERROR_SUCCESS
= 0;
13
14
[Fact]
15
public
void
Parser_GiveHelpArgument_ExpectSuccess
()
16
{
17
var result =
Parser
.
Default
.
ParseArguments
<
Options
>(
new
[] {
"--help"
});
18
19
Assert.Equal(
ParserResultType
.NotParsed, result.Tag);
20
Assert.Null(result.Value);
21
Assert.NotEmpty(result.Errors);
22
}
23
24
[Fact]
25
public
void
Parser_GiveConnectionStringAndJobId_ExpectSuccess
()
26
{
27
var result =
Parser
.
Default
.
ParseArguments
<
Options
>(
new
[] {
28
"-c"
,
"someConnectionString"
,
29
"-j"
,
"1234"
,
30
});
31
32
Assert.Equal(
ParserResultType
.Parsed, result.Tag);
33
Assert.NotNull(result.Value);
34
Assert.Empty(result.Errors);
35
Assert.Equal(
"someConnectionString"
, result.Value.ConnectionString);
36
Assert.Equal(1234, result.Value.JobId);
37
}
38
39
[Fact]
40
public
void
Parser_GiveVerb1_ExpectSuccess
()
41
{
42
var result =
Parser
.
Default
.
ParseArguments
<
Verb1Options
,
Verb2Options
>(
new
[] {
43
"verb1"
,
44
"-j"
,
"1234"
,
45
});
46
47
Assert.Equal(
ParserResultType
.Parsed, result.Tag);
48
Assert.Empty(result.Errors);
49
Assert.NotNull(result.Value);
50
Assert.NotNull(result.Value as
Verb1Options
);
51
Assert.Equal(1234, (result.Value as
Verb1Options
).JobId);
52
}
53
54
[Fact]
55
public
void
Parser_GiveVerb2_ExpectSuccess
()
56
{
57
var result =
Parser
.
Default
.
ParseArguments
<
Verb1Options
,
Verb2Options
>(
new
[] {
58
"verb2"
,
59
"-c"
,
"someConnectionString"
,
60
});
61
62
Assert.Equal(
ParserResultType
.Parsed, result.Tag);
63
Assert.Empty(result.Errors);
64
Assert.NotNull(result.Value);
65
Assert.NotNull(result.Value as
Verb2Options
);
66
Assert.Equal(
"someConnectionString"
, (result.Value as
Verb2Options
).ConnectionString);
67
}
68
69
// Options
70
internal
class
Options
71
{
72
[Option(
'c'
,
"connectionString"
, Required =
true
,
HelpText
=
"Texts.ExplainConnection"
)]
73
public
string
ConnectionString
{
get
;
set
; }
74
75
[Option(
'j'
,
"jobId"
, Required =
true
,
HelpText
=
"Texts.ExplainJob"
)]
76
public
int
JobId
{
get
;
set
; }
77
78
[Usage(ApplicationAlias =
"Importer.exe"
)]
79
public
static
IEnumerable<Example>
Examples
80
{
81
get
=>
new
[] {
82
new
Example
(
"Texts.ExplainExampleExecution"
,
new
Options
() {
83
ConnectionString
=
"Server=MyServer;Database=MyDatabase"
,
84
JobId
= 5
85
}),
86
};
87
}
88
}
89
90
// Options
91
[Verb(
"verb1"
)]
92
internal
class
Verb1Options
93
{
94
[Option(
'j'
,
"jobId"
, Required =
false
,
HelpText
=
"Texts.ExplainJob"
)]
95
public
int
JobId
{
get
;
set
; }
96
}
97
98
// Options
99
[Verb(
"verb2"
)]
100
internal
class
Verb2Options
101
{
102
[Option(
'c'
,
"connectionString"
, Required =
false
,
HelpText
=
"Texts.ExplainConnection"
)]
103
public
string
ConnectionString
{
get
;
set
; }
104
}
105
106
}
107
}
108
CommandLine.Parser
Provides methods to parse command line arguments.
Definition
Parser.cs:21
CommandLine.Parser.ParseArguments
ParserResult< object > ParseArguments(IEnumerable< string > args, params Type[] types)
Parses a string array of command line arguments for verb commands scenario, constructing the proper i...
Definition
Parser.cs:216
CommandLine.Parser.Default
static Parser Default
Gets the singleton instance created with basic defaults.
Definition
Parser.cs:75
CommandLine.Tests.Unit.Issue543Tests.Options
Definition
Issue543Tests.cs:71
CommandLine.Tests.Unit.Issue543Tests.Options.JobId
int JobId
Definition
Issue543Tests.cs:76
CommandLine.Tests.Unit.Issue543Tests.Options.ConnectionString
string ConnectionString
Definition
Issue543Tests.cs:73
CommandLine.Tests.Unit.Issue543Tests.Options.Examples
static IEnumerable< Example > Examples
Definition
Issue543Tests.cs:80
CommandLine.Tests.Unit.Issue543Tests.Verb1Options
Definition
Issue543Tests.cs:93
CommandLine.Tests.Unit.Issue543Tests.Verb1Options.JobId
int JobId
Definition
Issue543Tests.cs:95
CommandLine.Tests.Unit.Issue543Tests.Verb2Options
Definition
Issue543Tests.cs:101
CommandLine.Tests.Unit.Issue543Tests.Verb2Options.ConnectionString
string ConnectionString
Definition
Issue543Tests.cs:103
CommandLine.Tests.Unit.Issue543Tests
Definition
Issue543Tests.cs:10
CommandLine.Tests.Unit.Issue543Tests.Parser_GiveVerb1_ExpectSuccess
void Parser_GiveVerb1_ExpectSuccess()
Definition
Issue543Tests.cs:40
CommandLine.Tests.Unit.Issue543Tests.Parser_GiveConnectionStringAndJobId_ExpectSuccess
void Parser_GiveConnectionStringAndJobId_ExpectSuccess()
Definition
Issue543Tests.cs:25
CommandLine.Tests.Unit.Issue543Tests.Parser_GiveHelpArgument_ExpectSuccess
void Parser_GiveHelpArgument_ExpectSuccess()
Definition
Issue543Tests.cs:15
CommandLine.Tests.Unit.Issue543Tests.Parser_GiveVerb2_ExpectSuccess
void Parser_GiveVerb2_ExpectSuccess()
Definition
Issue543Tests.cs:55
CommandLine.Tests.Unit.Issue543Tests.ERROR_SUCCESS
const int ERROR_SUCCESS
Definition
Issue543Tests.cs:12
CommandLine.Text.Example
Models a command line usage example.
Definition
Example.cs:13
CommandLine.Text.HelpText
Definition
HelpText.cs:33
CommandLine.Tests.Unit
Definition
BaseAttributeTests.cs:5
CommandLine.Text
Definition
AssemblyLicenseAttribute.cs:7
CommandLine.ParserResultType
ParserResultType
Discriminator enumeration of CommandLine.ParserResultType derivates.
Definition
ParserResult.cs:36
deps
commandlineparser
tests
CommandLine.Tests
Unit
Issue543Tests.cs
Generated by
1.9.8