Skip to content

Commit

Permalink
adding passing tests: ConnectionTests.ThePutMethod can submit PUT req…
Browse files Browse the repository at this point in the history
…uests with no data (i.e. empty body).
  • Loading branch information
davidalpert committed Aug 1, 2015
1 parent ef8a6fe commit c54dfa1
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Octokit.Tests/Http/ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHttpClient>();
IResponse response = new Response();
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
_exampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());

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

Console.WriteLine(expectedBody);

httpClient.Received(1).Send(Arg.Is<IRequest>(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()
{
Expand All @@ -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<IHttpClient>();
IResponse response = new Response();
httpClient.Send(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
_exampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());

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 == expectedBody &&
req.Method == HttpMethod.Put &&
req.Headers["X-GitHub-OTP"] == "two-factor" &&
req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken);
}
}

public class ThePostMethod
Expand Down

0 comments on commit c54dfa1

Please sign in to comment.