Skip to content

Commit

Permalink
added sample tests from mbedded sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnewton76 committed Jan 18, 2019
1 parent 12aac09 commit c88fe2a
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/CommandLine.Tests/Unit/Issue389_Tests.cs
@@ -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
}),
};
}

}
}
}

0 comments on commit c88fe2a

Please sign in to comment.