-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to declare subcommands. (#2)
* Added the ability to declare subcommands. * Added logic to print subcommand help.
- Loading branch information
Showing
5 changed files
with
136 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace ThorNet.UnitTests | ||
{ | ||
/// <summary> | ||
/// Tests to make sure subcommands are run. | ||
/// </summary> | ||
public class SubcommandTests | ||
{ | ||
[Fact] | ||
public void ConflictingCommandAndSubcommand_Throws() | ||
{ | ||
Assert.Throws<ArgumentOutOfRangeException>(() => | ||
{ | ||
new DuplicateTarget(); | ||
}); | ||
} | ||
|
||
public class DuplicateTarget : Thor | ||
{ | ||
public DuplicateTarget() | ||
{ | ||
Subcommand<Duplicate>(); | ||
} | ||
|
||
public void Duplicate() { } | ||
} | ||
|
||
public class Duplicate : Thor | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void Subcommand_IsTriggered() | ||
{ | ||
Assert.Equal(0, Trigger.Counter); | ||
Thor.Start<TriggerTarget>(new[] { nameof(Trigger), nameof(Trigger.Increment) }); | ||
Assert.Equal(1, Trigger.Counter); | ||
} | ||
|
||
public class TriggerTarget : Thor | ||
{ | ||
public TriggerTarget() | ||
{ | ||
Subcommand<Trigger>(); | ||
} | ||
} | ||
|
||
public class Trigger : Thor | ||
{ | ||
public static int Counter => _counter; | ||
static int _counter; | ||
|
||
public void Increment() { _counter++; } | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -30,5 +30,5 @@ | |
"tooling": { | ||
"defaultNamespace": "ThorNet" | ||
}, | ||
"version": "0.2.1" | ||
"version": "0.3.0" | ||
} |