66
77namespace Semmle . Extraction . Tests
88{
9- internal class DotnetCommandStub : IDotnetCommand
9+ internal class DotNetCliInvokerStub : IDotNetCliInvoker
1010 {
1111 private readonly IList < string > output ;
1212 private string lastArgs = "" ;
1313 public bool Success { get ; set ; } = true ;
1414
15- public DotnetCommandStub ( IList < string > output )
15+ public DotNetCliInvokerStub ( IList < string > output )
1616 {
1717 this . output = output ;
1818 }
@@ -38,8 +38,8 @@ public bool RunCommand(string args, out IList<string> output)
3838 public class DotNetTests
3939 {
4040
41- private static IDotNet MakeDotnet ( IDotnetCommand dotnetCommand ) =>
42- new DotNet ( dotnetCommand , new ProgressMonitor ( new LoggerStub ( ) ) ) ;
41+ private static IDotNet MakeDotnet ( IDotNetCliInvoker dotnetCliInvoker ) =>
42+ new DotNet ( dotnetCliInvoker , new ProgressMonitor ( new LoggerStub ( ) ) ) ;
4343
4444 private static IList < string > MakeDotnetRestoreOutput ( ) =>
4545 new List < string > {
@@ -61,26 +61,26 @@ private static IList<string> MakeDotnetListRuntimesOutput() =>
6161 public void TestDotnetInfo ( )
6262 {
6363 // Setup
64- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) ;
64+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) ;
6565
6666 // Execute
67- var _ = MakeDotnet ( dotnetCommand ) ;
67+ var _ = MakeDotnet ( dotnetCliInvoker ) ;
6868
6969 // Verify
70- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
70+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
7171 Assert . Equal ( "--info" , lastArgs ) ;
7272 }
7373
7474 [ Fact ]
7575 public void TestDotnetInfoFailure ( )
7676 {
7777 // Setup
78- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) { Success = false } ;
78+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) { Success = false } ;
7979
8080 // Execute
8181 try
8282 {
83- var _ = MakeDotnet ( dotnetCommand ) ;
83+ var _ = MakeDotnet ( dotnetCliInvoker ) ;
8484 }
8585
8686 // Verify
@@ -96,44 +96,44 @@ public void TestDotnetInfoFailure()
9696 public void TestDotnetRestoreProjectToDirectory1 ( )
9797 {
9898 // Setup
99- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) ;
100- var dotnet = MakeDotnet ( dotnetCommand ) ;
99+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) ;
100+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
101101
102102 // Execute
103103 dotnet . RestoreProjectToDirectory ( "myproject.csproj" , "mypackages" , out var _ ) ;
104104
105105 // Verify
106- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
106+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
107107 Assert . Equal ( "restore --no-dependencies \" myproject.csproj\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true" , lastArgs ) ;
108108 }
109109
110110 [ Fact ]
111111 public void TestDotnetRestoreProjectToDirectory2 ( )
112112 {
113113 // Setup
114- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) ;
115- var dotnet = MakeDotnet ( dotnetCommand ) ;
114+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) ;
115+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
116116
117117 // Execute
118118 dotnet . RestoreProjectToDirectory ( "myproject.csproj" , "mypackages" , out var _ , "myconfig.config" ) ;
119119
120120 // Verify
121- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
121+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
122122 Assert . Equal ( "restore --no-dependencies \" myproject.csproj\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --configfile \" myconfig.config\" " , lastArgs ) ;
123123 }
124124
125125 [ Fact ]
126126 public void TestDotnetRestoreSolutionToDirectory1 ( )
127127 {
128128 // Setup
129- var dotnetCommand = new DotnetCommandStub ( MakeDotnetRestoreOutput ( ) ) ;
130- var dotnet = MakeDotnet ( dotnetCommand ) ;
129+ var dotnetCliInvoker = new DotNetCliInvokerStub ( MakeDotnetRestoreOutput ( ) ) ;
130+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
131131
132132 // Execute
133133 dotnet . RestoreSolutionToDirectory ( "mysolution.sln" , "mypackages" , out var projects ) ;
134134
135135 // Verify
136- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
136+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
137137 Assert . Equal ( "restore --no-dependencies \" mysolution.sln\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal" , lastArgs ) ;
138138 Assert . Equal ( 2 , projects . Count ( ) ) ;
139139 Assert . Contains ( "/path/to/project.csproj" , projects ) ;
@@ -144,15 +144,15 @@ public void TestDotnetRestoreSolutionToDirectory1()
144144 public void TestDotnetRestoreSolutionToDirectory2 ( )
145145 {
146146 // Setup
147- var dotnetCommand = new DotnetCommandStub ( MakeDotnetRestoreOutput ( ) ) ;
148- var dotnet = MakeDotnet ( dotnetCommand ) ;
149- dotnetCommand . Success = false ;
147+ var dotnetCliInvoker = new DotNetCliInvokerStub ( MakeDotnetRestoreOutput ( ) ) ;
148+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
149+ dotnetCliInvoker . Success = false ;
150150
151151 // Execute
152152 dotnet . RestoreSolutionToDirectory ( "mysolution.sln" , "mypackages" , out var projects ) ;
153153
154154 // Verify
155- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
155+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
156156 Assert . Equal ( "restore --no-dependencies \" mysolution.sln\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal" , lastArgs ) ;
157157 Assert . Empty ( projects ) ;
158158 }
@@ -161,44 +161,44 @@ public void TestDotnetRestoreSolutionToDirectory2()
161161 public void TestDotnetNew ( )
162162 {
163163 // Setup
164- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) ;
165- var dotnet = MakeDotnet ( dotnetCommand ) ;
164+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) ;
165+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
166166
167167 // Execute
168168 dotnet . New ( "myfolder" ) ;
169169
170170 // Verify
171- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
171+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
172172 Assert . Equal ( "new console --no-restore --output \" myfolder\" " , lastArgs ) ;
173173 }
174174
175175 [ Fact ]
176176 public void TestDotnetAddPackage ( )
177177 {
178178 // Setup
179- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) ;
180- var dotnet = MakeDotnet ( dotnetCommand ) ;
179+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) ;
180+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
181181
182182 // Execute
183183 dotnet . AddPackage ( "myfolder" , "mypackage" ) ;
184184
185185 // Verify
186- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
186+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
187187 Assert . Equal ( "add \" myfolder\" package \" mypackage\" --no-restore" , lastArgs ) ;
188188 }
189189
190190 [ Fact ]
191191 public void TestDotnetGetListedRuntimes1 ( )
192192 {
193193 // Setup
194- var dotnetCommand = new DotnetCommandStub ( MakeDotnetListRuntimesOutput ( ) ) ;
195- var dotnet = MakeDotnet ( dotnetCommand ) ;
194+ var dotnetCliInvoker = new DotNetCliInvokerStub ( MakeDotnetListRuntimesOutput ( ) ) ;
195+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
196196
197197 // Execute
198198 var runtimes = dotnet . GetListedRuntimes ( ) ;
199199
200200 // Verify
201- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
201+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
202202 Assert . Equal ( "--list-runtimes" , lastArgs ) ;
203203 Assert . Equal ( 2 , runtimes . Count ) ;
204204 Assert . Contains ( "Microsoft.AspNetCore.App 7.0.2 [/path/dotnet/shared/Microsoft.AspNetCore.App]" , runtimes ) ;
@@ -209,15 +209,15 @@ public void TestDotnetGetListedRuntimes1()
209209 public void TestDotnetGetListedRuntimes2 ( )
210210 {
211211 // Setup
212- var dotnetCommand = new DotnetCommandStub ( MakeDotnetListRuntimesOutput ( ) ) ;
213- var dotnet = MakeDotnet ( dotnetCommand ) ;
214- dotnetCommand . Success = false ;
212+ var dotnetCliInvoker = new DotNetCliInvokerStub ( MakeDotnetListRuntimesOutput ( ) ) ;
213+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
214+ dotnetCliInvoker . Success = false ;
215215
216216 // Execute
217217 var runtimes = dotnet . GetListedRuntimes ( ) ;
218218
219219 // Verify
220- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
220+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
221221 Assert . Equal ( "--list-runtimes" , lastArgs ) ;
222222 Assert . Empty ( runtimes ) ;
223223 }
@@ -226,14 +226,14 @@ public void TestDotnetGetListedRuntimes2()
226226 public void TestDotnetExec ( )
227227 {
228228 // Setup
229- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) ;
230- var dotnet = MakeDotnet ( dotnetCommand ) ;
229+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) ;
230+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
231231
232232 // Execute
233233 dotnet . Exec ( "myarg1 myarg2" ) ;
234234
235235 // Verify
236- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
236+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
237237 Assert . Equal ( "exec myarg1 myarg2" , lastArgs ) ;
238238 }
239239 }
0 commit comments