2121namespace ECoreNetto . Tools . Tests . Commands
2222{
2323 using System ;
24- using System . CommandLine . Invocation ;
24+ using System . CommandLine ;
2525 using System . IO ;
26+ using System . Threading ;
2627 using System . Threading . Tasks ;
2728
2829 using ECoreNetto . Reporting . Generators ;
2930 using ECoreNetto . Tools . Commands ;
31+ using ECoreNetto . Tools . Services ;
3032
3133 using Moq ;
32-
3334 using NUnit . Framework ;
3435
3536 /// <summary>
@@ -38,24 +39,36 @@ namespace ECoreNetto.Tools.Tests.Commands
3839 [ TestFixture ]
3940 public class MarkdownReportCommandTestFixture
4041 {
42+ private RootCommand rootCommand ;
43+
4144 private Mock < IMarkdownReportGenerator > markdownReportGenerator ;
4245
46+ private Mock < IVersionChecker > versionChecker ;
47+
4348 private MarkdownReportCommand . Handler handler ;
4449
50+ private CancellationTokenSource cts ;
51+
4552 [ SetUp ]
4653 public void SetUp ( )
4754 {
55+ this . cts = new CancellationTokenSource ( ) ;
56+
57+ var markdownReportCommand = new MarkdownReportCommand ( ) ;
58+ this . rootCommand = new RootCommand ( ) ;
59+ this . rootCommand . Add ( markdownReportCommand ) ;
60+
4861 this . markdownReportGenerator = new Mock < IMarkdownReportGenerator > ( ) ;
62+ this . versionChecker = new Mock < IVersionChecker > ( ) ;
4963
5064 this . markdownReportGenerator . Setup ( x => x . IsValidReportExtension ( It . IsAny < FileInfo > ( ) ) )
5165 . Returns ( new Tuple < bool , string > ( true , "valid extension" ) ) ;
5266
53- this . handler = new MarkdownReportCommand . Handler (
54- this . markdownReportGenerator . Object ) ;
67+ this . handler = new MarkdownReportCommand . Handler ( this . markdownReportGenerator . Object , this . versionChecker . Object ) ;
5568 }
5669
5770 [ Test ]
58- public void Verify_that_inspect_command_can_be_constructed ( )
71+ public void Verify_that_MarkdownReportCommand_can_be_constructed ( )
5972 {
6073 Assert . That ( ( ) =>
6174 {
@@ -66,42 +79,59 @@ public void Verify_that_inspect_command_can_be_constructed()
6679 [ Test ]
6780 public async Task Verify_that_InvokeAsync_returns_0 ( )
6881 {
69- var invocationContext = new InvocationContext ( null ! ) ;
82+ var args = new [ ]
83+ {
84+ "md-report" ,
85+ "--no-logo" ,
86+ "--input-model" , Path . Combine ( TestContext . CurrentContext . TestDirectory , "Data" , "recipe.ecore" ) ,
87+ "--output-report" , Path . Combine ( TestContext . CurrentContext . TestDirectory , "md-report.md" )
88+ } ;
7089
71- this . handler . InputModel = new FileInfo ( Path . Combine ( TestContext . CurrentContext . TestDirectory , "Data" , "recipe.ecore" ) ) ;
72- this . handler . OutputReport = new FileInfo ( Path . Combine ( TestContext . CurrentContext . TestDirectory , "md-report.md" ) ) ;
90+ var parseResult = this . rootCommand . Parse ( args ) ;
7391
74- var result = await this . handler . InvokeAsync ( invocationContext ) ;
92+ var result = await this . handler . InvokeAsync ( parseResult , this . cts . Token ) ;
7593
7694 this . markdownReportGenerator . Verify ( x => x . GenerateReport ( It . IsAny < FileInfo > ( ) , It . IsAny < FileInfo > ( ) ) , Times . Once ) ;
7795
96+ this . versionChecker . Verify ( x => x . ExecuteAsync ( It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
97+
7898 Assert . That ( result , Is . EqualTo ( 0 ) , "InvokeAsync should return 0 upon success." ) ;
7999 }
80100
81101 [ Test ]
82102 public async Task Verify_that_when_the_input_ecore_model_does_not_exists_returns_not_0 ( )
83103 {
84- var invocationContext = new InvocationContext ( null ! ) ;
104+ var args = new [ ]
105+ {
106+ "md-report" ,
107+ "--no-logo" ,
108+ "--input-model" , Path . Combine ( TestContext . CurrentContext . TestDirectory , "Data" , "non-existent.ecore" ) ,
109+ "--output-report" , Path . Combine ( TestContext . CurrentContext . TestDirectory , "md-report.md" )
110+ } ;
85111
86- this . handler . InputModel = new FileInfo ( Path . Combine ( TestContext . CurrentContext . TestDirectory , "Data" , "non-existent.ecore" ) ) ;
87- this . handler . OutputReport = new FileInfo ( Path . Combine ( TestContext . CurrentContext . TestDirectory , "md-report.md" ) ) ;
112+ var parseResult = this . rootCommand . Parse ( args ) ;
88113
89- var result = await this . handler . InvokeAsync ( invocationContext ) ;
114+ var result = await this . handler . InvokeAsync ( parseResult , this . cts . Token ) ;
90115
91116 Assert . That ( result , Is . EqualTo ( - 1 ) , "InvokeAsync should return -1 upon failure." ) ;
92117 }
93118
94119 [ Test ]
95120 public async Task Verify_that_when_the_output_extensions_is_not_supported_returns_not_0 ( )
96121 {
97- var invocationContext = new InvocationContext ( null ! ) ;
122+ var args = new [ ]
123+ {
124+ "md-report" ,
125+ "--no-logo" ,
126+ "--input-model" , Path . Combine ( TestContext . CurrentContext . TestDirectory , "Data" , "recipe.ecore" ) ,
127+ } ;
98128
99129 this . markdownReportGenerator . Setup ( x => x . IsValidReportExtension ( It . IsAny < FileInfo > ( ) ) )
100130 . Returns ( new Tuple < bool , string > ( false , "invalid extension" ) ) ;
101131
102- this . handler . InputModel = new FileInfo ( Path . Combine ( TestContext . CurrentContext . TestDirectory , "Data" , "recipe.ecore" ) ) ;
132+ var parseResult = this . rootCommand . Parse ( args ) ;
103133
104- var result = await this . handler . InvokeAsync ( invocationContext ) ;
134+ var result = await this . handler . InvokeAsync ( parseResult , this . cts . Token ) ;
105135
106136 Assert . That ( result , Is . EqualTo ( - 1 ) , "InvokeAsync should return -1 upon failure." ) ;
107137 }
0 commit comments