Skip to content

Commit 0103862

Browse files
maririosannelo-msft
authored andcommitted
[FR] Add AAD tests for every endpoint (Azure#17191)
* add tests for every endpoint * remove playback * custom forms with and withouth labels for aad
1 parent 4062b55 commit 0103862

File tree

41 files changed

+25539
-13095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+25539
-13095
lines changed

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormRecognizerClient/FormRecognizerClientLiveTests.cs

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ public void FormRecognizerClientCannotAuthenticateWithFakeApiKey()
4242
}
4343
}
4444

45+
#region StartRecognizeContent
46+
4547
[Test]
46-
public async Task FormRecognizerClientCanAuthenticateWithTokenCredential()
48+
public async Task StartRecognizeContentCanAuthenticateWithTokenCredential()
4749
{
4850
var client = CreateFormRecognizerClient(useTokenCredential: true);
4951
RecognizeContentOperation operation;
@@ -63,8 +65,6 @@ public async Task FormRecognizerClientCanAuthenticateWithTokenCredential()
6365
Assert.AreEqual("Contoso", formPage.Lines[0].Text);
6466
}
6567

66-
#region StartRecognizeContent
67-
6868
/// <summary>
6969
/// Verifies that the <see cref="FormRecognizerClient" /> is able to connect to the Form
7070
/// Recognizer cognitive service and perform operations.
@@ -521,6 +521,32 @@ public void StartRecognizeContentWithNoSupporttedLanguage()
521521

522522
#region StartRecognizeReceipts
523523

524+
[Test]
525+
public async Task StartRecognizeReceiptsCanAuthenticateWithTokenCredential()
526+
{
527+
var client = CreateFormRecognizerClient(useTokenCredential: true);
528+
RecognizeReceiptsOperation operation;
529+
530+
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.ReceiptJpg);
531+
using (Recording.DisableRequestBodyRecording())
532+
{
533+
operation = await client.StartRecognizeReceiptsAsync(stream);
534+
}
535+
536+
// Sanity check to make sure we got an actual response back from the service.
537+
538+
RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);
539+
540+
RecognizedForm form = formPage.Single();
541+
Assert.NotNull(form);
542+
543+
ValidatePrebuiltForm(
544+
form,
545+
includeFieldElements: true,
546+
expectedFirstPageNumber: 1,
547+
expectedLastPageNumber: 1);
548+
}
549+
524550
/// <summary>
525551
/// Verifies that the <see cref="FormRecognizerClient" /> is able to connect to the Form
526552
/// Recognizer cognitive service and perform analysis of receipts.
@@ -969,6 +995,32 @@ public void StartRecognizeReceiptsWithWrongLocale()
969995

970996
#region StartRecognizeBusinessCards
971997

998+
[Test]
999+
public async Task StartRecognizeBusinessCardsCanAuthenticateWithTokenCredential()
1000+
{
1001+
var client = CreateFormRecognizerClient(useTokenCredential: true);
1002+
RecognizeBusinessCardsOperation operation;
1003+
1004+
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.BusinessCardJpg);
1005+
using (Recording.DisableRequestBodyRecording())
1006+
{
1007+
operation = await client.StartRecognizeBusinessCardsAsync(stream);
1008+
}
1009+
1010+
// Sanity check to make sure we got an actual response back from the service.
1011+
1012+
RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);
1013+
1014+
RecognizedForm form = formPage.Single();
1015+
Assert.NotNull(form);
1016+
1017+
ValidatePrebuiltForm(
1018+
form,
1019+
includeFieldElements: true,
1020+
expectedFirstPageNumber: 1,
1021+
expectedLastPageNumber: 1);
1022+
}
1023+
9721024
[Test]
9731025
[TestCase(true)]
9741026
[TestCase(false) ]
@@ -1333,6 +1385,32 @@ public async Task StartRecognizeBusinessCardsCanParseMultipageForm(bool useStrea
13331385

13341386
#region StartRecognizeInvoices
13351387

1388+
[Test]
1389+
public async Task StartRecognizeInvoicesCanAuthenticateWithTokenCredential()
1390+
{
1391+
var client = CreateFormRecognizerClient(useTokenCredential: true);
1392+
RecognizeInvoicesOperation operation;
1393+
1394+
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoicePdf);
1395+
using (Recording.DisableRequestBodyRecording())
1396+
{
1397+
operation = await client.StartRecognizeInvoicesAsync(stream);
1398+
}
1399+
1400+
// Sanity check to make sure we got an actual response back from the service.
1401+
1402+
RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);
1403+
1404+
RecognizedForm form = formPage.Single();
1405+
Assert.NotNull(form);
1406+
1407+
ValidatePrebuiltForm(
1408+
form,
1409+
includeFieldElements: true,
1410+
expectedFirstPageNumber: 1,
1411+
expectedLastPageNumber: 1);
1412+
}
1413+
13361414
[Test]
13371415
[TestCase(true)]
13381416
[TestCase(false)]
@@ -1671,6 +1749,49 @@ public void StartRecognizeInvoicesWithWrongLocale()
16711749

