Skip to content

Commit

Permalink
Added the test to use query parameters with PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Sep 18, 2018
1 parent cdf59c4 commit 02e51bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
25 changes: 24 additions & 1 deletion RestSharp.IntegrationTests/RequestBodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,26 @@ public void MultipartFormData_Without_File_Creates_A_Valid_RequestBody()
}
}

[Test]
public void Query_Parameters_With_Json_Body()
{
const Method httpMethod = Method.PUT;

using (SimpleServer.Create(BASE_URL, Handlers.Generic<RequestBodyCapturer>()))
{
var client = new RestClient(BASE_URL);
var request = new RestRequest(RequestBodyCapturer.RESOURCE, httpMethod)
.AddJsonBody(new {displayName = "Display Name"})
.AddQueryParameter("key", "value");

client.Execute(request);

Assert.Equals(RequestBodyCapturer.CapturedUrl, "http://localhost:8888/Capture?key=value");
Assert.Equals(RequestBodyCapturer.CapturedContentType, "application/json");
Assert.Equals(RequestBodyCapturer.CapturedEntityBody, "{\"displayName\":\"Display Name\"}");
}
}

private static void AssertHasNoRequestBody()
{
Assert.Null(RequestBodyCapturer.CapturedContentType);
Expand All @@ -260,15 +280,18 @@ private class RequestBodyCapturer

public static string CapturedEntityBody { get; set; }

public static Uri CapturedUrl { get; set; }

public static void Capture(HttpListenerContext context)
{
HttpListenerRequest request = context.Request;

CapturedContentType = request.ContentType;
CapturedHasEntityBody = request.HasEntityBody;
CapturedEntityBody = StreamToString(request.InputStream);
CapturedUrl = request.Url;
}

private static string StreamToString(Stream stream)
{
StreamReader streamReader = new StreamReader(stream);
Expand Down
2 changes: 1 addition & 1 deletion RestSharp.Tests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void Can_Add_Object_With_IntegerArray_property()
{
RestRequest request = new RestRequest();

request.AddObject(new { Items = new [] { 2, 3, 4 } });
Assert.DoesNotThrow(() => request.AddObject(new { Items = new [] { 2, 3, 4 } }));
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dotnet restore
msbuild /t:build /p:Configuration=Release
msbuild /t:build /p:Configuration=Release /p:DefineConstants=APPVEYOR
dotnet test --no-build
msbuild /t:Pack /p:Version=106.0.0 /p:DefineConstants=APPVEYOR
msbuild /t:Pack /p:Version=106.0.0

0 comments on commit 02e51bc

Please sign in to comment.