Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added sample tests from mbedded sample code
- Loading branch information
1 parent
12aac09
commit c88fe2a
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
}), | ||
}; | ||
} | ||
|
||
} | ||
} | ||
} |