1515
1616namespace Microsoft . Azure . Functions . PowerShellWorker . Test
1717{
18+ using System . Collections . ObjectModel ;
1819 using System . Management . Automation ;
1920
2021 internal class TestUtils
@@ -285,8 +286,23 @@ public void ProfileShouldWork()
285286 s_testLogger . FullLog . Clear ( ) ;
286287 testManager . InvokeProfile ( profilePath ) ;
287288
288- Assert . Single ( s_testLogger . FullLog ) ;
289- Assert . Equal ( "Information: INFORMATION: Hello PROFILE" , s_testLogger . FullLog [ 0 ] ) ;
289+ var relevantLogs = s_testLogger . FullLog . Where ( message => ! message . StartsWith ( "Trace:" ) ) . ToList ( ) ;
290+ Assert . Single ( relevantLogs ) ;
291+ Assert . Equal ( "Information: INFORMATION: Hello PROFILE" , relevantLogs [ 0 ] ) ;
292+ }
293+
294+ [ Fact ]
295+ public void ProfileExecutionTimeShouldBeLogged ( )
296+ {
297+ var profilePath = Path . Join ( s_funcDirectory , "ProfileBasic" , "profile.ps1" ) ;
298+ var testManager = NewTestPowerShellManager ( s_testLogger ) ;
299+
300+ s_testLogger . FullLog . Clear ( ) ;
301+ testManager . InvokeProfile ( profilePath ) ;
302+
303+ Assert . Equal ( 1 , s_testLogger . FullLog . Count (
304+ message => message . StartsWith ( "Trace" )
305+ && message . Contains ( "Profile invocation completed in" ) ) ) ;
290306 }
291307
292308 [ Fact ]
@@ -299,8 +315,9 @@ public void ProfileWithTerminatingError()
299315 s_testLogger . FullLog . Clear ( ) ;
300316
301317 Assert . Throws < CmdletInvocationException > ( ( ) => testManager . InvokeProfile ( profilePath ) ) ;
302- Assert . Single ( s_testLogger . FullLog ) ;
303- Assert . Matches ( "Error: Failed to run profile.ps1. See logs for detailed errors. Profile location: " , s_testLogger . FullLog [ 0 ] ) ;
318+ var relevantLogs = s_testLogger . FullLog . Where ( message => ! message . StartsWith ( "Trace:" ) ) . ToList ( ) ;
319+ Assert . Single ( relevantLogs ) ;
320+ Assert . Matches ( "Error: Failed to run profile.ps1. See logs for detailed errors. Profile location: " , relevantLogs [ 0 ] ) ;
304321 }
305322
306323 [ Fact ]
@@ -313,10 +330,11 @@ public void ProfileWithNonTerminatingError()
313330 s_testLogger . FullLog . Clear ( ) ;
314331 testManager . InvokeProfile ( profilePath ) ;
315332
316- Assert . Equal ( 2 , s_testLogger . FullLog . Count ) ;
317- Assert . StartsWith ( "Error: ERROR: " , s_testLogger . FullLog [ 0 ] ) ;
318- Assert . Contains ( "help me!" , s_testLogger . FullLog [ 0 ] ) ;
319- Assert . Matches ( "Error: Failed to run profile.ps1. See logs for detailed errors. Profile location: " , s_testLogger . FullLog [ 1 ] ) ;
333+ var relevantLogs = s_testLogger . FullLog . Where ( message => ! message . StartsWith ( "Trace:" ) ) . ToList ( ) ;
334+ Assert . Equal ( 2 , relevantLogs . Count ) ;
335+ Assert . StartsWith ( "Error: ERROR: " , relevantLogs [ 0 ] ) ;
336+ Assert . Contains ( "help me!" , relevantLogs [ 0 ] ) ;
337+ Assert . Matches ( "Error: Failed to run profile.ps1. See logs for detailed errors. Profile location: " , relevantLogs [ 1 ] ) ;
320338 }
321339
322340 [ Fact ]
0 commit comments