Beispiel #1
0
        public async Task AnalyzeOperationWithActionsError()
        {
            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"
                {
                    ""displayName"": ""AnalyzeOperationBatchWithErrorTest"",
                    ""jobId"": ""75d521bc-c2aa-4d8a-aabe-713e72d53a2d"",
                    ""lastUpdateDateTime"": ""2021-03-03T22:39:37Z"",
                    ""createdDateTime"": ""2021-03-03T22:39:36Z"",
                    ""expirationDateTime"": ""2021-03-04T22:39:36Z"",
                    ""status"": ""succeeded"",
                    ""errors"": [
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/entityRecognitionPiiTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/entityRecognitionTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/keyPhraseExtractionTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/entityLinkingTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/sentimentAnalysisTasks/0""
                      }
                    ],
                    ""tasks"": {
                      ""details"": {
                        ""name"": ""AnalyzeOperationBatchWithErrorTest"",
                        ""lastUpdateDateTime"": ""2021-03-03T22:39:37Z""
                      },
                      ""completed"": 0,
                      ""failed"": 5,
                      ""inProgress"": 0,
                      ""total"": 5,
                      ""entityRecognitionTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""entityRecognitionPiiTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""keyPhraseExtractionTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""entityLinkingTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""sentimentAnalysisTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ]
                    }
                }"));

            var mockResponse = new MockResponse(200);

            mockResponse.ContentStream = stream;

            var mockTransport = new MockTransport(new[] { mockResponse });
            var client        = CreateTestClient(mockTransport);

            var documents = new List <string>
            {
                "Elon Musk is the CEO of SpaceX and Tesla."
            };

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                },
                RecognizeEntitiesActions = new List <RecognizeEntitiesAction>()
                {
                    new RecognizeEntitiesAction()
                },
                RecognizePiiEntitiesActions = new List <RecognizePiiEntitiesAction>()
                {
                    new RecognizePiiEntitiesAction()
                },
                RecognizeLinkedEntitiesActions = new List <RecognizeLinkedEntitiesAction>()
                {
                    new RecognizeLinkedEntitiesAction()
                },
                AnalyzeSentimentActions = new List <AnalyzeSentimentAction>()
                {
                    new AnalyzeSentimentAction()
                },
                DisplayName = "AnalyzeOperationBatchWithErrorTest"
            };

            var operation = new AnalyzeActionsOperation("75d521bc-c2aa-4d8a-aabe-713e72d53a2d", client);
            await operation.UpdateStatusAsync();

            Assert.AreEqual(5, operation.ActionsFailed);
            Assert.AreEqual(0, operation.ActionsSucceeded);
            Assert.AreEqual(0, operation.ActionsInProgress);
            Assert.AreEqual(5, operation.ActionsTotal);

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            RecognizeEntitiesActionResult       entitiesActionsResults         = resultCollection.RecognizeEntitiesResults.FirstOrDefault();
            ExtractKeyPhrasesActionResult       keyPhrasesActionsResults       = resultCollection.ExtractKeyPhrasesResults.FirstOrDefault();
            RecognizePiiEntitiesActionResult    piiActionsResults              = resultCollection.RecognizePiiEntitiesResults.FirstOrDefault();
            RecognizeLinkedEntitiesActionResult entityLinkingActionsResults    = resultCollection.RecognizeLinkedEntitiesResults.FirstOrDefault();
            AnalyzeSentimentActionResult        analyzeSentimentActionsResults = resultCollection.AnalyzeSentimentResults.FirstOrDefault();

            Assert.IsTrue(entitiesActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => entitiesActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(keyPhrasesActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => keyPhrasesActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(piiActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => piiActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(entityLinkingActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => entityLinkingActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(analyzeSentimentActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => analyzeSentimentActionsResults.DocumentsResults.GetType());
        }
        public async Task AnalyzeOperationWithActionsError()
        {
            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"
                {
                    ""displayName"": ""AnalyzeOperationBatchWithErrorTest"",
                    ""jobId"": ""75d521bc-c2aa-4d8a-aabe-713e72d53a2d"",
                    ""lastUpdateDateTime"": ""2021-03-03T22:39:37Z"",
                    ""createdDateTime"": ""2021-03-03T22:39:36Z"",
                    ""expirationDateTime"": ""2021-03-04T22:39:36Z"",
                    ""status"": ""succeeded"",
                    ""errors"": [
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/entityRecognitionPiiTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/entityRecognitionTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/keyPhraseExtractionTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/entityLinkingTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/sentimentAnalysisTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/extractiveSummarizationTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/customEntityRecognitionTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/customSingleClassificationTasks/0""
                      },
                      {
                        ""code"": ""InvalidRequest"",
                        ""message"": ""Some error"",
                        ""target"": ""#/tasks/customMultiClassificationTasks/0""
                      }
                    ],
                    ""tasks"": {
                      ""details"": {
                        ""name"": ""AnalyzeOperationBatchWithErrorTest"",
                        ""lastUpdateDateTime"": ""2021-03-03T22:39:37Z""
                      },
                      ""completed"": 0,
                      ""failed"": 9,
                      ""inProgress"": 0,
                      ""total"": 9,
                      ""entityRecognitionTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""entityRecognitionPiiTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""keyPhraseExtractionTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""entityLinkingTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""sentimentAnalysisTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""extractiveSummarizationTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                     ""customEntityRecognitionTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                     ""customSingleClassificationTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ],
                      ""customMultiClassificationTasks"": [
                        {
                          ""lastUpdateDateTime"": ""2021-03-03T22:39:37.1716697Z"",
                          ""taskName"": ""something"",
                          ""state"": ""failed""
                        }
                      ]
                    }
                }"));

            var mockResponse = new MockResponse(200);

            mockResponse.ContentStream = stream;

            var mockTransport = new MockTransport(new[] { mockResponse });
            var client        = CreateTestClient(mockTransport);

            AnalyzeActionsOperation operation = CreateOperation(client);
            await operation.UpdateStatusAsync();

            Assert.AreEqual(9, operation.ActionsFailed);
            Assert.AreEqual(0, operation.ActionsSucceeded);
            Assert.AreEqual(0, operation.ActionsInProgress);
            Assert.AreEqual(9, operation.ActionsTotal);

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            RecognizeEntitiesActionResult       entitiesActionsResults               = resultCollection.RecognizeEntitiesResults.FirstOrDefault();
            ExtractKeyPhrasesActionResult       keyPhrasesActionsResults             = resultCollection.ExtractKeyPhrasesResults.FirstOrDefault();
            RecognizePiiEntitiesActionResult    piiActionsResults                    = resultCollection.RecognizePiiEntitiesResults.FirstOrDefault();
            RecognizeLinkedEntitiesActionResult entityLinkingActionsResults          = resultCollection.RecognizeLinkedEntitiesResults.FirstOrDefault();
            AnalyzeSentimentActionResult        analyzeSentimentActionsResults       = resultCollection.AnalyzeSentimentResults.FirstOrDefault();
            ExtractSummaryActionResult          extractSummaryActionsResults         = resultCollection.ExtractSummaryResults.FirstOrDefault();
            RecognizeCustomEntitiesActionResult recognizeCustomEntitiesActionResults = resultCollection.RecognizeCustomEntitiesResults.FirstOrDefault();
            SingleCategoryClassifyActionResult  singleCategoryClassifyActionResult   = resultCollection.SingleCategoryClassifyResults.FirstOrDefault();
            MultiCategoryClassifyActionResult   multiCategoryClassifyActionResult    = resultCollection.MultiCategoryClassifyResults.FirstOrDefault();

            Assert.IsTrue(entitiesActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => entitiesActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(keyPhrasesActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => keyPhrasesActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(piiActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => piiActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(entityLinkingActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => entityLinkingActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(analyzeSentimentActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => analyzeSentimentActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(extractSummaryActionsResults.HasError);
            Assert.Throws <InvalidOperationException>(() => extractSummaryActionsResults.DocumentsResults.GetType());

            Assert.IsTrue(recognizeCustomEntitiesActionResults.HasError);
            Assert.Throws <InvalidOperationException>(() => recognizeCustomEntitiesActionResults.DocumentsResults.GetType());

            Assert.IsTrue(singleCategoryClassifyActionResult.HasError);
            Assert.Throws <InvalidOperationException>(() => singleCategoryClassifyActionResult.DocumentsResults.GetType());

            Assert.IsTrue(multiCategoryClassifyActionResult.HasError);
            Assert.Throws <InvalidOperationException>(() => multiCategoryClassifyActionResult.DocumentsResults.GetType());
        }