Fix bug with Put setting invalid content type

Turns out we were calling the wrong overload.
This commit is contained in:
Haacked
2013-10-15 10:18:17 -07:00
parent f49939ab10
commit 2168d92e8f
3 changed files with 46 additions and 2 deletions
@@ -109,6 +109,21 @@ namespace Octokit.Tests.Clients
Args.Object);
}
[Fact]
public void GetsOrCreatesAuthenticationAtCorrectUrlUsingTwoFactor()
{
var data = new NewAuthorization();
var client = Substitute.For<IApiConnection>();
var authEndpoint = new AuthorizationsClient(client);
authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data, "two-factor");
client.Received().Put<Authorization>(
Arg.Is<Uri>(u => u.ToString() == "/authorizations/clients/clientId"),
Args.Object,
"two-factor");
}
[Fact]
public async Task WrapsTwoFactorFailureWithTwoFactorException()
{
+27 -1
View File
@@ -236,6 +236,7 @@ namespace Octokit.Tests.Http
req.BaseAddress == ExampleUri &&
(string)req.Body == data &&
req.Method == HttpVerb.Patch &&
req.ContentType == "application/x-www-form-urlencoded" &&
req.Endpoint == new Uri("/endpoint", UriKind.Relative)));
}
}
@@ -243,7 +244,7 @@ namespace Octokit.Tests.Http
public class ThePutAsyncMethod
{
[Fact]
public async Task RunsConfiguredAppWithAppropriateEnv()
public async Task MakesPutRequestWithData()
{
string data = SimpleJson.SerializeObject(new object());
var httpClient = Substitute.For<IHttpClient>();
@@ -261,6 +262,31 @@ namespace Octokit.Tests.Http
req.BaseAddress == ExampleUri &&
(string)req.Body == data &&
req.Method == HttpMethod.Put &&
req.ContentType == "application/x-www-form-urlencoded" &&
req.Endpoint == new Uri("/endpoint", UriKind.Relative)));
}
[Fact]
public async Task MakesPutRequestWithDataAndTwoFactor()
{
string data = SimpleJson.SerializeObject(new object());
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>();
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection("Test Runner",
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
await connection.PutAsync<string>(new Uri("/endpoint", UriKind.Relative), new object(), "two-factor");
httpClient.Received(1).Send<string>(Arg.Is<IRequest>(req =>
req.BaseAddress == ExampleUri &&
(string)req.Body == data &&
req.Method == HttpMethod.Put &&
req.Headers["X-GitHub-OTP"] == "two-factor" &&
req.ContentType == "application/x-www-form-urlencoded" &&
req.Endpoint == new Uri("/endpoint", UriKind.Relative)));
}
}
+4 -1
View File
@@ -123,7 +123,10 @@ namespace Octokit
public async Task<IResponse<T>> PutAsync<T>(Uri endpoint, object body, string twoFactorAuthenticationCode)
{
return await SendData<T>(endpoint, HttpMethod.Put, body, twoFactorAuthenticationCode);
return await SendData<T>(endpoint,
HttpMethod.Put,
body,
twoFactorAuthenticationCode: twoFactorAuthenticationCode);
}
async Task<IResponse<T>> SendData<T>(