-
Notifications
You must be signed in to change notification settings - Fork 416
Expand file tree
/
Copy pathTestActions.cs
More file actions
64 lines (52 loc) · 1.77 KB
/
TestActions.cs
File metadata and controls
64 lines (52 loc) · 1.77 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
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
namespace System.CommandLine.Tests;
public class SynchronousTestAction : SynchronousCommandLineAction
{
private readonly Action<ParseResult> _invoke;
private readonly int _returnValue;
public SynchronousTestAction(
Action<ParseResult> invoke,
bool terminating = true,
bool clearsParseErrors = false,
int returnValue = 0)
{
ClearsParseErrors = clearsParseErrors;
_invoke = invoke;
_returnValue = returnValue;
Terminating = terminating;
}
public override bool ClearsParseErrors { get; }
public override bool Terminating { get; }
public override int Invoke(ParseResult parseResult)
{
_invoke(parseResult);
return _returnValue;
}
}
public class AsynchronousTestAction : AsynchronousCommandLineAction
{
private readonly Action<ParseResult> _invoke;
private readonly int _returnValue;
public AsynchronousTestAction(
Action<ParseResult> invoke,
bool terminating = true,
bool clearsParseErrors = false,
int returnValue = 0)
{
ClearsParseErrors = clearsParseErrors;
_invoke = invoke;
_returnValue = returnValue;
Terminating = terminating;
}
public override bool ClearsParseErrors { get; }
public override bool Terminating { get; }
public override Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken = default)
{
_invoke(parseResult);
return Task.FromResult(_returnValue);
}
}