Skip to content

Commit b91be14

Browse files
committed
Added very first of many redirection cookie tests.
1 parent d3727a0 commit b91be14

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/RestSharp.Tests.Integrated/RedirectTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ public async Task Can_Perform_GET_Async_With_Request_Cookies() {
3838
response.Content.Should().Be("[\"cookie=value\",\"cookie2=value2\"]");
3939
}
4040

41+
[Fact]
42+
public async Task Can_Perform_POST_Async_With_RedirectionResponse_Cookies() {
43+
var request = new RestRequest("/post/set-cookie-redirect") {
44+
Method = Method.Post,
45+
};
46+
47+
var response = await _client.ExecuteAsync(request);
48+
// Verify the cookie exists from the POST:
49+
response.Cookies.Count.Should().BeGreaterThan(0).And.Be(1);
50+
response.Cookies[0].Name.Should().Be("redirectCookie");
51+
response.Cookies[0].Value.Should().Be("value1");
52+
// Make sure the redirected location spits out the correct content:
53+
response.Content.Should().Be("[\"redirectCookie=value1\"]", "was successfully redirected to get-cookies");
54+
}
55+
4156
class Response {
4257
public string? Message { get; set; }
4358
}

test/RestSharp.Tests.Integrated/Server/TestServer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public HttpServer(ITestOutputHelper? output = null) {
5151
}
5252
);
5353

54+
_app.MapPost(
55+
"/post/set-cookie-redirect",
56+
(HttpContext ctx) => {
57+
ctx.Response.Cookies.Append("redirectCookie", "value1");
58+
return Results.Redirect("/get-cookies", permanent: false, preserveMethod: false);
59+
});
60+
5461
// PUT
5562
_app.MapPut(
5663
ContentResource,

0 commit comments

Comments
 (0)