本文整理汇总了C#中System.Net.Connection.GetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.GetAsync方法的具体用法?C# Connection.GetAsync怎么用?C# Connection.GetAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Connection
的用法示例。
在下文中一共展示了Connection.GetAsync方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanMakeMutipleRequestsWithSameConnection
public async Task CanMakeMutipleRequestsWithSameConnection()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>();
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
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));
httpClient.Received(3).Send<string>(Arg.Is<IRequest>(req =>
req.BaseAddress == ExampleUri &&
req.Method == HttpMethod.Get &&
req.Endpoint == new Uri("endpoint", UriKind.Relative)));
}
示例2: SendsProperlyFormattedRequest
public async Task SendsProperlyFormattedRequest()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>();
httpClient.Send<string>(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.GetAsync<string>(new Uri("endpoint", UriKind.Relative));
httpClient.Received(1).Send<string>(Arg.Is<IRequest>(req =>
req.BaseAddress == ExampleUri &&
req.ContentType == null &&
req.Body == null &&
req.Method == HttpMethod.Get &&
req.Endpoint == new Uri("endpoint", UriKind.Relative)), Args.CancellationToken);
}
示例3: ParsesApiInfoOnResponse
public async Task ParsesApiInfoOnResponse()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>
{
Headers =
{
{ "X-Accepted-OAuth-Scopes", "user" },
}
};
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var resp = await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative));
Assert.NotNull(resp.ApiInfo);
Assert.Equal("user", resp.ApiInfo.AcceptedOauthScopes.First());
}
示例4: ThrowsAuthorizationExceptionExceptionForUnauthorizedResponse
public async Task ThrowsAuthorizationExceptionExceptionForUnauthorizedResponse()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string> { StatusCode = HttpStatusCode.Unauthorized};
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await AssertEx.Throws<AuthorizationException>(
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
Assert.NotNull(exception);
}
示例5: ThrowsForbiddenExceptionForUnknownForbiddenResponse
public async Task ThrowsForbiddenExceptionForUnknownForbiddenResponse()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>
{
StatusCode = HttpStatusCode.Forbidden,
Body = "YOU SHALL NOT PASS!"
};
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await AssertEx.Throws<ForbiddenException>(
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
Assert.Equal("YOU SHALL NOT PASS!", exception.Message);
}
示例6: ThrowsLoginAttemptsExceededExceptionForForbiddenResponse
public async Task ThrowsLoginAttemptsExceededExceptionForForbiddenResponse()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>
{
StatusCode = HttpStatusCode.Forbidden,
Body = "{\"message\":\"Maximum number of login attempts exceeded\"," +
"\"documentation_url\":\"http://developer.github.com/v3\"}"
};
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await AssertEx.Throws<LoginAttemptsExceededException>(
async () => await connection.GetAsync<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);
}
示例7: ThrowsRateLimitExceededExceptionForForbidderResponse
public async Task ThrowsRateLimitExceededExceptionForForbidderResponse()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>
{
StatusCode = HttpStatusCode.Forbidden,
Body = "{\"message\":\"API rate limit exceeded. " +
"See http://developer.github.com/v3/#rate-limiting for details.\"}"
};
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await AssertEx.Throws<RateLimitExceededException>(
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
Assert.Equal("API rate limit exceeded. See http://developer.github.com/v3/#rate-limiting for details.",
exception.Message);
}
示例8: ThrowsApiValidationExceptionFor422Response
public async Task ThrowsApiValidationExceptionFor422Response()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>
{
StatusCode = (HttpStatusCode)422,
Body = @"{""errors"":[{""code"":""custom"",""field"":""key"",""message"":""key is " +
@"already in use"",""resource"":""PublicKey""}],""message"":""Validation Failed""}"
};
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await AssertEx.Throws<ApiValidationException>(
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
Assert.Equal("Validation Failed", exception.Message);
Assert.Equal("key is already in use", exception.ApiError.Errors[0].Message);
}
示例9: ThrowsTwoFactorExceptionExceptionWhenChallenged
public async Task ThrowsTwoFactorExceptionExceptionWhenChallenged(
string headerKey,
string otpHeaderValue,
TwoFactorType expectedFactorType)
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>
{
StatusCode = HttpStatusCode.Unauthorized,
};
response.Headers[headerKey] = otpHeaderValue;
httpClient.Send<string>(Args.Request).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await AssertEx.Throws<TwoFactorRequiredException>(
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
Assert.Equal(expectedFactorType, exception.TwoFactorType);
}
示例10: ThrowsNotFoundExceptionForFileNotFoundResponse
public async Task ThrowsNotFoundExceptionForFileNotFoundResponse()
{
var httpClient = Substitute.For<IHttpClient>();
IResponse<string> response = new ApiResponse<string>
{
StatusCode = HttpStatusCode.NotFound,
Body = "GONE BYE BYE!"
};
httpClient.Send<string>(Args.Request, Args.CancellationToken).Returns(Task.FromResult(response));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
ExampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
var exception = await AssertEx.Throws<NotFoundException>(
async () => await connection.GetAsync<string>(new Uri("endpoint", UriKind.Relative)));
Assert.Equal("GONE BYE BYE!", exception.Message);
}