1
1
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using System . CommandLine . Builder ;
4
5
using System . CommandLine . IO ;
5
6
using FluentAssertions ;
6
7
using Xunit ;
@@ -10,7 +11,7 @@ namespace System.CommandLine.Tests
10
11
public class CommandExtensionsTests
11
12
{
12
13
[ Fact ]
13
- public void Mulitple_invocations_via_Invoke_extension_will_not_reconfigure_implicit_parser ( )
14
+ public void Command_Invoke_can_be_called_more_than_once_for_the_same_command ( )
14
15
{
15
16
var command = new RootCommand ( "Root command description" )
16
17
{
@@ -22,12 +23,34 @@ public void Mulitple_invocations_via_Invoke_extension_will_not_reconfigure_impli
22
23
command . Invoke ( "-h" , console1 ) ;
23
24
24
25
console1 . Out . ToString ( ) . Should ( ) . Contain ( command . Description ) ;
25
-
26
+
26
27
var console2 = new TestConsole ( ) ;
27
28
28
29
command . Invoke ( "-h" , console2 ) ;
29
30
30
31
console2 . Out . ToString ( ) . Should ( ) . Contain ( command . Description ) ;
31
32
}
33
+
34
+ [ Fact ]
35
+ public void When_CommandLineBuilder_is_used_then_Command_Invoke_uses_its_configuration ( )
36
+ {
37
+ var command = new RootCommand ( ) ;
38
+
39
+ new CommandLineBuilder ( command )
40
+ . UseMiddleware ( context =>
41
+ {
42
+ context . Console . Out . Write ( "hello!" ) ;
43
+ } )
44
+ . Build ( ) ;
45
+
46
+ var console = new TestConsole ( ) ;
47
+
48
+ command . Invoke ( "" , console ) ;
49
+
50
+ console . Out
51
+ . ToString ( )
52
+ . Should ( )
53
+ . Contain ( "hello!" ) ;
54
+ }
32
55
}
33
56
}
0 commit comments