Skip to content

Commit

Permalink
[FormRecognizer] Cleaning up misc operations live tests (Azure#38807)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinelski authored and matthohn-msft committed Oct 27, 2023
1 parent 3345ebf commit d253081
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public async Task BuildDocumentClassifierWithAzureBlobContentSource()
Assert.Greater(classifier.CreatedOn, startTime);
Assert.Greater(classifier.ExpiresOn, classifier.CreatedOn);

AssertDocumentTypeDictionariesAreEquivalent(documentTypes, classifier.DocumentTypes);
DocumentAssert.AreEquivalent(documentTypes, classifier.DocumentTypes);
}

[RecordedTest]
Expand Down Expand Up @@ -152,7 +152,7 @@ public async Task BuildDocumentClassifierWithAzureBlobFileListSource()
Assert.Greater(classifier.CreatedOn, startTime);
Assert.Greater(classifier.ExpiresOn, classifier.CreatedOn);

AssertDocumentTypeDictionariesAreEquivalent(documentTypes, classifier.DocumentTypes);
DocumentAssert.AreEquivalent(documentTypes, classifier.DocumentTypes);
}

#endregion Build
Expand All @@ -172,13 +172,7 @@ public async Task GetDocumentClassifier(bool useTokenCredential)
DocumentClassifierDetails expected = disposableClassifier.Value;
DocumentClassifierDetails classifier = await client.GetDocumentClassifierAsync(classifierId);

Assert.AreEqual(expected.ClassifierId, classifier.ClassifierId);
Assert.AreEqual(expected.Description, classifier.Description);
Assert.AreEqual(expected.ServiceVersion, classifier.ServiceVersion);
Assert.AreEqual(expected.CreatedOn, classifier.CreatedOn);
Assert.AreEqual(expected.ExpiresOn, classifier.ExpiresOn);

AssertDocumentTypeDictionariesAreEquivalent(expected.DocumentTypes, classifier.DocumentTypes);
DocumentAssert.AreEqual(expected, classifier);
}

[RecordedTest]
Expand Down Expand Up @@ -234,13 +228,7 @@ public async Task GetDocumentClassifiers(bool useTokenCredential)
DocumentClassifierDetails classifier = idMapping[id];
DocumentClassifierDetails expected = expectedIdMapping[id];

Assert.AreEqual(expected.ClassifierId, classifier.ClassifierId);
Assert.AreEqual(expected.Description, classifier.Description);
Assert.AreEqual(expected.ServiceVersion, classifier.ServiceVersion);
Assert.AreEqual(expected.CreatedOn, classifier.CreatedOn);
Assert.AreEqual(expected.ExpiresOn, classifier.ExpiresOn);

AssertDocumentTypeDictionariesAreEquivalent(expected.DocumentTypes, classifier.DocumentTypes);
DocumentAssert.AreEqual(expected, classifier);
}
}

Expand Down Expand Up @@ -274,45 +262,5 @@ public void DeleteDocumentClassifierThrowsWhenClassifierDoesNotExist()
}

#endregion Delete