16721750
#region StartRecognizeCustomForms
16731751

1752+
[Test]
1753+
[TestCase(true)]
1754+
[TestCase(false)]
1755+
public async Task StartRecognizeCustomFormsCanAuthenticateWithTokenCredential(bool useTrainingLabels)
1756+
{
1757+
var client = CreateFormRecognizerClient(useTokenCredential: true);
1758+
await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels);
1759+
RecognizeCustomFormsOperation operation;
1760+
1761+
using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.Form1);
1762+
using (Recording.DisableRequestBodyRecording())
1763+
{
1764+
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream);
1765+
}
1766+
1767+
// Sanity check to make sure we got an actual response back from the service.
1768+
1769+
RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);
1770+
1771+
RecognizedForm form = formPage.Single();
1772+
Assert.NotNull(form);
1773+
1774+
if (useTrainingLabels)
1775+
{
1776+
ValidateModelWithLabelsForm(
1777+
form,
1778+
trainedModel.ModelId,
1779+
includeFieldElements: false,
1780+
expectedFirstPageNumber: 1,
1781+
expectedLastPageNumber: 1,
1782+
isComposedModel: false);
1783+
}
1784+
else
1785+
{
1786+
ValidateModelWithNoLabelsForm(
1787+
form,
1788+
trainedModel.ModelId,
1789+
includeFieldElements: false,
1790+
expectedFirstPageNumber: 1,
1791+
expectedLastPageNumber: 1);
1792+
}
1793+
}
1794+
16741795
/// <summary>
16751796
/// Verifies that the <see cref="FormRecognizerClient" /> is able to connect to the Form
16761797
/// Recognizer cognitive service and perform analysis based on a custom labeled model.

sdk/formrecognizer/Azure.AI.FormRecognizer/tests/FormTrainingClient/FormTrainingClientLiveTests.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void FormTrainingClientCannotAuthenticateWithFakeApiKey()
3838
}
3939

4040
[Test]
41-
public async Task FormTrainingClientCanAuthenticateWithTokenCredential()
41+
public async Task StartTrainingCanAuthenticateWithTokenCredential()
4242
{
4343
var client = CreateFormTrainingClient(useTokenCredential: true);
4444
var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl);
@@ -133,9 +133,11 @@ public async Task CheckFormTypeinSubmodelAndRecognizedForm(bool labeled)
133133
}
134134

135135
[Test]
136-
public async Task StartCreateComposedModel()
136+
[TestCase(false)]
137+
[TestCase(true)]
138+
public async Task StartCreateComposedModel(bool useTokenCredential)
137139
{
138-
var client = CreateFormTrainingClient();
140+
var client = CreateFormTrainingClient(useTokenCredential);
139141

140142
await using var trainedModelA = await CreateDisposableTrainedModelAsync(useTrainingLabels: true);
141143
await using var trainedModelB = await CreateDisposableTrainedModelAsync(useTrainingLabels: true);
@@ -289,11 +291,13 @@ public async Task StartTrainingError()
289291
}
290292

291293
[Test]
292-
[TestCase(true)]
293-
[TestCase(false)]
294-
public async Task TrainingOps(bool labeled)
294+
[TestCase(true, true)]
295+
[TestCase(false, true)]
296+
[TestCase(true, false)]
297+
[TestCase(false, false)]
298+
public async Task TrainingOps(bool labeled, bool useTokenCredential)
295299
{
296-
var client = CreateFormTrainingClient();
300+
var client = CreateFormTrainingClient(useTokenCredential);
297301
var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl);
298302

299303
TrainingOperation operation = await client.StartTrainingAsync(trainingFilesUri, labeled);
@@ -371,10 +375,12 @@ public void DeleteModelFailsWhenModelDoesNotExist()
371375
}
372376

373377
[Test]
374-
public async Task CopyModel()
378+
[TestCase(true)]
379+
[TestCase(false)]
380+
public async Task CopyModel(bool useTokenCredential)
375381
{
376-
var sourceClient = CreateFormTrainingClient();
377-
var targetClient = CreateFormTrainingClient();
382+
var sourceClient = CreateFormTrainingClient(useTokenCredential);
383+
var targetClient = CreateFormTrainingClient(useTokenCredential);
378384
var resourceId = TestEnvironment.TargetResourceId;
379385
var region = TestEnvironment.TargetResourceRegion;
380386

@@ -424,10 +430,12 @@ public async Task CopyModelWithLabelsAndModelName()
424430
}
425431

426432
[Test]
427-
public async Task CopyComposedModel()
433+
[TestCase(true)]
434+
[TestCase(false)]
435+
public async Task CopyComposedModel(bool useTokenCredential)
428436
{
429-
var sourceClient = CreateFormTrainingClient();
430-
var targetClient = CreateFormTrainingClient();
437+
var sourceClient = CreateFormTrainingClient(useTokenCredential);
438+
var targetClient = CreateFormTrainingClient(useTokenCredential);
431439
var resourceId = TestEnvironment.TargetResourceId;
432440
var region = TestEnvironment.TargetResourceRegion;
433441

0 commit comments

Comments
 (0)