本文整理汇总了C#中ApiConnection.GetQueuedOperation方法的典型用法代码示例。如果您正苦于以下问题:C# ApiConnection.GetQueuedOperation方法的具体用法?C# ApiConnection.GetQueuedOperation怎么用?C# ApiConnection.GetQueuedOperation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiConnection
的用法示例。
在下文中一共展示了ApiConnection.GetQueuedOperation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsuresArgumentNotNull
public async Task EnsuresArgumentNotNull()
{
var connection = new ApiConnection(Substitute.For<IConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => connection.GetQueuedOperation<object>(null, CancellationToken.None));
}
示例2: GetIsRepeatedUntilHttpStatusCodeOkIsReturned
public async Task GetIsRepeatedUntilHttpStatusCodeOkIsReturned()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
var result = new object();
IApiResponse<object> firstResponse = new ApiResponse<object>(new Response(HttpStatusCode.Accepted, null, new Dictionary<string, string>(), "application/json"), result);
IApiResponse<object> completedResponse = new ApiResponse<object>(new Response(HttpStatusCode.OK, null, new Dictionary<string, string>(), "application/json"), result);
var connection = Substitute.For<IConnection>();
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken)
.Returns(x => Task.FromResult(firstResponse),
x => Task.FromResult(firstResponse),
x => Task.FromResult(completedResponse));
var apiConnection = new ApiConnection(connection);
await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, CancellationToken.None);
connection.Received(3).GetResponse<object>(queuedOperationUrl, Args.CancellationToken);
}
示例3: CanCancelQueuedOperation
public async Task CanCancelQueuedOperation()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
var result = new object();
IApiResponse<object> accepted = new ApiResponse<object>(new Response(HttpStatusCode.Accepted, null, new Dictionary<string, string>(), "application/json"), result);
var connection = Substitute.For<IConnection>();
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken).Returns(x => Task.FromResult(accepted));
var apiConnection = new ApiConnection(connection);
var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(100);
var canceled = false;
var operationResult = await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, cancellationTokenSource.Token)
.ContinueWith(task =>
{
canceled = task.IsCanceled;
return task;
}, TaskContinuationOptions.OnlyOnCanceled)
.ContinueWith(task => task, TaskContinuationOptions.OnlyOnFaulted);
Assert.True(canceled);
Assert.Null(operationResult);
}
示例4: WhenGetReturnsNotOkOrAcceptedApiExceptionIsThrown
public async Task WhenGetReturnsNotOkOrAcceptedApiExceptionIsThrown()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
const HttpStatusCode statusCode = HttpStatusCode.PartialContent;
IApiResponse<object> response = new ApiResponse<object>(new Response(statusCode, null, new Dictionary<string, string>(), "application/json"), new object());
var connection = Substitute.For<IConnection>();
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken).Returns(Task.FromResult(response));
var apiConnection = new ApiConnection(connection);
await Assert.ThrowsAsync<ApiException>(() => apiConnection.GetQueuedOperation<object>(queuedOperationUrl, Args.CancellationToken));
}
示例5: WhenGetReturnsOkThenBodyAsObjectIsReturned
public async Task WhenGetReturnsOkThenBodyAsObjectIsReturned()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
var result = new object();
const HttpStatusCode statusCode = HttpStatusCode.OK;
IApiResponse<object> response = new ApiResponse<object>(new Response(statusCode, null, new Dictionary<string, string>(), "application/json"), result);
var connection = Substitute.For<IConnection>();
connection.GetResponse<object>(queuedOperationUrl, Args.CancellationToken).Returns(Task.FromResult(response));
var apiConnection = new ApiConnection(connection);
var actualResult = await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, Args.CancellationToken);
Assert.Same(actualResult,result);
}
示例6: MakesGetRequest
public async Task MakesGetRequest()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
const HttpStatusCode statusCode = HttpStatusCode.OK;
IApiResponse<object> response = new ApiResponse<object>(new Response(statusCode, null, new Dictionary<string, string>(), "application/json"), new object());
var connection = Substitute.For<IConnection>();
connection.GetResponse<object>(queuedOperationUrl,Args.CancellationToken).Returns(Task.FromResult(response));
var apiConnection = new ApiConnection(connection);
await apiConnection.GetQueuedOperation<object>(queuedOperationUrl,CancellationToken.None);
connection.Received().GetResponse<object>(queuedOperationUrl, Args.CancellationToken);
}
示例7: GetIsRepeatedUntilHttpStatusCodeOkIsReturned
public async Task GetIsRepeatedUntilHttpStatusCodeOkIsReturned()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
var result = new object();
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)
.Returns(x => Task.FromResult(firstResponse),
x => Task.FromResult(firstResponse),
x => Task.FromResult(completedResponse));
var apiConnection = new ApiConnection(connection);
await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, CancellationToken.None);
connection.Received(3).GetAsync<object>(queuedOperationUrl, Args.CancellationToken);
}
示例8: WhenGetReturnsNotOkOrAcceptedApiExceptionIsThrown
public async Task WhenGetReturnsNotOkOrAcceptedApiExceptionIsThrown()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
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));
var apiConnection = new ApiConnection(connection);
await AssertEx.Throws<ApiException>(async () => await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, Args.CancellationToken));
}
示例9: MakesGetRequest
public async Task MakesGetRequest()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
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));
var apiConnection = new ApiConnection(connection);
await apiConnection.GetQueuedOperation<object>(queuedOperationUrl,CancellationToken.None);
connection.Received().GetAsync<object>(queuedOperationUrl, Args.CancellationToken);
}
示例10: WhenGetReturnsNoContentThenReturnsEmptyCollection
public async Task WhenGetReturnsNoContentThenReturnsEmptyCollection()
{
var queuedOperationUrl = new Uri("anything", UriKind.Relative);
var result = new[] { new object() };
const HttpStatusCode statusCode = HttpStatusCode.NoContent;
var httpResponse = new Response(statusCode, null, new Dictionary<string, string>(), "application/json");
IApiResponse<IReadOnlyList<object>> response = new ApiResponse<IReadOnlyList<object>>(
httpResponse, result);
var connection = Substitute.For<IConnection>();
connection.GetResponse<IReadOnlyList<object>>(queuedOperationUrl, Args.CancellationToken)
.Returns(Task.FromResult(response));
var apiConnection = new ApiConnection(connection);
var actualResult = await apiConnection.GetQueuedOperation<object>(queuedOperationUrl, Args.CancellationToken);
Assert.Empty(actualResult);
}