private void AssertDocumentTypeDictionariesAreEquivalent(IReadOnlyDictionary<string, ClassifierDocumentTypeDetails> docTypes1, IReadOnlyDictionary<string, ClassifierDocumentTypeDetails> docTypes2)
{
Assert.AreEqual(docTypes1.Count, docTypes2.Count);

foreach (string key in docTypes1.Keys)
{
ClassifierDocumentTypeDetails docType1 = docTypes1[key];
ClassifierDocumentTypeDetails docType2 = docTypes2[key];

Assert.AreEqual(docType1.TrainingDataSource.Kind, docType2.TrainingDataSource.Kind);

if (docType1.TrainingDataSource.Kind == DocumentContentSourceKind.Blob)
{
var source1 = docType1.TrainingDataSource as BlobContentSource;
var source2 = docType2.TrainingDataSource as BlobContentSource;

// The URI returned by the service does not include query parameters, so we're
// making sure they're not included in our comparison.
string uri1 = source1.ContainerUri.GetLeftPart(UriPartial.Path);
string uri2 = source2.ContainerUri.GetLeftPart(UriPartial.Path);

Assert.AreEqual(uri1, uri2);
Assert.AreEqual(source1.Prefix, source2.Prefix);
}
else if (docType1.TrainingDataSource.Kind == DocumentContentSourceKind.BlobFileList)
{
var source1 = docType1.TrainingDataSource as BlobFileListContentSource;
var source2 = docType2.TrainingDataSource as BlobFileListContentSource;

// The URI returned by the service does not include query parameters, so we're
// making sure they're not included in our comparison.
string uri1 = source1.ContainerUri.GetLeftPart(UriPartial.Path);
string uri2 = source2.ContainerUri.GetLeftPart(UriPartial.Path);

Assert.AreEqual(uri1, uri2);
Assert.AreEqual(source1.FileList, source2.FileList);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ public async Task ComposeDocumentModel(bool useTokenCredential)
DocumentTypeDetails documentType0 = model.DocumentTypes[componentModel0.ModelId];
DocumentTypeDetails documentType1 = model.DocumentTypes[componentModel1.ModelId];

AssertDocumentTypesAreEqual(expectedDocumentType0, documentType0);
AssertDocumentTypesAreEqual(expectedDocumentType1, documentType1);
DocumentAssert.AreEqual(expectedDocumentType0, documentType0);
DocumentAssert.AreEqual(expectedDocumentType1, documentType1);
}

[RecordedTest]
Expand Down Expand Up @@ -322,15 +322,7 @@ public async Task GetDocumentModel(bool useTokenCredential)
DocumentModelDetails expected = disposableModel.Value;
DocumentModelDetails model = await client.GetDocumentModelAsync(disposableModel.ModelId);

Assert.AreEqual(expected.ModelId, model.ModelId);
Assert.AreEqual(expected.Description, model.Description);
Assert.AreEqual(expected.ServiceVersion, model.ServiceVersion);
Assert.AreEqual(expected.CreatedOn, model.CreatedOn);
Assert.AreEqual(expected.ExpiresOn, model.ExpiresOn);

CollectionAssert.AreEquivalent(expected.Tags, model.Tags);

AssertDocumentTypeDictionariesAreEquivalent(expected.DocumentTypes, model.DocumentTypes);
DocumentAssert.AreEqual(expected, model);
}

[RecordedTest]
Expand Down Expand Up @@ -445,60 +437,5 @@ public async Task GetCopyAuthorization()
Assert.IsNotEmpty(copyAuthorization.AccessToken);
Assert.Greater(copyAuthorization.ExpiresOn, Recording.UtcNow);
}

private void AssertFieldSchemasAreEqual(DocumentFieldSchema fieldSchema1, DocumentFieldSchema fieldSchema2)
{
if (fieldSchema1 == null)
{
Assert.Null(fieldSchema2);
}
else
{
Assert.NotNull(fieldSchema2);

Assert.AreEqual(fieldSchema1.Type, fieldSchema2.Type);
Assert.AreEqual(fieldSchema1.Description, fieldSchema2.Description);
Assert.AreEqual(fieldSchema1.Example, fieldSchema2.Example);

AssertFieldSchemasAreEqual(fieldSchema1.Items, fieldSchema2.Items);
AssertFieldSchemaDictionariesAreEquivalent(fieldSchema1.Properties, fieldSchema2.Properties);
}
}

private void AssertFieldSchemaDictionariesAreEquivalent(IReadOnlyDictionary<string, DocumentFieldSchema> fieldSchemas1, IReadOnlyDictionary<string, DocumentFieldSchema> fieldSchemas2)
{
Assert.AreEqual(fieldSchemas1.Count, fieldSchemas2.Count);

foreach (string key in fieldSchemas1.Keys)
{
DocumentFieldSchema fieldSchema1 = fieldSchemas1[key];
DocumentFieldSchema fieldSchema2 = fieldSchemas2[key];

AssertFieldSchemasAreEqual(fieldSchema1, fieldSchema2);
}
}

private void AssertDocumentTypesAreEqual(DocumentTypeDetails docType1, DocumentTypeDetails docType2)
{
Assert.AreEqual(docType1.Description, docType2.Description);
Assert.AreEqual(docType1.BuildMode, docType2.BuildMode);

CollectionAssert.AreEquivalent(docType1.FieldConfidence, docType2.FieldConfidence);

AssertFieldSchemaDictionariesAreEquivalent(docType1.FieldSchema, docType2.FieldSchema);
}

private void AssertDocumentTypeDictionariesAreEquivalent(IReadOnlyDictionary<string, DocumentTypeDetails> docTypes1, IReadOnlyDictionary<string, DocumentTypeDetails> docTypes2)
{
Assert.AreEqual(docTypes1.Count, docTypes2.Count);

foreach (string key in docTypes1.Keys)
{
DocumentTypeDetails docType1 = docTypes1[key];
DocumentTypeDetails docType2 = docTypes2[key];

AssertDocumentTypesAreEqual(docType1, docType2);
}
}
}
}
Loading

0 comments on commit d253081

Please sign in to comment.