mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 19:46:07 +00:00
Fix up ApiExtensions
This commit is contained in:
@@ -27,7 +27,7 @@ namespace Octokit.Tests.Http
|
||||
var data = await apiConnection.Get<object>(getUri);
|
||||
|
||||
Assert.Same(response.BodyAsObject, data);
|
||||
connection.Received().GetAsync<object>(getUri);
|
||||
connection.Received().GetResponse<object>(getUri);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -314,12 +314,12 @@ namespace Octokit.Tests.Http
|
||||
const HttpStatusCode statusCode = HttpStatusCode.OK;
|
||||
IResponse<object> response = new ApiResponse<object> { BodyAsObject = new object(), StatusCode = statusCode };
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetAsync<object>(queuedOperationUrl,Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
connection.GetResponse<object>(queuedOperationUrl,Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
|
||||
await apiConnection.GetQueuedOperation<object>(queuedOperationUrl,CancellationToken.None);
|
||||
|
||||
connection.Received().GetAsync<object>(queuedOperationUrl, Args.CancellationToken);
|
||||
connection.Received().GetResponse<object>(queuedOperationUrl, Args.CancellationToken);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -330,7 +330,7 @@ namespace Octokit.Tests.Http
|
||||
const HttpStatusCode statusCode = HttpStatusCode.PartialContent;
|
||||
IResponse<object> response = new ApiResponse<object> { BodyAsObject = new object(), StatusCode = statusCode };
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetAsync<object>(queuedOperationUrl, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
|
||||
await AssertEx.Throws<ApiException>(async () => await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, Args.CancellationToken));
|
||||
@@ -345,7 +345,7 @@ namespace Octokit.Tests.Http
|
||||
const HttpStatusCode statusCode = HttpStatusCode.OK;
|
||||
IResponse<object> response = new ApiResponse<object> { BodyAsObject = result, StatusCode = statusCode };
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetAsync<object>(queuedOperationUrl, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken).Returns(Task.FromResult(response));
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
|
||||
var actualResult = await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, Args.CancellationToken);
|
||||
@@ -361,7 +361,7 @@ namespace Octokit.Tests.Http
|
||||
IResponse<object> firstResponse = new ApiResponse<object> { BodyAsObject = result, StatusCode = HttpStatusCode.Accepted };
|
||||
IResponse<object> completedResponse = new ApiResponse<object> { BodyAsObject = result, StatusCode = HttpStatusCode.OK };
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetAsync<object>(queuedOperationUrl, Args.CancellationToken)
|
||||
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken)
|
||||
.Returns(x => Task.FromResult(firstResponse),
|
||||
x => Task.FromResult(firstResponse),
|
||||
x => Task.FromResult(completedResponse));
|
||||
@@ -370,7 +370,7 @@ namespace Octokit.Tests.Http
|
||||
|
||||
await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, CancellationToken.None);
|
||||
|
||||
connection.Received(3).GetAsync<object>(queuedOperationUrl, Args.CancellationToken);
|
||||
connection.Received(3).GetResponse<object>(queuedOperationUrl, Args.CancellationToken);
|
||||
}
|
||||
|
||||
public async Task CanCancelQueuedOperation()
|
||||
@@ -380,7 +380,7 @@ namespace Octokit.Tests.Http
|
||||
var result = new object();
|
||||
IResponse<object> accepted = new ApiResponse<object> { BodyAsObject = result, StatusCode = HttpStatusCode.Accepted };
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetAsync<object>(queuedOperationUrl, Args.CancellationToken).Returns(x => Task.FromResult(accepted));
|
||||
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken).Returns(x => Task.FromResult(accepted));
|
||||
|
||||
var apiConnection = new ApiConnection(connection);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Octokit.Tests.Http
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative));
|
||||
await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative));
|
||||
|
||||
httpClient.Received(1).Send<string>(Arg.Is<IRequest>(req =>
|
||||
req.BaseAddress == ExampleUri &&
|
||||
@@ -54,9 +54,9 @@ namespace Octokit.Tests.Http
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative));
|
||||
await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative));
|
||||
await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative));
|
||||
await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative));
|
||||
await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative));
|
||||
await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative));
|
||||
|
||||
httpClient.Received(3).Send<string>(Arg.Is<IRequest>(req =>
|
||||
req.BaseAddress == ExampleUri &&
|
||||
@@ -83,7 +83,7 @@ namespace Octokit.Tests.Http
|
||||
httpClient,
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var resp = await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative));
|
||||
var resp = await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative));
|
||||
Assert.NotNull(resp.ApiInfo);
|
||||
Assert.Equal("user", resp.ApiInfo.AcceptedOauthScopes.First());
|
||||
}
|
||||
@@ -101,7 +101,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<AuthorizationException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
Assert.NotNull(exception);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<AuthorizationException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, exception.StatusCode);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<TwoFactorRequiredException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal(expectedFactorType, exception.TwoFactorType);
|
||||
}
|
||||
@@ -178,7 +178,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<ApiValidationException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal("Validation Failed", exception.Message);
|
||||
Assert.Equal("key is already in use", exception.ApiError.Errors[0].Message);
|
||||
@@ -202,7 +202,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<RateLimitExceededException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal("API rate limit exceeded. See http://developer.github.com/v3/#rate-limiting for details.",
|
||||
exception.Message);
|
||||
@@ -226,7 +226,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<LoginAttemptsExceededException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal("Maximum number of login attempts exceeded", exception.Message);
|
||||
Assert.Equal("http://developer.github.com/v3", exception.ApiError.DocumentationUrl);
|
||||
@@ -249,7 +249,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<NotFoundException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal("GONE BYE BYE!", exception.Message);
|
||||
}
|
||||
@@ -271,7 +271,7 @@ namespace Octokit.Tests.Http
|
||||
Substitute.For<IJsonSerializer>());
|
||||
|
||||
var exception = await AssertEx.Throws<ForbiddenException>(
|
||||
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
async () => await connection.GetResponse<string>(new Uri("endpoint", UriKind.Relative)));
|
||||
|
||||
Assert.Equal("YOU SHALL NOT PASS!", exception.Message);
|
||||
}
|
||||
|
||||
@@ -79,11 +79,11 @@ namespace Octokit.Tests.Reactive
|
||||
ApiInfo = CreateApiInfo(new Dictionary<string, Uri>())
|
||||
};
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
gitHubClient.Connection.GetAsync<List<Repository>>(firstPageUrl)
|
||||
gitHubClient.Connection.GetResponse<List<Repository>>(firstPageUrl)
|
||||
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => firstPageResponse));
|
||||
gitHubClient.Connection.GetAsync<List<Repository>>(secondPageUrl)
|
||||
gitHubClient.Connection.GetResponse<List<Repository>>(secondPageUrl)
|
||||
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => secondPageResponse));
|
||||
gitHubClient.Connection.GetAsync<List<Repository>>(thirdPageUrl)
|
||||
gitHubClient.Connection.GetResponse<List<Repository>>(thirdPageUrl)
|
||||
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => lastPageResponse));
|
||||
var repositoriesClient = new ObservableRepositoriesClient(gitHubClient);
|
||||
|
||||
@@ -142,13 +142,13 @@ namespace Octokit.Tests.Reactive
|
||||
ApiInfo = CreateApiInfo(new Dictionary<string, Uri>())
|
||||
};
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
gitHubClient.Connection.GetAsync<List<Repository>>(firstPageUrl)
|
||||
gitHubClient.Connection.GetResponse<List<Repository>>(firstPageUrl)
|
||||
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => firstPageResponse));
|
||||
gitHubClient.Connection.GetAsync<List<Repository>>(secondPageUrl)
|
||||
gitHubClient.Connection.GetResponse<List<Repository>>(secondPageUrl)
|
||||
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => secondPageResponse));
|
||||
gitHubClient.Connection.GetAsync<List<Repository>>(thirdPageUrl)
|
||||
gitHubClient.Connection.GetResponse<List<Repository>>(thirdPageUrl)
|
||||
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => thirdPageResponse));
|
||||
gitHubClient.Connection.GetAsync<List<Repository>>(fourthPageUrl)
|
||||
gitHubClient.Connection.GetResponse<List<Repository>>(fourthPageUrl)
|
||||
.Returns(Task.Factory.StartNew<IResponse<List<Repository>>>(() => lastPageResponse));
|
||||
var repositoriesClient = new ObservableRepositoriesClient(gitHubClient);
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
client.GetAllBranches("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<Branch>>(expected);
|
||||
github.Connection.Received(1).GetResponse<List<Branch>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
client.GetAllLanguages("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<Tuple<string, long>>>(expected);
|
||||
github.Connection.Received(1).GetResponse<List<Tuple<string, long>>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
client.GetAllTeams("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<Team>>(expected);
|
||||
github.Connection.Received(1).GetResponse<List<Team>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ namespace Octokit.Tests.Reactive
|
||||
|
||||
client.GetAllTags("owner", "repo");
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<RepositoryTag>>(expected);
|
||||
github.Connection.Received(1).GetResponse<List<RepositoryTag>>(expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Octokit.Tests
|
||||
|
||||
client.GetAll();
|
||||
|
||||
github.Connection.Received(1).GetAsync<List<EmailAddress>>(expectedUri);
|
||||
github.Connection.Received(1).GetResponse<List<EmailAddress>>(expectedUri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Octokit
|
||||
|
||||
try
|
||||
{
|
||||
var response = await ApiConnection.Connection.GetAsync<string>(endpoint);
|
||||
var response = await ApiConnection.Connection.GetResponse<string>(endpoint);
|
||||
return response.StatusCode == System.Net.HttpStatusCode.NoContent;
|
||||
}
|
||||
catch (NotFoundException)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Octokit
|
||||
return connection.GetHtml(uri, null);
|
||||
}
|
||||
|
||||
public static Task<IResponse<T>> GetAsync<T>(this IConnection connection, Uri uri)
|
||||
public static Task<IResponse<T>> GetResponse<T>(this IConnection connection, Uri uri)
|
||||
{
|
||||
Ensure.ArgumentNotNull(connection, "connection");
|
||||
Ensure.ArgumentNotNull(uri, "uri");
|
||||
@@ -49,7 +49,7 @@ namespace Octokit
|
||||
return connection.Get<T>(uri, null, null);
|
||||
}
|
||||
|
||||
public static Task<IResponse<T>> GetAsync<T>(this IConnection connection, Uri uri, CancellationToken cancellationToken)
|
||||
public static Task<IResponse<T>> GetResponse<T>(this IConnection connection, Uri uri, CancellationToken cancellationToken)
|
||||
{
|
||||
Ensure.ArgumentNotNull(connection, "connection");
|
||||
Ensure.ArgumentNotNull(uri, "uri");
|
||||
|
||||
@@ -301,7 +301,7 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNull(uri, "uri");
|
||||
|
||||
var response = await Connection.GetAsync<T>(uri, cancellationToken);
|
||||
var response = await Connection.GetResponse<T>(uri, cancellationToken);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Accepted)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user