/// <exception cref="System.IO.IOException"></exception> public virtual HttpResponse Execute(HttpRequestMessage httpUriRequest) { capturedRequests.AddItem(httpUriRequest); foreach (string urlPattern in responders.Keys) { if (urlPattern.Equals("*") || httpUriRequest.GetURI().GetPath().Contains(urlPattern )) { CustomizableMockHttpClient.Responder responder = responders.Get(urlPattern); return(responder.Execute(httpUriRequest)); } } throw new RuntimeException("No responders matched for url pattern: " + httpUriRequest .GetURI().GetPath()); }
public HttpClient GetHttpClient() { CustomizableMockHttpClient mockHttpClient = new CustomizableMockHttpClient(); CustomizableMockHttpClient.Responder sentinal = this.DefaultChangesResponder(); Queue <CustomizableMockHttpClient.Responder> responders = new List <CustomizableMockHttpClient.Responder >(); responders.AddItem(this.DefaultChangesResponder()); responders.AddItem(CustomizableMockHttpClient.TransientErrorResponder(errorCode, statusMessage)); ResponderChain responderChain = new ResponderChain(responders, sentinal); mockHttpClient.SetResponder("_changes", responderChain); return(mockHttpClient); }
/// <exception cref="System.IO.IOException"></exception> public virtual HttpResponse Execute(HttpRequestMessage httpUriRequest) { DelayResponseIfNeeded(); Log.D(Database.Tag, "execute() called with request: " + httpUriRequest.GetURI().GetPath ()); capturedRequests.AddItem(httpUriRequest); foreach (string urlPattern in responders.Keys) { if (urlPattern.Equals("*") || httpUriRequest.GetURI().GetPath().Contains(urlPattern )) { CustomizableMockHttpClient.Responder responder = responders.Get(urlPattern); HttpResponse response = responder.Execute(httpUriRequest); NotifyResponseListeners(httpUriRequest, response); return(response); } } throw new RuntimeException("No responders matched for url pattern: " + httpUriRequest .GetURI().GetPath()); }
/// <exception cref="System.IO.IOException"></exception> public virtual HttpResponse Execute(HttpRequestMessage httpUriRequest) { CustomizableMockHttpClient.Responder responder; CustomizableMockHttpClient.Responder nextResponder = responders.Peek(); if (nextResponder != null) { responder = responders.Remove(); } else { if (sentinal != null) { responder = sentinal; } else { throw new RuntimeException("No more responders in queue"); } } return(responder.Execute(httpUriRequest)); }
public virtual void SetResponder(string urlPattern, CustomizableMockHttpClient.Responder responder) { responders.Put(urlPattern, responder); }
/// <summary>Create a responder chain with a "sentinal".</summary> /// <remarks> /// Create a responder chain with a "sentinal". /// If and when the responders passed into responders are consumed, then the sentinal /// will handle all remaining requests to the responder chain. /// This is the version you want to use if you don't know ahead of time how many /// requests this responderchain will need to handle. /// </remarks> /// <param name="responders"> /// a list of responders, which will be "consumed" as soon /// as they respond to a request. /// </param> /// <param name="sentinal"> /// the final responder in the chain, which is "sticky" and won't /// be removed after handling a request. /// </param> public ResponderChain(Queue<CustomizableMockHttpClient.Responder> responders, CustomizableMockHttpClient.Responder sentinal) { this.responders = responders; this.sentinal = sentinal; }
/// <summary>Create a responder chain with a "sentinal".</summary> /// <remarks> /// Create a responder chain with a "sentinal". /// If and when the responders passed into responders are consumed, then the sentinal /// will handle all remaining requests to the responder chain. /// This is the version you want to use if you don't know ahead of time how many /// requests this responderchain will need to handle. /// </remarks> /// <param name="responders"> /// a list of responders, which will be "consumed" as soon /// as they respond to a request. /// </param> /// <param name="sentinal"> /// the final responder in the chain, which is "sticky" and won't /// be removed after handling a request. /// </param> public ResponderChain(Queue <CustomizableMockHttpClient.Responder> responders, CustomizableMockHttpClient.Responder sentinal) { this.responders = responders; this.sentinal = sentinal; }