6
6
7
7
namespace Semmle . Extraction . Tests
8
8
{
9
- internal class DotnetCommandStub : IDotnetCommand
9
+ internal class DotNetCliInvokerStub : IDotNetCliInvoker
10
10
{
11
11
private readonly IList < string > output ;
12
12
private string lastArgs = "" ;
13
13
public bool Success { get ; set ; } = true ;
14
14
15
- public DotnetCommandStub ( IList < string > output )
15
+ public DotNetCliInvokerStub ( IList < string > output )
16
16
{
17
17
this . output = output ;
18
18
}
@@ -38,8 +38,8 @@ public bool RunCommand(string args, out IList<string> output)
38
38
public class DotNetTests
39
39
{
40
40
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 ( ) ) ) ;
43
43
44
44
private static IList < string > MakeDotnetRestoreOutput ( ) =>
45
45
new List < string > {
@@ -61,26 +61,26 @@ private static IList<string> MakeDotnetListRuntimesOutput() =>
61
61
public void TestDotnetInfo ( )
62
62
{
63
63
// Setup
64
- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) ;
64
+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) ;
65
65
66
66
// Execute
67
- var _ = MakeDotnet ( dotnetCommand ) ;
67
+ var _ = MakeDotnet ( dotnetCliInvoker ) ;
68
68
69
69
// Verify
70
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
70
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
71
71
Assert . Equal ( "--info" , lastArgs ) ;
72
72
}
73
73
74
74
[ Fact ]
75
75
public void TestDotnetInfoFailure ( )
76
76
{
77
77
// Setup
78
- var dotnetCommand = new DotnetCommandStub ( new List < string > ( ) ) { Success = false } ;
78
+ var dotnetCliInvoker = new DotNetCliInvokerStub ( new List < string > ( ) ) { Success = false } ;
79
79
80
80
// Execute
81
81
try
82
82
{
83
- var _ = MakeDotnet ( dotnetCommand ) ;
83
+ var _ = MakeDotnet ( dotnetCliInvoker ) ;
84
84
}
85
85
86
86
// Verify
@@ -96,44 +96,44 @@ public void TestDotnetInfoFailure()
96
96
public void TestDotnetRestoreProjectToDirectory1 ( )
97
97
{
98
98
// 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 ) ;
101
101
102
102
// Execute
103
103
dotnet . RestoreProjectToDirectory ( "myproject.csproj" , "mypackages" , out var _ ) ;
104
104
105
105
// Verify
106
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
106
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
107
107
Assert . Equal ( "restore --no-dependencies \" myproject.csproj\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true" , lastArgs ) ;
108
108
}
109
109
110
110
[ Fact ]
111
111
public void TestDotnetRestoreProjectToDirectory2 ( )
112
112
{
113
113
// 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 ) ;
116
116
117
117
// Execute
118
118
dotnet . RestoreProjectToDirectory ( "myproject.csproj" , "mypackages" , out var _ , "myconfig.config" ) ;
119
119
120
120
// Verify
121
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
121
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
122
122
Assert . Equal ( "restore --no-dependencies \" myproject.csproj\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --configfile \" myconfig.config\" " , lastArgs ) ;
123
123
}
124
124
125
125
[ Fact ]
126
126
public void TestDotnetRestoreSolutionToDirectory1 ( )
127
127
{
128
128
// Setup
129
- var dotnetCommand = new DotnetCommandStub ( MakeDotnetRestoreOutput ( ) ) ;
130
- var dotnet = MakeDotnet ( dotnetCommand ) ;
129
+ var dotnetCliInvoker = new DotNetCliInvokerStub ( MakeDotnetRestoreOutput ( ) ) ;
130
+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
131
131
132
132
// Execute
133
133
dotnet . RestoreSolutionToDirectory ( "mysolution.sln" , "mypackages" , out var projects ) ;
134
134
135
135
// Verify
136
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
136
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
137
137
Assert . Equal ( "restore --no-dependencies \" mysolution.sln\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal" , lastArgs ) ;
138
138
Assert . Equal ( 2 , projects . Count ( ) ) ;
139
139
Assert . Contains ( "/path/to/project.csproj" , projects ) ;
@@ -144,15 +144,15 @@ public void TestDotnetRestoreSolutionToDirectory1()
144
144
public void TestDotnetRestoreSolutionToDirectory2 ( )
145
145
{
146
146
// 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 ;
150
150
151
151
// Execute
152
152
dotnet . RestoreSolutionToDirectory ( "mysolution.sln" , "mypackages" , out var projects ) ;
153
153
154
154
// Verify
155
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
155
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
156
156
Assert . Equal ( "restore --no-dependencies \" mysolution.sln\" --packages \" mypackages\" /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal" , lastArgs ) ;
157
157
Assert . Empty ( projects ) ;
158
158
}
@@ -161,44 +161,44 @@ public void TestDotnetRestoreSolutionToDirectory2()
161
161
public void TestDotnetNew ( )
162
162
{
163
163
// 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 ) ;
166
166
167
167
// Execute
168
168
dotnet . New ( "myfolder" ) ;
169
169
170
170
// Verify
171
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
171
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
172
172
Assert . Equal ( "new console --no-restore --output \" myfolder\" " , lastArgs ) ;
173
173
}
174
174
175
175
[ Fact ]
176
176
public void TestDotnetAddPackage ( )
177
177
{
178
178
// 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 ) ;
181
181
182
182
// Execute
183
183
dotnet . AddPackage ( "myfolder" , "mypackage" ) ;
184
184
185
185
// Verify
186
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
186
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
187
187
Assert . Equal ( "add \" myfolder\" package \" mypackage\" --no-restore" , lastArgs ) ;
188
188
}
189
189
190
190
[ Fact ]
191
191
public void TestDotnetGetListedRuntimes1 ( )
192
192
{
193
193
// Setup
194
- var dotnetCommand = new DotnetCommandStub ( MakeDotnetListRuntimesOutput ( ) ) ;
195
- var dotnet = MakeDotnet ( dotnetCommand ) ;
194
+ var dotnetCliInvoker = new DotNetCliInvokerStub ( MakeDotnetListRuntimesOutput ( ) ) ;
195
+ var dotnet = MakeDotnet ( dotnetCliInvoker ) ;
196
196
197
197
// Execute
198
198
var runtimes = dotnet . GetListedRuntimes ( ) ;
199
199
200
200
// Verify
201
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
201
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
202
202
Assert . Equal ( "--list-runtimes" , lastArgs ) ;
203
203
Assert . Equal ( 2 , runtimes . Count ) ;
204
204
Assert . Contains ( "Microsoft.AspNetCore.App 7.0.2 [/path/dotnet/shared/Microsoft.AspNetCore.App]" , runtimes ) ;
@@ -209,15 +209,15 @@ public void TestDotnetGetListedRuntimes1()
209
209
public void TestDotnetGetListedRuntimes2 ( )
210
210
{
211
211
// 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 ;
215
215
216
216
// Execute
217
217
var runtimes = dotnet . GetListedRuntimes ( ) ;
218
218
219
219
// Verify
220
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
220
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
221
221
Assert . Equal ( "--list-runtimes" , lastArgs ) ;
222
222
Assert . Empty ( runtimes ) ;
223
223
}
@@ -226,14 +226,14 @@ public void TestDotnetGetListedRuntimes2()
226
226
public void TestDotnetExec ( )
227
227
{
228
228
// 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 ) ;
231
231
232
232
// Execute
233
233
dotnet . Exec ( "myarg1 myarg2" ) ;
234
234
235
235
// Verify
236
- var lastArgs = dotnetCommand . GetLastArgs ( ) ;
236
+ var lastArgs = dotnetCliInvoker . GetLastArgs ( ) ;
237
237
Assert . Equal ( "exec myarg1 myarg2" , lastArgs ) ;
238
238
}
239
239
}
0 commit comments