use HTTP verbs for clarity: PUT edition

GetOrCreate no more
This commit is contained in:
half-ogre
2013-10-14 12:14:29 -07:00
parent 7e6373ca53
commit a0306ae1df
8 changed files with 20 additions and 30 deletions

View File

@@ -75,7 +75,7 @@ namespace Octokit.Tests.Clients
authEndpoint.Create(new NewAuthorization());
client.Received().Create<Authorization>(Arg.Is<Uri>(u => u.ToString() == "/authorizations")
client.Received().Post<Authorization>(Arg.Is<Uri>(u => u.ToString() == "/authorizations")
, Args.NewAuthorization);
}
}
@@ -105,7 +105,7 @@ namespace Octokit.Tests.Clients
authEndpoint.GetOrCreateApplicationAuthentication("clientId", "secret", data);
client.Received().GetOrCreate<Authorization>(Arg.Is<Uri>(u => u.ToString() == "/authorizations/clients/clientId"),
client.Received().Put<Authorization>(Arg.Is<Uri>(u => u.ToString() == "/authorizations/clients/clientId"),
Args.Object);
}
@@ -114,7 +114,7 @@ namespace Octokit.Tests.Clients
{
var data = new NewAuthorization();
var client = Substitute.For<IApiConnection>();
client.GetOrCreate<Authorization>(Args.Uri, Args.Object, Args.String).Returns(_ => { throw new AuthorizationException(); });
client.Put<Authorization>(Args.Uri, Args.Object, Args.String).Returns(_ => { throw new AuthorizationException(); });
var authEndpoint = new AuthorizationsClient(client);
AssertEx.Throws<TwoFactorChallengeFailedException>(async () =>

View File

@@ -46,7 +46,7 @@ namespace Octokit.Tests.Clients
releasesClient.CreateRelease("fake", "repo", data);
client.Received().Create<Release>(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/releases"), data);
client.Received().Post<Release>(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/releases"), data);
}
[Fact]

View File

@@ -42,7 +42,7 @@ namespace Octokit.Tests.Clients
repositoriesClient.Create(new NewRepository { Name = "aName" });
client.Received().Create<Repository>(Arg.Is<Uri>(u => u.ToString() == "user/repos"), Arg.Any<NewRepository>());
client.Received().Post<Repository>(Arg.Is<Uri>(u => u.ToString() == "user/repos"), Arg.Any<NewRepository>());
}
[Fact]
@@ -54,7 +54,7 @@ namespace Octokit.Tests.Clients
repositoriesClient.Create(newRepository);
client.Received().Create<Repository>(Arg.Any<Uri>(), newRepository);
client.Received().Post<Repository>(Arg.Any<Uri>(), newRepository);
}
}
@@ -78,7 +78,7 @@ namespace Octokit.Tests.Clients
await repositoriesClient.Create("theLogin", new NewRepository { Name = "aName" });
client.Received().Create<Repository>(Arg.Is<Uri>(u => u.ToString() == "orgs/theLogin/repos"), Arg.Any<NewRepository>());
client.Received().Post<Repository>(Arg.Is<Uri>(u => u.ToString() == "orgs/theLogin/repos"), Arg.Any<NewRepository>());
}
[Fact]
@@ -90,7 +90,7 @@ namespace Octokit.Tests.Clients
await repositoriesClient.Create("aLogin", newRepository);
client.Received().Create<Repository>(Arg.Any<Uri>(), newRepository);
client.Received().Post<Repository>(Arg.Any<Uri>(), newRepository);
}
}

View File

@@ -102,7 +102,7 @@ namespace Octokit.Tests.Clients
sshKeysClient.Create(data);
client.Received().Create<SshKey>(endpoint, data);
client.Received().Post<SshKey>(endpoint, data);
}
[Fact]

View File

@@ -133,7 +133,7 @@ namespace Octokit.Tests.Http
connection.PostAsync<object>(Args.Uri, Args.Object).Returns(Task.FromResult(response));
var apiConnection = new ApiConnection(connection);
var data = await apiConnection.Create<object>(postUri, sentData);
var data = await apiConnection.Post<object>(postUri, sentData);
Assert.Same(data, response.BodyAsObject);
connection.Received().PostAsync<object>(postUri, sentData);
@@ -145,8 +145,8 @@ namespace Octokit.Tests.Http
{
var client = new ApiConnection(Substitute.For<IConnection>());
var postUri = new Uri("/", UriKind.Relative);
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create<object>(null, new object()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create<object>(postUri, null));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Post<object>(null, new object()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Post<object>(postUri, null));
}
}

View File

@@ -83,7 +83,7 @@ namespace Octokit
note_url = newAuthorization.NoteUrl
};
return await Client.GetOrCreate<Authorization>(endpoint, requestData);
return await Client.Put<Authorization>(endpoint, requestData);
}
/// <summary>
@@ -126,7 +126,7 @@ namespace Octokit
try
{
return await Client.GetOrCreate<Authorization>(
return await Client.Put<Authorization>(
endpoint,
requestData,
twoFactorAuthenticationCode);

View File

@@ -48,7 +48,7 @@ namespace Octokit
return await _pagination.GetAllPages(async () => await GetPage<T>(endpoint, parameters));
}
public async Task<T> Create<T>(Uri endpoint, object data)
public async Task<T> Post<T>(Uri endpoint, object data)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");
Ensure.ArgumentNotNull(data, "data");
@@ -58,7 +58,7 @@ namespace Octokit
return response.BodyAsObject;
}
public async Task<T> GetOrCreate<T>(Uri endpoint, object data)
public async Task<T> Put<T>(Uri endpoint, object data)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");
Ensure.ArgumentNotNull(data, "data");
@@ -68,7 +68,7 @@ namespace Octokit
return response.BodyAsObject;
}
public async Task<T> GetOrCreate<T>(Uri endpoint, object data, string twoFactorAuthenticationCode)
public async Task<T> Put<T>(Uri endpoint, object data, string twoFactorAuthenticationCode)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");
Ensure.ArgumentNotNull(data, "data");
@@ -89,16 +89,6 @@ namespace Octokit
return response.BodyAsObject;
}
public async Task<T> Put<T>(Uri endpoint, object data)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");
Ensure.ArgumentNotNull(data, "data");
var response = await Connection.PostAsync<T>(endpoint, data);
return response.BodyAsObject;
}
public async Task Delete<T>(Uri endpoint)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");

View File

@@ -16,9 +16,9 @@ namespace Octokit
Task<T> Get<T>(Uri endpoint, IDictionary<string, string> parameters);
Task<string> GetHtml(Uri endpoint, IDictionary<string, string> parameters);
Task<IReadOnlyList<T>> GetAll<T>(Uri endpoint, IDictionary<string, string> parameters);
Task<T> Create<T>(Uri endpoint, object data);
Task<T> GetOrCreate<T>(Uri endpoint, object data);
Task<T> GetOrCreate<T>(Uri endpoint, object data, string twoFactorAuthenticationCode);
Task<T> Post<T>(Uri endpoint, object data);
Task<T> Put<T>(Uri endpoint, object data);
Task<T> Put<T>(Uri endpoint, object data, string twoFactorAuthenticationCode);
Task<T> Update<T>(Uri endpoint, object data);
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification="Legitimate, but I'm not fixing it just yet.")]
Task Delete<T>(Uri endpoint);