@@ -244,17 +244,21 @@ public void ReadWorkerProviderFromConfig_OverrideDefaultExePath()
244
244
[ MemberData ( nameof ( InvalidWorkerDescriptions ) ) ]
245
245
public void InvalidWorkerDescription_Throws ( WorkerDescription workerDescription )
246
246
{
247
- Assert . Throws < ValidationException > ( ( ) => workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) ) ) ;
247
+ var testLogger = new TestLogger ( testLanguage ) ;
248
+
249
+ Assert . Throws < ValidationException > ( ( ) => workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) , testLogger ) ) ;
248
250
}
249
251
250
252
[ Theory ]
251
253
[ MemberData ( nameof ( ValidWorkerDescriptions ) ) ]
252
254
public void ValidateWorkerDescription_Succeeds ( WorkerDescription workerDescription )
253
255
{
256
+ var testLogger = new TestLogger ( testLanguage ) ;
257
+
254
258
try
255
259
{
256
260
RpcWorkerConfigTestUtilities . CreateTestWorkerFileInCurrentDir ( ) ;
257
- workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) ) ;
261
+ workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) , testLogger ) ;
258
262
}
259
263
finally
260
264
{
@@ -267,26 +271,88 @@ public void ValidateWorkerDescription_Succeeds(WorkerDescription workerDescripti
267
271
[ InlineData ( "DotNet" ) ]
268
272
[ InlineData ( "dotnet.exe" ) ]
269
273
[ InlineData ( "DOTNET.EXE" ) ]
270
- public void ValidateWorkerDescription_ResolvesDotNetDefaultWorkerExecutablePath ( string defaultExecutablePath )
274
+ public void ValidateWorkerDescription_ResolvesDotNetDefaultWorkerExecutablePath_WhenExpectedFileExists (
275
+ string defaultExecutablePath )
271
276
{
277
+ var testLogger = new TestLogger ( testLanguage ) ;
278
+
272
279
var expectedExecutablePath =
273
280
RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
274
- ? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) , "dotnet" , defaultExecutablePath )
281
+ ? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) , "dotnet" , "dotnet.exe" )
275
282
: defaultExecutablePath ;
276
283
277
- var workerDescription = new RpcWorkerDescription { Language = testLanguage , Extensions = new List < string > ( ) , DefaultExecutablePath = defaultExecutablePath } ;
278
- workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) ) ;
284
+ var workerDescription = new RpcWorkerDescription
285
+ {
286
+ Language = testLanguage ,
287
+ Extensions = new List < string > ( ) ,
288
+ DefaultExecutablePath = defaultExecutablePath ,
289
+ FileExists = path =>
290
+ {
291
+ Assert . Equal ( expectedExecutablePath , path ) ;
292
+ return true ;
293
+ }
294
+ } ;
295
+
296
+ workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) , testLogger ) ;
279
297
Assert . Equal ( expectedExecutablePath , workerDescription . DefaultExecutablePath ) ;
280
298
}
281
299
300
+ [ Theory ]
301
+ [ InlineData ( "dotnet" ) ]
302
+ [ InlineData ( "DotNet" ) ]
303
+ [ InlineData ( "dotnet.exe" ) ]
304
+ [ InlineData ( "DOTNET.EXE" ) ]
305
+ public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePathAndWarns_WhenExpectedFileDoesNotExist (
306
+ string defaultExecutablePath )
307
+ {
308
+ var testLogger = new TestLogger ( testLanguage ) ;
309
+
310
+ var expectedExecutablePath =
311
+ RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
312
+ ? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFiles ) , "dotnet" , "dotnet.exe" )
313
+ : defaultExecutablePath ;
314
+
315
+ var workerDescription = new RpcWorkerDescription
316
+ {
317
+ Language = testLanguage ,
318
+ Extensions = new List < string > ( ) ,
319
+ DefaultExecutablePath = defaultExecutablePath ,
320
+ FileExists = path =>
321
+ {
322
+ Assert . Equal ( expectedExecutablePath , path ) ;
323
+ return false ;
324
+ }
325
+ } ;
326
+
327
+ workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) , testLogger ) ;
328
+ Assert . Equal ( defaultExecutablePath , workerDescription . DefaultExecutablePath ) ;
329
+ Assert . True ( testLogger . GetLogMessages ( ) . Any ( message => message . Level == LogLevel . Warning
330
+ && message . FormattedMessage . Contains ( defaultExecutablePath )
331
+ && message . FormattedMessage . Contains ( expectedExecutablePath ) ) ) ;
332
+ }
333
+
282
334
[ Theory ]
283
335
[ InlineData ( @"D:\CustomExecutableFolder\dotnet" ) ]
284
336
[ InlineData ( @"/CustomExecutableFolder/dotnet" ) ]
285
337
[ InlineData ( "AnythingElse" ) ]
286
- public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePath_WhenDoesNotStrictlyMatchDotNet ( string defaultExecutablePath )
338
+ public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePath_WhenDoesNotStrictlyMatchDotNet (
339
+ string defaultExecutablePath )
287
340
{
288
- var workerDescription = new RpcWorkerDescription { Language = testLanguage , Extensions = new List < string > ( ) , DefaultExecutablePath = defaultExecutablePath } ;
289
- workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) ) ;
341
+ var testLogger = new TestLogger ( testLanguage ) ;
342
+
343
+ var workerDescription = new RpcWorkerDescription
344
+ {
345
+ Language = testLanguage ,
346
+ Extensions = new List < string > ( ) ,
347
+ DefaultExecutablePath = defaultExecutablePath ,
348
+ FileExists = path =>
349
+ {
350
+ Assert . True ( false , "FileExists should not be called" ) ;
351
+ return false ;
352
+ }
353
+ } ;
354
+
355
+ workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) , testLogger ) ;
290
356
Assert . Equal ( defaultExecutablePath , workerDescription . DefaultExecutablePath ) ;
291
357
}
292
358
0 commit comments