-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathGetting_Started_100_Calculator.cs
74 lines (58 loc) · 2.14 KB
/
Getting_Started_100_Calculator.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
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using CommandDotNet.TestTools;
using CommandDotNet.TestTools.Scenarios;
using NUnit.Framework;
namespace CommandDotNet.DocExamples.GettingStarted;
[TestFixture]
public class Getting_Started_100_Calculator
{
// begin-snippet: getting-started-100-calculator
public class Program
{
// this is the entry point of your application
static int Main(string[] args)
{
// AppRunner<T> where T is the class defining your commands
// You can use Program or create commands in another class
return new AppRunner<Program>().Run(args);
}
// Add command with two positional arguments
public void Add(int x, int y) => Console.WriteLine(x + y);
// Subtract command with two positional arguments
public void Subtract(int x, int y) => Console.WriteLine(x - y);
}
// end-snippet
public static BashSnippet Help = new("getting-started-100-calculator-help",
new AppRunner<Program>(),
"dotnet calculator.dll", "--help", 0,
@"Usage: {0} [command]
Commands:
Add
Subtract
Use ""{0} [command] --help"" for more information about a command.");
public static BashSnippet Help_Add = new("getting-started-100-calculator-add-help",
new AppRunner<Program>(),
"dotnet calculator.dll", "Add -h", 0,
@"Usage: {0} Add <x> <y>
Arguments:
x <NUMBER>
y <NUMBER>");
public static BashSnippet Add = new("getting-started-100-calculator-add",
new AppRunner<Program>().InterceptSystemConsoleWrites(),
"dotnet calculator.dll", "Add 40 20", 0,
@"60");
public static BashSnippet Add_Invalid = new("getting-started-100-calculator-add-invalid",
new AppRunner<Program>(),
"dotnet calculator.dll", "Add a 20", 2,
@"'a' is not a valid Number");
// Test commands not testing via BashSnippet
[Test]
public void Subtract_works() =>
new AppRunner<Program>()
.InterceptSystemConsoleWrites()
.Verify(new Scenario
{
When = { Args = "Subtract 40 20" },
Then = { Output = "20" }
});
}