@@ -244,17 +244,21 @@ public void ReadWorkerProviderFromConfig_OverrideDefaultExePath()
244244 [ MemberData ( nameof ( InvalidWorkerDescriptions ) ) ]
245245 public void InvalidWorkerDescription_Throws ( WorkerDescription workerDescription )
246246 {
247- Assert . Throws < ValidationException > ( ( ) => workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) ) ) ;
247+ var testLogger = new TestLogger ( testLanguage ) ;
248+
249+ Assert . Throws < ValidationException > ( ( ) => workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) , testLogger ) ) ;
248250 }
249251
250252 [ Theory ]
251253 [ MemberData ( nameof ( ValidWorkerDescriptions ) ) ]
252254 public void ValidateWorkerDescription_Succeeds ( WorkerDescription workerDescription )
253255 {
256+ var testLogger = new TestLogger ( testLanguage ) ;
257+
254258 try
255259 {
256260 RpcWorkerConfigTestUtilities . CreateTestWorkerFileInCurrentDir ( ) ;
257- workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) ) ;
261+ workerDescription . ApplyDefaultsAndValidate ( Directory . GetCurrentDirectory ( ) , testLogger ) ;
258262 }
259263 finally
260264 {
@@ -267,26 +271,88 @@ public void ValidateWorkerDescription_Succeeds(WorkerDescription workerDescripti
267271 [ InlineData ( "DotNet" ) ]
268272 [ InlineData ( "dotnet.exe" ) ]
269273 [ InlineData ( "DOTNET.EXE" ) ]
270- public void ValidateWorkerDescription_ResolvesDotNetDefaultWorkerExecutablePath ( string defaultExecutablePath )
274+ public void ValidateWorkerDescription_ResolvesDotNetDefaultWorkerExecutablePath_WhenExpectedFileExists (
275+ string defaultExecutablePath )
271276 {
277+ var testLogger = new TestLogger ( testLanguage ) ;
278+
272279 var expectedExecutablePath =
273280 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" )
275282 : defaultExecutablePath ;
276283
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 ) ;
279297 Assert . Equal ( expectedExecutablePath , workerDescription . DefaultExecutablePath ) ;
280298 }
281299
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+
282334 [ Theory ]
283335 [ InlineData ( @"D:\CustomExecutableFolder\dotnet" ) ]
284336 [ InlineData ( @"/CustomExecutableFolder/dotnet" ) ]
285337 [ InlineData ( "AnythingElse" ) ]
286- public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePath_WhenDoesNotStrictlyMatchDotNet ( string defaultExecutablePath )
338+ public void ValidateWorkerDescription_DoesNotModifyDefaultWorkerExecutablePath_WhenDoesNotStrictlyMatchDotNet (
339+ string defaultExecutablePath )
287340 {
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 ) ;
290356 Assert . Equal ( defaultExecutablePath , workerDescription . DefaultExecutablePath ) ;
291357 }
292358
0 commit comments