-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more test coverage to make sure any behaviour with required argum…
…ents and command interaction is trapped
- Loading branch information
1 parent
9153e6c
commit a74cd43
Showing
7 changed files
with
136 additions
and
2 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
21 changes: 21 additions & 0 deletions
21
test/EntryPointTests/Arguments/AppOptionModels/RequiredCliArguments.cs
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,21 @@ | ||
using EntryPoint; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using EntryPointTests.Arguments.Helpers; | ||
|
||
namespace EntryPointTests.Arguments.AppOptionModels { | ||
public class RequiredCliArguments : BaseCliArguments { | ||
public RequiredCliArguments() : base("Test") { } | ||
|
||
[Required] | ||
[OptionParameter("my-option", 'o')] | ||
public bool MyOption { get; set; } | ||
|
||
public override void OnHelpInvoked(string helpText) { | ||
throw new HelpTriggeredSuccessException(); | ||
} | ||
} | ||
} |
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,40 @@ | ||
using EntryPoint; | ||
using EntryPoint.Exceptions; | ||
using EntryPointTests.Arguments.AppOptionModels; | ||
using EntryPointTests.Arguments.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace EntryPointTests.Arguments { | ||
public class RequiredTests { | ||
[Fact] | ||
public void RequiredProvided() { | ||
string[] args = { | ||
"--my-option=true" | ||
}; | ||
var a = Cli.Parse<RequiredCliArguments>(args); | ||
Assert.Equal(true, a.MyOption); | ||
} | ||
|
||
[Fact] | ||
public void RequiredNotProvided() { | ||
string[] args = { | ||
|
||
}; | ||
Assert.Throws<RequiredException>( | ||
() => Cli.Parse<RequiredCliArguments>(args)); | ||
} | ||
|
||
[Fact] | ||
public void RequiredNotProvided_HelpInvoked() { | ||
string[] args = { | ||
"--help" | ||
}; | ||
Assert.Throws<HelpTriggeredSuccessException>( | ||
() => Cli.Parse<RequiredCliArguments>(args)); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/EntryPointTests/Commands/BaseCommandsHelpers/ArgumentModel_RequiredOptions.cs
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,17 @@ | ||
using EntryPoint; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace EntryPointTests.Commands.BaseCommandsHelpers { | ||
public class ArgumentModel_RequiredOptions : BaseCliArguments { | ||
[Required] | ||
[OptionParameter("my-option", 'o')] | ||
public bool MyOption { get; set; } | ||
|
||
public override void OnHelpInvoked(string helpText) { | ||
throw new EntryPointTests.Arguments.Helpers.HelpTriggeredSuccessException(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/EntryPointTests/Commands/BaseCommandsHelpers/CommandModel_RequiredOptions.cs
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,15 @@ | ||
using EntryPoint; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace EntryPointTests.Commands.BaseCommandsHelpers { | ||
public class CommandModel_RequiredOptions : BaseCliCommands { | ||
[Command("Main")] | ||
public void Main(string[] args) { | ||
var a = Cli.Parse<ArgumentModel_RequiredOptions>(args); | ||
throw new Helpers.CommandExecutedException(a.MyOption.ToString()); | ||
} | ||
} | ||
} |
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,41 @@ | ||
using EntryPoint; | ||
using EntryPoint.Exceptions; | ||
using EntryPointTests.Commands.BaseCommandsHelpers; | ||
using EntryPointTests.Commands.Helpers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace EntryPointTests.Commands { | ||
public class CommandArgumentsTests { | ||
[Fact] | ||
public void Command_RequiredArguments_HelpGenerator() { | ||
string[] args = { | ||
"Main", "--help" | ||
}; | ||
Assert.Throws<Arguments.Helpers.HelpTriggeredSuccessException>( | ||
() => Cli.Execute<CommandModel_RequiredOptions>(args)); | ||
} | ||
|
||
[Fact] | ||
public void Command_RequiredArguments_NotProvided() { | ||
string[] args = { | ||
"Main" | ||
}; | ||
Assert.Throws<RequiredException>( | ||
() => Cli.Execute<CommandModel_RequiredOptions>(args)); | ||
} | ||
|
||
[Fact] | ||
public void Command_RequiredArguments_OK() { | ||
string[] args = { | ||
"Main", "--my-option=true" | ||
}; | ||
var e = Assert.Throws<CommandExecutedException>( | ||
() => Cli.Execute<CommandModel_RequiredOptions>(args)); | ||
Assert.Equal(true.ToString(), e.ParamName); | ||
} | ||
} | ||
} |
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