File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
tests/ConsoleAppFramework.Tests/Integration Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Threading . Tasks ;
3+ using FluentAssertions ;
4+ using Microsoft . Extensions . Hosting ;
5+ using Xunit ;
6+ // ReSharper disable UnusedMember.Local
7+ // ReSharper disable ClassNeverInstantiated.Local
8+
9+ namespace ConsoleAppFramework . Integration . Test ;
10+
11+ public class FilterTest
12+ {
13+ [ Fact ]
14+ public void ApplyAttributeFilterTest ( )
15+ {
16+ using var console = new CaptureConsoleOutput ( ) ;
17+ var args = new [ ] { "test-argument-name" } ;
18+ Host . CreateDefaultBuilder ( ) . RunConsoleAppFrameworkAsync < TestConsoleApp > ( args ) ;
19+ console . Output . Should ( ) . Contain ( "[in filter] before" ) ;
20+ console . Output . Should ( ) . Contain ( args [ 0 ] ) ;
21+ console . Output . Should ( ) . Contain ( "[in filter] after" ) ;
22+ }
23+
24+ /// <inheritdoc />
25+ private class TestConsoleApp : ConsoleAppBase
26+ {
27+ [ RootCommand ]
28+ [ ConsoleAppFilter ( typeof ( TestFilter ) ) ]
29+ public void RootCommand ( [ Option ( index : 0 ) ] string someArgument ) => Console . WriteLine ( someArgument ) ;
30+ }
31+
32+ /// <inheritdoc />
33+ private class TestFilter : ConsoleAppFilter
34+ {
35+ /// <inheritdoc />
36+ public override async ValueTask Invoke ( ConsoleAppContext context , Func < ConsoleAppContext , ValueTask > next )
37+ {
38+ Console . WriteLine ( "[in filter] before" ) ;
39+ await next ( context ) ;
40+ Console . WriteLine ( "[in filter] after" ) ;
41+ }
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments