Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Add AAD tests for every endpoint #17191

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
maririos marked this conversation as resolved.
Show resolved Hide resolved
{
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