Skip to content

Commit ac7e23a

Browse files
migrate form recognizer (Azure#25879)
1 parent 24aab72 commit ac7e23a

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

sdk/core/Azure.Core.TestFramework/src/ProxyTransport.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public class ProxyTransport : HttpPipelineTransport
2121
private static readonly RemoteCertificateValidationCallback ServerCertificateCustomValidationCallback =
2222
(_, certificate, _, _) => certificate.Issuer == TestProxy.DevCertIssuer;
2323

24-
public ProxyTransport(TestProxy proxy, HttpPipelineTransport transport, TestRecording recording)
24+
private readonly Func<EntryRecordModel> _filter;
25+
26+
public ProxyTransport(TestProxy proxy, HttpPipelineTransport transport, TestRecording recording, Func<EntryRecordModel> filter)
2527
{
2628
if (transport is HttpClientTransport)
2729
{
@@ -39,6 +41,7 @@ public ProxyTransport(TestProxy proxy, HttpPipelineTransport transport, TestReco
3941
}
4042
_recording = recording;
4143
_proxy = proxy;
44+
_filter = filter;
4245
}
4346

4447
public override void Process(HttpMessage message)
@@ -59,15 +62,15 @@ private async Task ProcessResponseAsync(HttpMessage message, bool async)
5962
{
6063
if (message.Response.Headers.Contains("x-request-mismatch"))
6164
{
62-
var streamreader = new StreamReader(message.Response.ContentStream);
65+
var streamReader = new StreamReader(message.Response.ContentStream);
6366
string response;
6467
if (async)
6568
{
66-
response = await streamreader.ReadToEndAsync();
69+
response = await streamReader.ReadToEndAsync();
6770
}
6871
else
6972
{
70-
response = streamreader.ReadToEnd();
73+
response = streamReader.ReadToEnd();
7174
}
7275
throw new TestRecordingMismatchException(response);
7376
}
@@ -106,6 +109,27 @@ public override Request CreateRequest()
106109
// copied from https://github.com/Azure/azure-sdk-for-net/blob/main/common/Perf/Azure.Test.Perf/TestProxyPolicy.cs
107110
private void RedirectToTestProxy(HttpMessage message)
108111
{
112+
if (_recording.Mode == RecordedTestMode.Record)
113+
{
114+
switch (_filter())
115+
{
116+
case EntryRecordModel.Record:
117+
break;
118+
case EntryRecordModel.RecordWithoutRequestBody:
119+
message.Request.Content = null;
120+
break;
121+
case EntryRecordModel.DoNotRecord:
122+
return;
123+
}
124+
}
125+
else if (_recording.Mode == RecordedTestMode.Playback)
126+
{
127+
if (_filter() == EntryRecordModel.RecordWithoutRequestBody)
128+
{
129+
message.Request.Content = null;
130+
}
131+
}
132+
109133
var request = message.Request;
110134
request.Headers.SetValue("x-recording-id", _recording.RecordingId);
111135
request.Headers.SetValue("x-recording-mode", _recording.Mode.ToString().ToLower());

sdk/core/Azure.Core.TestFramework/src/TestRecording.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public HttpPipelineTransport CreateTransport(HttpPipelineTransport currentTransp
329329
{
330330
if (!_useLegacyTransport && Mode != RecordedTestMode.Live)
331331
{
332-
return new ProxyTransport(_proxy, currentTransport, this);
332+
return new ProxyTransport(_proxy, currentTransport, this, () => _disableRecording.Value);
333333
}
334334
return Mode switch
335335
{

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/DocumentAnalysisLiveTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class DocumentAnalysisLiveTestBase : RecordedTestBase<DocumentAnalysisTes
1919
private readonly DocumentAnalysisClientOptions.ServiceVersion _serviceVersion;
2020

2121
public DocumentAnalysisLiveTestBase(bool isAsync, DocumentAnalysisClientOptions.ServiceVersion serviceVersion)
22-
: base(isAsync, useLegacyTransport: true)
22+
: base(isAsync)
2323
{
2424
_serviceVersion = serviceVersion;
2525
Sanitizer = new DocumentAnalysisRecordedTestSanitizer();

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/Infrastructure/FormRecognizerLiveTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class FormRecognizerLiveTestBase : RecordedTestBase<FormRecognizerTestEnv
2424
private readonly FormRecognizerClientOptions.ServiceVersion _serviceVersion;
2525

2626
public FormRecognizerLiveTestBase(bool isAsync, FormRecognizerClientOptions.ServiceVersion serviceVersion)
27-
: base(isAsync, useLegacyTransport: true)
27+
: base(isAsync)
2828
{
2929
_serviceVersion = serviceVersion;
3030
Sanitizer = new FormRecognizerRecordedTestSanitizer();

0 commit comments

Comments
 (0)