-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathProgram_Tests.cs
62 lines (52 loc) · 1.68 KB
/
Program_Tests.cs
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
// SPDX-FileCopyrightText: 2022 Frans van Dorsselaer
//
// SPDX-License-Identifier: GPL-2.0-only
using System.CommandLine;
namespace UnitTests;
using ExitCode = Program.ExitCode;
[TestClass]
sealed class Program_Tests
: ParseTestBase
{
[TestMethod]
public void MainSuccess()
{
var exitCode = (ExitCode)Program.Main(new string[] { "--version" });
Assert.AreEqual(ExitCode.Success, exitCode);
}
[TestMethod]
public void MainParseError()
{
var exitCode = (ExitCode)Program.Main(new string[] { "unknown-command" });
Assert.AreEqual(ExitCode.ParseError, exitCode);
}
[TestMethod]
public void RunInvalidExitCode()
{
var mock = CreateMock();
mock.Setup(m => m.License(
It.IsNotNull<IConsole>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult((ExitCode)0x0badf00d));
Assert.ThrowsException<UnexpectedResultException>(() =>
{
Test(ExitCode.Success, mock, "license");
});
}
[TestMethod]
public void RunException()
{
var mock = CreateMock();
mock.Setup(m => m.License(
It.IsNotNull<IConsole>(), It.IsAny<CancellationToken>())).Throws<NotImplementedException>();
var exception = Assert.ThrowsException<AggregateException>(() =>
{
Test(ExitCode.Success, mock, "license");
});
Assert.IsInstanceOfType(exception.InnerException, typeof(NotImplementedException));
}
[TestMethod]
public void CompletionGuard_DoesNotThrow()
{
var completions = Program.CompletionGuard(null!, null!);
Assert.IsTrue(completions.SequenceEqual(Array.Empty<string>()));
}
}