Skip to content

Commit

Permalink
refactoring ThePutMethod tests to clearly use the same body throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
davidalpert committed Aug 1, 2015
1 parent 3f1bd13 commit ef8a6fe
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Octokit.Tests/Http/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ public class ThePutMethod
[Fact]
public async Task MakesPutRequestWithData()
{
string data = SimpleJson.SerializeObject(new object());
var body = new object();
var expectedBody = SimpleJson.SerializeObject(body);
var httpClient = Substitute.For<IHttpClient>();
IResponse response = new Response();
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
Expand All @@ -357,11 +358,11 @@ public async Task MakesPutRequestWithData()
httpClient,
Substitute.For<IJsonSerializer>());

await connection.Put<string>(new Uri("endpoint", UriKind.Relative), new object());
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), body);

httpClient.Received(1).Send(Arg.Is<IRequest>(req =>
req.BaseAddress == _exampleUri &&
(string)req.Body == data &&
(string)req.Body == expectedBody &&
req.Method == HttpMethod.Put &&
req.ContentType == "application/x-www-form-urlencoded" &&
req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken);
Expand All @@ -370,7 +371,8 @@ public async Task MakesPutRequestWithData()
[Fact]
public async Task MakesPutRequestWithDataAndTwoFactor()
{
string data = SimpleJson.SerializeObject(new object());
var body = new object();
var expectedBody = SimpleJson.SerializeObject(body);
var httpClient = Substitute.For<IHttpClient>();
IResponse response = new Response();
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
Expand All @@ -380,11 +382,11 @@ public async Task MakesPutRequestWithDataAndTwoFactor()
httpClient,
Substitute.For<IJsonSerializer>());

await connection.Put<string>(new Uri("endpoint", UriKind.Relative), new object(), "two-factor");
await connection.Put<string>(new Uri("endpoint", UriKind.Relative), body, "two-factor");

httpClient.Received(1).Send(Arg.Is<IRequest>(req =>
req.BaseAddress == _exampleUri &&
(string)req.Body == data &&
(string)req.Body == expectedBody &&
req.Method == HttpMethod.Put &&
req.Headers["X-GitHub-OTP"] == "two-factor" &&
req.ContentType == "application/x-www-form-urlencoded" &&
Expand Down

0 comments on commit ef8a6fe

Please sign in to comment.