public async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { HttpResponseMessage response = null; IHttpMessageHandler handler = null; // First check for a perfect match, or if there's a key that's a base url of the request // url, match it if client code chooses to accept that. if (_urlsToHandlers.TryGetValue(request.RequestUri, out handler) || (MatchBaseUrls && null != (handler = _urlsToHandlers.FirstOrDefault( entry => entry.Key.IsBaseOf(request.RequestUri)).Value))) { response = await handler.SendAsync(request, cancellationToken).ConfigureAwait(false); } else if (DeferToDefault) { response = await DefaultAsync(request, cancellationToken).ConfigureAwait(false); } else { Console.WriteLine(string.Format("WARNING: No validator found for absolute URI: {0}", request.RequestUri.AbsoluteUri)); // No handler found, so return 404 response = await HttpTests.CreateJsonStringResponseAsync( HttpStatusCode.NotFound, "Resource not found.", "ResourceNotFoundError") .ConfigureAwait(false); } return(response); }