-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelpCommandFixture.cs
More file actions
87 lines (74 loc) · 2.46 KB
/
HelpCommandFixture.cs
File metadata and controls
87 lines (74 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using NSubstitute;
using NUnit.Framework;
using Octopus.CommandLine;
using Octopus.CommandLine.Commands;
using Serilog;
using Shouldly;
using Tests.Helpers;
namespace Tests.Commands;
[TestFixture]
public class HelpCommandFixture
{
HelpCommand helpCommand;
ICommandLocator commandLocator;
StringWriter output;
TextWriter originalOutput;
ICommandOutputProvider commandOutputProvider;
ILogger logger;
[SetUp]
public void SetUp()
{
originalOutput = Console.Out;
output = new StringWriter();
Console.SetOut(output);
commandLocator = Substitute.For<ICommandLocator>();
logger = new LoggerConfiguration().WriteTo.TextWriter(output).CreateLogger();
commandOutputProvider = new CommandOutputProvider("TestApp", "0.0.0", new DefaultCommandOutputJsonSerializer(), logger);
helpCommand = new HelpCommand(new Lazy<ICommandLocator>(() => commandLocator), commandOutputProvider);
}
[Test]
public void ShouldPrintGeneralHelpWhenNoArgsGiven()
{
commandLocator.List()
.Returns([
new Metadata { Name = "create-foo" },
new Metadata { Name = "create-bar" }
]);
helpCommand.Execute();
output.ToString()
.ShouldSatisfyAllConditions(
actual => actual.ShouldMatch(@"Usage: (dotnet|testhost.*|ReSharperTestRunner64) <command> \[<options>\]"),
actual => actual.ShouldContain("Where <command> is one of:"),
actual => actual.ShouldContain("create-foo")
);
}
[Test]
public void ShouldPrintHelpForExistingCommand()
{
var speak = new SpeakCommand(commandOutputProvider);
commandLocator.Find("speak").Returns(speak);
helpCommand.Execute("speak");
output.ToString()
.ShouldMatch(@"Usage: (dotnet|testhost.*|ReSharperTestRunner64) speak \[<options>\]");
}
[Test]
public void ShouldFailForUnrecognisedCommand()
{
commandLocator.Find("foo").Returns((ICommand)null);
helpCommand.Execute("foo");
output.ToString().ShouldContain("Command 'foo' is not supported");
}
[TearDown]
public void TearDown()
{
Console.SetOut(originalOutput);
}
class Metadata : ICommandMetadata
{
public string Name { get; set; }
public string[] Aliases { get; set; }
public string Description { get; set; }
}
}