|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using MatthiWare.CommandLine; |
| 5 | +using MatthiWare.CommandLine.Abstractions; |
| 6 | +using MatthiWare.CommandLine.Abstractions.Command; |
| 7 | +using MatthiWare.CommandLine.Abstractions.Usage; |
| 8 | +using MatthiWare.CommandLine.Core.Attributes; |
| 9 | +using Moq; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace MatthiWare.CommandLineParser.Tests.Usage |
| 13 | +{ |
| 14 | + public class HelpDisplayCommandTests |
| 15 | + { |
| 16 | + [Theory] |
| 17 | + [InlineData(new string[] { "db", "--help" }, true)] |
| 18 | + [InlineData(new string[] { "db" }, true)] |
| 19 | + [InlineData(new string[] { "db", "-o", "--help" }, true)] |
| 20 | + [InlineData(new string[] { "db", "-o", "help" }, false)] |
| 21 | + [InlineData(new string[] { "-x", "blabla", "--help" }, true)] |
| 22 | + [InlineData(new string[] { }, true)] |
| 23 | + [InlineData(new string[] { "-x", "--help" }, true)] |
| 24 | + [InlineData(new string[] { "--help" }, true)] |
| 25 | + public void TestHelpDisplayFiresCorrectly(string[] args, bool fires) |
| 26 | + { |
| 27 | + bool calledFlag = false; |
| 28 | + |
| 29 | + var usagePrinterMock = new Mock<IUsagePrinter>(); |
| 30 | + |
| 31 | + usagePrinterMock.Setup(mock => mock.PrintUsage()).Callback(() => calledFlag = true); |
| 32 | + usagePrinterMock.Setup(mock => mock.PrintUsage(It.IsAny<ICommandLineCommand>())).Callback(() => calledFlag = true); |
| 33 | + usagePrinterMock.Setup(mock => mock.PrintUsage(It.IsAny<ICommandLineOption>())).Callback(() => calledFlag = true); |
| 34 | + |
| 35 | + var parser = new CommandLineParser<Options> |
| 36 | + { |
| 37 | + Printer = usagePrinterMock.Object |
| 38 | + }; |
| 39 | + |
| 40 | + var cmd = parser.AddCommand<CommandOptions>() |
| 41 | + .Name("db") |
| 42 | + .Description("Database commands"); |
| 43 | + |
| 44 | + parser.Parse(args); |
| 45 | + |
| 46 | + Assert.Equal<bool>(fires, calledFlag); |
| 47 | + } |
| 48 | + |
| 49 | + public class Options |
| 50 | + { |
| 51 | + [Name("x"), Description("Some description")] |
| 52 | + public string Option { get; set; } |
| 53 | + } |
| 54 | + |
| 55 | + public class CommandOptions |
| 56 | + { |
| 57 | + [Name("o"), Description("Some description"), Required] |
| 58 | + public string Option { get; set; } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments