Skip to content

Commit

Permalink
[FR] Add AAD tests for every endpoint (Azure#17191)
Browse files Browse the repository at this point in the history
* add tests for every endpoint

* remove playback

* custom forms with and withouth labels for aad
  • Loading branch information
maririos authored and annelo-msft committed Feb 17, 2021
1 parent 4062b55 commit 0103862
Show file tree
Hide file tree
Showing 41 changed files with 25,539 additions and 13,095 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public void FormRecognizerClientCannotAuthenticateWithFakeApiKey()
}
}

#region StartRecognizeContent

[Test]
public async Task FormRecognizerClientCanAuthenticateWithTokenCredential()
public async Task StartRecognizeContentCanAuthenticateWithTokenCredential()
{
var client = CreateFormRecognizerClient(useTokenCredential: true);
RecognizeContentOperation operation;
Expand All @@ -63,8 +65,6 @@ public async Task FormRecognizerClientCanAuthenticateWithTokenCredential()
Assert.AreEqual("Contoso", formPage.Lines[0].Text);
}

#region StartRecognizeContent

/// <summary>
/// Verifies that the <see cref="FormRecognizerClient" /> is able to connect to the Form
/// Recognizer cognitive service and perform operations.
Expand Down Expand Up @@ -521,6 +521,32 @@ public void StartRecognizeContentWithNoSupporttedLanguage()

#region StartRecognizeReceipts

[Test]
public async Task StartRecognizeReceiptsCanAuthenticateWithTokenCredential()
{
var client = CreateFormRecognizerClient(useTokenCredential: true);
RecognizeReceiptsOperation operation;

using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.ReceiptJpg);
using (Recording.DisableRequestBodyRecording())
{
operation = await client.StartRecognizeReceiptsAsync(stream);
}

// Sanity check to make sure we got an actual response back from the service.

RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);

RecognizedForm form = formPage.Single();
Assert.NotNull(form);

ValidatePrebuiltForm(
form,
includeFieldElements: true,
expectedFirstPageNumber: 1,
expectedLastPageNumber: 1);
}

/// <summary>
/// Verifies that the <see cref="FormRecognizerClient" /> is able to connect to the Form
/// Recognizer cognitive service and perform analysis of receipts.
Expand Down Expand Up @@ -969,6 +995,32 @@ public void StartRecognizeReceiptsWithWrongLocale()

#region StartRecognizeBusinessCards

[Test]
public async Task StartRecognizeBusinessCardsCanAuthenticateWithTokenCredential()
{
var client = CreateFormRecognizerClient(useTokenCredential: true);
RecognizeBusinessCardsOperation operation;

using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.BusinessCardJpg);
using (Recording.DisableRequestBodyRecording())
{
operation = await client.StartRecognizeBusinessCardsAsync(stream);
}

// Sanity check to make sure we got an actual response back from the service.

RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);

RecognizedForm form = formPage.Single();
Assert.NotNull(form);

ValidatePrebuiltForm(
form,
includeFieldElements: true,
expectedFirstPageNumber: 1,
expectedLastPageNumber: 1);
}

[Test]
[TestCase(true)]
[TestCase(false) ]
Expand Down Expand Up @@ -1333,6 +1385,32 @@ public async Task StartRecognizeBusinessCardsCanParseMultipageForm(bool useStrea

#region StartRecognizeInvoices

[Test]
public async Task StartRecognizeInvoicesCanAuthenticateWithTokenCredential()
{
var client = CreateFormRecognizerClient(useTokenCredential: true);
RecognizeInvoicesOperation operation;

using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoicePdf);
using (Recording.DisableRequestBodyRecording())
{
operation = await client.StartRecognizeInvoicesAsync(stream);
}

// Sanity check to make sure we got an actual response back from the service.

RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);

RecognizedForm form = formPage.Single();
Assert.NotNull(form);

ValidatePrebuiltForm(
form,
includeFieldElements: true,
expectedFirstPageNumber: 1,
expectedLastPageNumber: 1);
}

[Test]
[TestCase(true)]
[TestCase(false)]
Expand Down Expand Up @@ -1671,6 +1749,49 @@ public void StartRecognizeInvoicesWithWrongLocale()

#region StartRecognizeCustomForms

[Test]
[TestCase(true)]
[TestCase(false)]
public async Task StartRecognizeCustomFormsCanAuthenticateWithTokenCredential(bool useTrainingLabels)
{
var client = CreateFormRecognizerClient(useTokenCredential: true);
await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels);
RecognizeCustomFormsOperation operation;

using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.Form1);
using (Recording.DisableRequestBodyRecording())
{
operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream);
}

// Sanity check to make sure we got an actual response back from the service.

RecognizedFormCollection formPage = await operation.WaitForCompletionAsync(PollingInterval);

RecognizedForm form = formPage.Single();
Assert.NotNull(form);

if (useTrainingLabels)
{
ValidateModelWithLabelsForm(
form,
trainedModel.ModelId,
includeFieldElements: false,
expectedFirstPageNumber: 1,
expectedLastPageNumber: 1,
isComposedModel: false);
}
else
{
ValidateModelWithNoLabelsForm(
form,
trainedModel.ModelId,
includeFieldElements: false,
expectedFirstPageNumber: 1,
expectedLastPageNumber: 1);
}
}

/// <summary>
/// Verifies that the <see cref="FormRecognizerClient" /> is able to connect to the Form
/// Recognizer cognitive service and perform analysis based on a custom labeled model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void FormTrainingClientCannotAuthenticateWithFakeApiKey()
}

[Test]
public async Task FormTrainingClientCanAuthenticateWithTokenCredential()
public async Task StartTrainingCanAuthenticateWithTokenCredential()
{
var client = CreateFormTrainingClient(useTokenCredential: true);
var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl);
Expand Down Expand Up @@ -133,9 +133,11 @@ public async Task CheckFormTypeinSubmodelAndRecognizedForm(bool labeled)
}

[Test]
public async Task StartCreateComposedModel()
[TestCase(false)]
[TestCase(true)]
public async Task StartCreateComposedModel(bool useTokenCredential)
{
var client = CreateFormTrainingClient();
var client = CreateFormTrainingClient(useTokenCredential);

await using var trainedModelA = await CreateDisposableTrainedModelAsync(useTrainingLabels: true);
await using var trainedModelB = await CreateDisposableTrainedModelAsync(useTrainingLabels: true);
Expand Down Expand Up @@ -289,11 +291,13 @@ public async Task StartTrainingError()
}

[Test]
[TestCase(true)]
[TestCase(false)]
public async Task TrainingOps(bool labeled)
[TestCase(true, true)]
[TestCase(false, true)]
[TestCase(true, false)]
[TestCase(false, false)]
public async Task TrainingOps(bool labeled, bool useTokenCredential)
{
var client = CreateFormTrainingClient();
var client = CreateFormTrainingClient(useTokenCredential);
var trainingFilesUri = new Uri(TestEnvironment.BlobContainerSasUrl);

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

[Test]
public async Task CopyModel()
[TestCase(true)]
[TestCase(false)]
public async Task CopyModel(bool useTokenCredential)
{
var sourceClient = CreateFormTrainingClient();
var targetClient = CreateFormTrainingClient();
var sourceClient = CreateFormTrainingClient(useTokenCredential);
var targetClient = CreateFormTrainingClient(useTokenCredential);
var resourceId = TestEnvironment.TargetResourceId;
var region = TestEnvironment.TargetResourceRegion;

Expand Down Expand Up @@ -424,10 +430,12 @@ public async Task CopyModelWithLabelsAndModelName()
}

[Test]
public async Task CopyComposedModel()
[TestCase(true)]
[TestCase(false)]
public async Task CopyComposedModel(bool useTokenCredential)
{
var sourceClient = CreateFormTrainingClient();
var targetClient = CreateFormTrainingClient();
var sourceClient = CreateFormTrainingClient(useTokenCredential);
var targetClient = CreateFormTrainingClient(useTokenCredential);
var resourceId = TestEnvironment.TargetResourceId;
var region = TestEnvironment.TargetResourceRegion;

Expand Down
Loading

0 comments on commit 0103862

Please sign in to comment.