Skip to content

Commit 28dc44e

Browse files
committed
Added very first of many redirection cookie tests.
1 parent 9298136 commit 28dc44e

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
@@ -53,6 +53,21 @@ public async Task Can_Perform_GET_Async_With_Request_Cookies() {
5353
response.Content.Should().Be("[\"cookie=value\",\"cookie2=value2\"]");
5454
}
5555

56+
[Fact]
57+
public async Task Can_Perform_POST_Async_With_RedirectionResponse_Cookies() {
58+
var request = new RestRequest("/post/set-cookie-redirect") {
59+
Method = Method.Post,
60+
};
61+
62+
var response = await _client.ExecuteAsync(request);
63+
// Verify the cookie exists from the POST:
64+
response.Cookies.Count.Should().BeGreaterThan(0).And.Be(1);
65+
response.Cookies[0].Name.Should().Be("redirectCookie");
66+
response.Cookies[0].Value.Should().Be("value1");
67+
// Make sure the redirected location spits out the correct content:
68+
response.Content.Should().Be("[\"redirectCookie=value1\"]", "was successfully redirected to get-cookies");
69+
}
70+
5671
class Response {
5772
public string? Message { get; set; }
5873
}

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

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

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

0 commit comments

Comments
 (0)