From c54dfa196fb2fb42504c66743010c3ca38427617 Mon Sep 17 00:00:00 2001 From: David Alpert Date: Fri, 31 Jul 2015 14:55:52 -0500 Subject: [PATCH] adding passing tests: ConnectionTests.ThePutMethod can submit PUT requests with no data (i.e. empty body). --- Octokit.Tests/Http/ConnectionTests.cs | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Octokit.Tests/Http/ConnectionTests.cs b/Octokit.Tests/Http/ConnectionTests.cs index d969cbef4a..64fae48a84 100644 --- a/Octokit.Tests/Http/ConnectionTests.cs +++ b/Octokit.Tests/Http/ConnectionTests.cs @@ -368,6 +368,31 @@ public async Task MakesPutRequestWithData() req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken); } + [Fact] + public async Task MakesPutRequestWithNoData() + { + var body = ApiConnection.EmptyBody; + var expectedBody = SimpleJson.SerializeObject(body); + var httpClient = Substitute.For(); + IResponse response = new Response(); + httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response)); + var connection = new Connection(new ProductHeaderValue("OctokitTests"), + _exampleUri, + Substitute.For(), + httpClient, + Substitute.For()); + + await connection.Put(new Uri("endpoint", UriKind.Relative), body); + + Console.WriteLine(expectedBody); + + httpClient.Received(1).Send(Arg.Is(req => + req.BaseAddress == _exampleUri && + (string)req.Body == expectedBody && + req.Method == HttpMethod.Put && + req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken); + } + [Fact] public async Task MakesPutRequestWithDataAndTwoFactor() { @@ -392,6 +417,30 @@ public async Task MakesPutRequestWithDataAndTwoFactor() req.ContentType == "application/x-www-form-urlencoded" && req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken); } + + [Fact] + public async Task MakesPutRequestWithNoDataAndTwoFactor() + { + var body = ApiConnection.EmptyBody ; + var expectedBody = SimpleJson.SerializeObject(body); + var httpClient = Substitute.For(); + IResponse response = new Response(); + httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response)); + var connection = new Connection(new ProductHeaderValue("OctokitTests"), + _exampleUri, + Substitute.For(), + httpClient, + Substitute.For()); + + await connection.Put(new Uri("endpoint", UriKind.Relative), body, "two-factor"); + + httpClient.Received(1).Send(Arg.Is(req => + req.BaseAddress == _exampleUri && + (string)req.Body == expectedBody && + req.Method == HttpMethod.Put && + req.Headers["X-GitHub-OTP"] == "two-factor" && + req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken); + } } public class ThePostMethod