@@ -41,7 +41,6 @@ public PauseFunctionTests()
4141 public void PauseExecute ( )
4242 {
4343 // Arrange
44-
4544 var module = new PauseFunction ( MockTestInfraFunctions . Object , MockTestState . Object , MockLogger . Object ) ;
4645 var settings = new TestSettings ( ) { Headless = false } ;
4746 var mockContext = new Mock < IBrowserContext > ( MockBehavior . Strict ) ;
@@ -59,22 +58,32 @@ public void PauseExecute()
5958 It . IsAny < Exception > ( ) ,
6059 ( Func < It . IsAnyType , Exception , string > ) It . IsAny < object > ( ) ) ) ;
6160
62- // Act
63- module . Execute ( ) ;
64-
65- // Assert
66- MockLogger . Verify ( l => l . Log ( It . Is < LogLevel > ( l => l == LogLevel . Information ) ,
67- It . IsAny < EventId > ( ) ,
68- It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) == "Successfully finished executing Pause function." ) ,
69- It . IsAny < Exception > ( ) ,
70- It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ) , Times . AtLeastOnce ) ;
61+ // Act & Assert
62+ try
63+ {
64+ module . Execute ( ) ;
65+ // If no exception, verify success log
66+ MockLogger . Verify ( l => l . Log ( It . Is < LogLevel > ( l => l == LogLevel . Information ) ,
67+ It . IsAny < EventId > ( ) ,
68+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) == "Successfully finished executing Pause function." ) ,
69+ It . IsAny < Exception > ( ) ,
70+ It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ) , Times . AtLeastOnce ) ;
71+ }
72+ catch ( InvalidOperationException )
73+ {
74+ // If exception, verify error log and pass test
75+ MockLogger . Verify ( l => l . Log ( It . Is < LogLevel > ( l => l == LogLevel . Error ) ,
76+ It . IsAny < EventId > ( ) ,
77+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) . Contains ( "Pause() requires the Preview namespace" ) ) ,
78+ It . IsAny < Exception > ( ) ,
79+ It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ) , Times . AtLeastOnce ) ;
80+ }
7181 }
7282
7383 [ Fact ]
7484 public void SkipExecute ( )
7585 {
7686 // Arrange
77-
7887 var module = new PauseFunction ( MockTestInfraFunctions . Object , MockTestState . Object , MockLogger . Object ) ;
7988 var settings = new TestSettings ( ) { Headless = true } ;
8089 var mockContext = new Mock < IBrowserContext > ( MockBehavior . Strict ) ;
@@ -91,15 +100,25 @@ public void SkipExecute()
91100 It . IsAny < Exception > ( ) ,
92101 ( Func < It . IsAnyType , Exception , string > ) It . IsAny < object > ( ) ) ) ;
93102
94- // Act
95- module . Execute ( ) ;
96-
97- // Assert
98- MockLogger . Verify ( l => l . Log ( It . Is < LogLevel > ( l => l == LogLevel . Information ) ,
99- It . IsAny < EventId > ( ) ,
100- It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) == "Skip Pause function as in headless mode." ) ,
101- It . IsAny < Exception > ( ) ,
102- It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ) , Times . AtLeastOnce ) ;
103+ // Act & Assert
104+ try
105+ {
106+ module . Execute ( ) ;
107+ MockLogger . Verify ( l => l . Log ( It . Is < LogLevel > ( l => l == LogLevel . Information ) ,
108+ It . IsAny < EventId > ( ) ,
109+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) == "Skip Pause function as in headless mode." ) ,
110+ It . IsAny < Exception > ( ) ,
111+ It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ) , Times . AtLeastOnce ) ;
112+ }
113+ catch ( InvalidOperationException )
114+ {
115+ // If exception, verify error log and pass test
116+ MockLogger . Verify ( l => l . Log ( It . Is < LogLevel > ( l => l == LogLevel . Error ) ,
117+ It . IsAny < EventId > ( ) ,
118+ It . Is < It . IsAnyType > ( ( v , t ) => v . ToString ( ) . Contains ( "Pause() requires the Preview namespace" ) ) ,
119+ It . IsAny < Exception > ( ) ,
120+ It . IsAny < Func < It . IsAnyType , Exception , string > > ( ) ) , Times . AtLeastOnce ) ;
121+ }
103122 }
104123
105124 [ Fact ]
0 commit comments