1- using System . Diagnostics ;
1+ using System ;
2+ using System . Diagnostics ;
3+ using System . IO ;
4+ using System . Linq ;
25
36using FluentAssertions ;
47
@@ -13,28 +16,24 @@ public class CliTest
1316 [ Test ]
1417 public void CliGenerated ( )
1518 {
16- RunDotnetCommand ( $ "{ pathToSlnDirectory } /TypeScript.ContractGenerator.Cli/bin/{ configuration } /{ targetFramework } /SkbKontur.TypeScript.ContractGenerator.Cli.dll " +
17- $ "-a { pathToSlnDirectory } /AspNetCoreExample.Api/bin/{ configuration } /{ targetFramework } /AspNetCoreExample.Api.dll " +
18- $ "-o { TestContext . CurrentContext . TestDirectory } /cliOutput " +
19- "--nullabilityMode NullableReference " +
20- "--lintMode TsLint" ) ;
21-
22- var expectedDirectory = $ "{ pathToSlnDirectory } /AspNetCoreExample.Generator/output";
23- var actualDirectory = $ "{ TestContext . CurrentContext . TestDirectory } /cliOutput";
24- TestBase . CheckDirectoriesEquivalenceInner ( expectedDirectory , actualDirectory , generatedOnly : true ) ;
19+ var output = Path . Combine ( TestContext . CurrentContext . TestDirectory , "cliOutput" ) ;
20+
21+ RunDotnetCommand ( $ "{ Tool ( ) } -a { Assembly ( ) } -o { output } --nullabilityMode NullableReference --lintMode TsLint") ;
22+
23+ var expectedDirectory = $ "{ repoRoot } /AspNetCoreExample.Generator/output";
24+ TestBase . CheckDirectoriesEquivalenceInner ( expectedDirectory , output , generatedOnly : true ) ;
2525 }
2626
2727 [ Test ]
2828 public void RoslynCliGenerated ( )
2929 {
30- RunDotnetCommand ( $ "{ pathToSlnDirectory } /TypeScript.ContractGenerator.Cli/bin/{ configuration } /{ targetFramework } /SkbKontur.TypeScript.ContractGenerator.Cli.dll " +
31- $ "-d { pathToSlnDirectory } /AspNetCoreExample.Api " +
32- $ "-a { typeof ( ControllerBase ) . Assembly . Location } " +
33- $ "-o { TestContext . CurrentContext . TestDirectory } /roslynCliOutput " +
34- "--nullabilityMode NullableReference " +
35- "--lintMode TsLint" ) ;
36-
37- var expectedDirectory = $ "{ pathToSlnDirectory } /AspNetCoreExample.Generator/output";
30+ var project = Path . Combine ( repoRoot , "AspNetCoreExample.Api" ) ;
31+ var assembly = typeof ( ControllerBase ) . Assembly . Location ;
32+ var output = Path . Combine ( TestContext . CurrentContext . TestDirectory , "roslynCliOutput" ) ;
33+
34+ RunDotnetCommand ( $ "{ Tool ( ) } -d { project } -a { assembly } -o { output } --nullabilityMode NullableReference --lintMode TsLint") ;
35+
36+ var expectedDirectory = $ "{ repoRoot } /AspNetCoreExample.Generator/output";
3837 var actualDirectory = $ "{ TestContext . CurrentContext . TestDirectory } /roslynCliOutput";
3938 TestBase . CheckDirectoriesEquivalenceInner ( expectedDirectory , actualDirectory , generatedOnly : true ) ;
4039 }
@@ -55,12 +54,47 @@ private static void RunDotnetCommand(string command)
5554 process . Start ( ) ;
5655 process . WaitForExit ( ) ;
5756
58- process . ExitCode . Should ( ) . Be ( 0 ) ;
59- process . StandardOutput . ReadToEnd ( ) . Trim ( ) . Should ( ) . Be ( "Generating TypeScript" ) ;
6057 process . StandardError . ReadToEnd ( ) . Trim ( ) . Should ( ) . BeEmpty ( ) ;
58+ process . StandardOutput . ReadToEnd ( ) . Trim ( ) . Should ( ) . Be ( "Generating TypeScript" ) ;
59+ process . ExitCode . Should ( ) . Be ( 0 ) ;
60+ }
61+
62+ private static string Tool ( )
63+ {
64+ return Path . Combine (
65+ repoRoot ,
66+ "TypeScript.ContractGenerator.Cli" ,
67+ "bin" ,
68+ configuration ,
69+ targetFramework ,
70+ "SkbKontur.TypeScript.ContractGenerator.Cli.dll"
71+ ) ;
72+ }
73+
74+ private static string Assembly ( )
75+ {
76+ return Path . Combine (
77+ repoRoot ,
78+ "AspNetCoreExample.Api" ,
79+ "bin" ,
80+ configuration ,
81+ targetFramework ,
82+ "AspNetCoreExample.Api.dll"
83+ ) ;
84+ }
85+
86+ private static string RootDirectory ( DirectoryInfo ? current = null )
87+ {
88+ current ??= new DirectoryInfo ( TestContext . CurrentContext . TestDirectory ) ;
89+ while ( current != null && current . EnumerateFiles ( ) . All ( x => x . Name != "TypeScript.ContractGenerator.sln" ) )
90+ {
91+ current = current . Parent ;
92+ }
93+
94+ return current ? . FullName ?? throw new InvalidOperationException ( "Cannot find root folder" ) ;
6195 }
6296
63- private static readonly string pathToSlnDirectory = $ " { TestContext . CurrentContext . TestDirectory } /../../../../" ;
97+ private static readonly string repoRoot = RootDirectory ( ) ;
6498
6599 private const string targetFramework = "net8.0" ;
66100
0 commit comments