adding passing tests: ConnectionTests.ThePutMethod can submit PUT requests with no data (i.e. empty body).

This commit is contained in:
David Alpert
2015-07-31 14:55:52 -05:00
parent ef8a6fe2cc
commit c54dfa196f
+49
View File
@@ -368,6 +368,31 @@ namespace Octokit.Tests.Http
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()
{
@@ -392,6 +417,30 @@ namespace Octokit.Tests.Http
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