Skip to content

Commit

Permalink
Add test to confirm sequential requests have correct headers (no beha…
Browse files Browse the repository at this point in the history
…viour change)
  • Loading branch information
Paul Morris-Hill committed Oct 25, 2023
1 parent f57bc2c commit b693b1c
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions FluentSimTests/FluentSimTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -55,23 +56,30 @@ private static IRestResponse MakeGetRequest(string path, int timeout=50000)
return resp;
}

private static IRestResponse MakePostRequest(string path, object body)
private static IRestResponse MakePostRequest(string path, object body, Dictionary<string, string> headers = null)
{
var verb = Method.POST;
return MakeRequest(path, verb, body);
return MakeRequest(path, verb, body, headers);
}

private static IRestResponse MakeRequest(string path, Method verb, object body = null)
private static IRestResponse MakeRequest(string path, Method verb, object body = null, Dictionary<string, string> headers = null)
{
var resp = MakeRawRequest(path, verb, body);
var resp = MakeRawRequest(path, verb, body, headers);
return resp;
}

private static IRestResponse MakeRawRequest(string path, Method verb, object body = null)
private static IRestResponse MakeRawRequest(string path, Method verb, object body = null, Dictionary<string, string> headers = null)
{
var request = new RestRequest(path, verb);
if (body != null) request.AddParameter("text/json", body, ParameterType.RequestBody);
var client = new RestClient(BaseAddress);
if (headers != null)
{
foreach (var header in headers)
{
request.AddHeader(header.Key, header.Value);
}
}
var resp = client.Execute(request);
return resp;
}
Expand Down Expand Up @@ -349,6 +357,28 @@ private void MakeVerbRequest(RouteConfigurer configurer, Method verb)

[Test]
public void CanGetPreviousRequests()
{
Sim.Post("/post").Responds("OK");
MakePostRequest("/post", "BODY", new Dictionary<string, string>
{
{"Header1", "value1"}
});

MakePostRequest("/post", "BODY", new Dictionary<string, string>
{
{"Header1", "value2"}
});

var requests = Sim.ReceivedRequests;
requests.Count.ShouldBe(2);
var firstRequest = requests[0];
var secondRequest = requests[1];
firstRequest.Headers["Header1"].ShouldBe("value1");
secondRequest.Headers["Header1"].ShouldBe("value2");
}

[Test]
public void CanGetMultipleRequestsWithHeaders()
{
Sim.Post("/post").Responds("OK");
MakePostRequest("/post", "BODY");
Expand Down

0 comments on commit b693b1c

Please sign in to comment.