Beispiel #1
0
 private bool IsInteractionMatch(Interaction interaction, HttpRequestMessage request)
 {
     if (interaction.Request.Uri != request.RequestUri.AbsoluteUri) return false;
     if (interaction.Request.Method != request.Method.Method) return false;
     if (interaction.Request.Body != request.Content.AsString()) return false;
     return true;
 }
Beispiel #2
0
 public HttpResponseMessage GetResponseFromInteraction(Interaction interaction)
 {
     var response = new HttpResponseMessage
     {
         Content = new StringContent(interaction.Response.Body),
         StatusCode = interaction.Response.StatusCode
     };
     response.Content.Headers.ContentType = new MediaTypeHeaderValue(interaction.Response.Headers["Content-Type"]);
     return response;
 }
Beispiel #3
0
 public void SaveInteraction(string hostname, Interaction interaction)
 {
     List<Interaction> interactions;
     var filename = GetFileName(hostname);
     if (File.Exists(filename))
     {
         var file = File.ReadAllText(filename);
         interactions = JsonConvert.DeserializeObject<List<Interaction>>(file);
     }
     else
     {
         interactions = new List<Interaction>();
     }
     interactions.Add(interaction);
     var json = JsonConvert.SerializeObject(interactions, Formatting.Indented);
     File.WriteAllText(filename, json);
 }
Beispiel #4
0
 public Interaction GetInteraction(HttpRequestMessage request, HttpResponseMessage response)
 {
     var interaction = new Interaction
     {
         Request = new Request
         {
             Body = request.Content.AsString(),
             Uri = request.RequestUri.AbsoluteUri,
             Method = request.Method.Method
         },
         Response = new Response
         {
             Body = response.Content.AsString(),
             StatusCode = response.StatusCode
         }
     };
     interaction.Response.Headers.Add("Content-Type", response.Content.Headers.ContentType.MediaType);
     return interaction;
 }