@@ -176,7 +176,7 @@ async public Task<NetmockeryTestCaseResult> ExecuteAgainstUrlAsync(string url)
176176 private const string ERROR_ENDPOINT_HAS_NO_MATCH = "Endpoint has no match for request" ;
177177
178178
179- async public Task < NetmockeryTestCaseResult > ExecuteAsync ( EndpointCollection endpointCollection , bool handleErrors = true )
179+ async public Task < NetmockeryTestCaseResult > ExecuteAsync ( EndpointCollection endpointCollection , bool handleErrors = true , DateTime ? now = null )
180180 {
181181 Debug . Assert ( endpointCollection != null ) ;
182182
@@ -204,14 +204,25 @@ async public Task<NetmockeryTestCaseResult> ExecuteAsync(EndpointCollection endp
204204 string responseBody = null ;
205205 if ( NeedsResponseBody )
206206 {
207- var httpResponse = new TestCaseHttpResponse ( ) ;
208- var responseBodyBytes = await responseCreator . CreateResponseAsync (
209- new TestCaseHttpRequest ( RequestPath , QueryString ) ,
210- Encoding . UTF8 . GetBytes ( RequestBody ?? "" ) ,
211- httpResponse ,
212- endpoint . Directory
213- ) ;
214- responseBody = httpResponse . GetWrittenResponseAsString ( ) ;
207+ var simpleResponseCreator = responseCreator as SimpleResponseCreator ;
208+ if ( simpleResponseCreator == null )
209+ {
210+ return testResult . SetFailure ( $ "Response creator { responseCreator . ToString ( ) } not supported by test framework") ;
211+ }
212+
213+ var requestInfo = new RequestInfo
214+ {
215+ EndpointDirectory = endpoint . Directory ,
216+ Headers = null ,
217+ RequestPath = RequestPath ,
218+ QueryString = QueryString ,
219+ RequestBody = RequestBody
220+ } ;
221+ if ( now != null )
222+ {
223+ requestInfo . SetStaticNow ( now . Value ) ;
224+ }
225+ responseBody = simpleResponseCreator . GetBodyAndExecuteReplacements ( requestInfo ) ;
215226 }
216227 string message ;
217228 if ( Evaluate ( matcher_and_creator . RequestMatcher . ToString ( ) , matcher_and_creator . ResponseCreator . ToString ( ) , responseBody , out message ) )
@@ -240,9 +251,21 @@ async public Task<Tuple<string, string>> GetResponseAsync(EndpointCollection end
240251 var matcher_and_creator = endpoint . Resolve ( new PathString ( RequestPath ) , new QueryString ( QueryString ) , RequestBody , null ) ;
241252 if ( matcher_and_creator != null )
242253 {
243- var responseCreator = matcher_and_creator . ResponseCreator ;
244- var responseBodyBytes = await responseCreator . CreateResponseAsync ( new TestCaseHttpRequest ( RequestPath , QueryString ) , Encoding . UTF8 . GetBytes ( RequestBody ?? "" ) , new TestCaseHttpResponse ( ) , endpoint . Directory ) ;
245- return Tuple . Create ( Encoding . UTF8 . GetString ( responseBodyBytes ) , ( string ) null ) ;
254+ var responseCreator = matcher_and_creator . ResponseCreator as SimpleResponseCreator ;
255+ if ( responseCreator == null )
256+ {
257+ return Tuple . Create ( ( string ) null , $ "This response creator is not supported by test framework: { matcher_and_creator . ResponseCreator . ToString ( ) } ") ;
258+ }
259+
260+ var responseBody = responseCreator . GetBodyAndExecuteReplacements ( new RequestInfo
261+ {
262+ EndpointDirectory = endpoint . Directory ,
263+ Headers = null ,
264+ QueryString = QueryString ,
265+ RequestBody = RequestBody ,
266+ RequestPath = RequestPath
267+ } ) ;
268+ return Tuple . Create ( responseBody , ( string ) null ) ;
246269 }
247270 else
248271 {
0 commit comments