public async Task <NetmockeryTestCaseResult> ExecuteAsync(EndpointCollection endpointCollection, bool handleErrors = true, DateTime?now = null) { Debug.Assert(endpointCollection != null); var testResult = new NetmockeryTestCaseResult { TestCase = this }; try { var endpoint = endpointCollection.Resolve(RequestPath); if (endpoint == null) { return(testResult.SetFailure(ERROR_NOMATCHING_ENDPOINT)); } testResult.EndpointName = endpoint.Name; var matcher_and_creator = endpoint.Resolve(Method, new PathString(RequestPath), new QueryString(QueryString), RequestBody ?? "", null); if (matcher_and_creator == null) { return(testResult.SetFailure(ERROR_ENDPOINT_HAS_NO_MATCH)); } if (!HasExpectations) { return(testResult.SetFailure("Test case has no expectations")); } var responseCreator = matcher_and_creator.ResponseCreator; string responseBody = null; string charset = ""; string contenttype = ""; int statusCode = 0; if (NeedsResponseBody) { var simpleResponseCreator = responseCreator as SimpleResponseCreator; if (simpleResponseCreator == null) { return(testResult.SetFailure($"Response creator {responseCreator.ToString()} not supported by test framework")); } var requestInfo = new RequestInfo { Endpoint = endpoint, Headers = null, RequestPath = RequestPath, QueryString = QueryString, RequestBody = RequestBody }; if (now != null) { requestInfo.SetStaticNow(now.Value); } responseBody = await simpleResponseCreator.GetBodyAndExecuteReplacementsAsync(requestInfo); contenttype = simpleResponseCreator.ContentType ?? ""; charset = simpleResponseCreator.Encoding.WebName; statusCode = simpleResponseCreator.StatusCode; } if (Evaluate(matcher_and_creator.RequestMatcher.ToString(), matcher_and_creator.ResponseCreator.ToString(), responseBody, contenttype, charset, statusCode, out string message)) { return(testResult.SetSuccess()); } else { return(testResult.SetFailure(message)); } } catch (Exception exception) { if (!handleErrors) { throw; } return(testResult.SetException(exception)); } }