public async Task AnalyzeHealthcareEntitiesPagination() { TextAnalyticsClient client = GetClient(); AnalyzeHealthcareEntitiesOperation operation = await client.StartAnalyzeHealthcareEntitiesAsync(s_batchDocuments); Assert.IsFalse(operation.HasCompleted); Assert.IsFalse(operation.HasValue); Assert.ThrowsAsync <InvalidOperationException>(async() => await Task.Run(() => operation.Value)); Assert.ThrowsAsync <InvalidOperationException>(async() => await Task.Run(() => operation.GetValuesAsync())); await operation.WaitForCompletionAsync(); Assert.IsTrue(operation.HasCompleted); Assert.IsTrue(operation.HasValue); ValidateOperationProperties(operation); // try async //There must be 1 page List <AnalyzeHealthcareEntitiesResultCollection> asyncPages = operation.Value.ToEnumerableAsync().Result; Assert.AreEqual(1, asyncPages.Count); // First page should have 2 results Assert.AreEqual(2, asyncPages[0].Count); // try sync //There must be 1 page List <AnalyzeHealthcareEntitiesResultCollection> pages = operation.GetValues().AsEnumerable().ToList(); Assert.AreEqual(1, pages.Count); // First page should have 2 results Assert.AreEqual(2, pages[0].Count); }
public async Task GetValuesAsyncSample() { #region Snippet:PageableOperationGetValuesAsync // create a client var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential()); var document = new List <string>() { "document with information" }; // Start the operation AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document); await healthOperation.WaitForCompletionAsync(); await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValuesAsync()) { foreach (HealthcareEntity entity in documentsInPage[0].Entities) { Console.WriteLine($" Entity: {entity.Text}"); } } #endregion }