| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using Azure.Core.Pipeline; |
| | | 8 | | using NUnit.Framework; |
| | | 9 | | |
| | | 10 | | namespace Azure.Core.TestFramework |
| | | 11 | | { |
| | | 12 | | [TestFixture(true)] |
| | | 13 | | [TestFixture(false)] |
| | | 14 | | public class SyncAsyncPolicyTestBase : SyncAsyncTestBase |
| | | 15 | | { |
| | 36 | 16 | | public SyncAsyncPolicyTestBase(bool isAsync) : base(isAsync) |
| | | 17 | | { |
| | 36 | 18 | | } |
| | | 19 | | |
| | | 20 | | protected async Task<Response> SendRequestAsync(HttpPipeline pipeline, Action<Request> requestAction, bool buffe |
| | | 21 | | { |
| | 1308 | 22 | | HttpMessage message = pipeline.CreateMessage(); |
| | 1308 | 23 | | message.BufferResponse = bufferResponse; |
| | 1308 | 24 | | requestAction(message.Request); |
| | | 25 | | |
| | 1308 | 26 | | if (IsAsync) |
| | | 27 | | { |
| | 654 | 28 | | await pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| | | 29 | | } |
| | | 30 | | else |
| | | 31 | | { |
| | 654 | 32 | | pipeline.Send(message, cancellationToken); |
| | | 33 | | } |
| | | 34 | | |
| | 832 | 35 | | return message.Response; |
| | 832 | 36 | | } |
| | | 37 | | |
| | | 38 | | protected async Task<Response> SendRequestAsync(HttpPipelineTransport transport, Action<Request> requestAction, |
| | | 39 | | { |
| | 1228 | 40 | | await Task.Yield(); |
| | | 41 | | |
| | 1228 | 42 | | var pipeline = new HttpPipeline(transport, new[] { policy }, responseClassifier); |
| | 1228 | 43 | | return await SendRequestAsync(pipeline, requestAction, bufferResponse, cancellationToken); |
| | 756 | 44 | | } |
| | | 45 | | |
| | | 46 | | protected async Task<Response> SendGetRequest(HttpPipelineTransport transport, HttpPipelinePolicy policy, Respon |
| | | 47 | | { |
| | 1216 | 48 | | return await SendRequestAsync(transport, request => |
| | 1216 | 49 | | { |
| | 2432 | 50 | | request.Method = RequestMethod.Get; |
| | 2432 | 51 | | request.Uri.Reset(uri ?? new Uri("http://example.com")); |
| | 2432 | 52 | | }, policy, responseClassifier, bufferResponse, cancellationToken); |
| | 748 | 53 | | } |
| | | 54 | | } |
| | | 55 | | } |