private HttpResponseMessage CreateResponse(MockHttpRequest request) { // Extract the last segment of the URI, this is the custom URI // sent by the unit tests. var resourceName = request.RequestUri.Host.Split('.').Last(); var response = MockWebResponse.CreateFromResource(resourceName); if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode <= (HttpStatusCode)299) { return(response); } else { throw new HttpErrorResponseException(CustomWebResponse.GenerateWebResponse(response)); } }
private static Func <MockHttpRequest, HttpWebResponse> Create( string content, string requestId, bool isOK) { var status = isOK ? HttpStatusCode.OK : HttpStatusCode.NotFound; return((request) => { Dictionary <string, string> headers = new Dictionary <string, string>(StringComparer.Ordinal); if (!string.IsNullOrEmpty(requestId)) { headers.Add(HeaderKeys.RequestIdHeader, requestId); } var response = MockWebResponse.Create(status, headers, content); if (isOK) { return response; } throw new HttpErrorResponseException(new HttpWebRequestResponseData(response)); }); }