forked from commandlineparser/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
4 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
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
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,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("CommandLine --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] | ||
private static IEnumerable<Example> PrivateUsage { get; } = new List<Example> | ||
{ | ||
new Example("Do something very cool", new Options | ||
{ | ||
PrivateOption = "test1", | ||
PrivateValue = "test2" | ||
}) | ||
}; | ||
} | ||
} | ||
} |