Exemplo n.º 1
0
        public async Task AnalyzeDocumentOperationCreatesDiagnosticScopeOnUpdate()
        {
            using var testListener = new ClientDiagnosticListener(DiagnosticNamespace);
            using var stream       = new MemoryStream(Encoding.UTF8.GetBytes("{}"));

            var mockResponse = new MockResponse(200);

            mockResponse.ContentStream = stream;

            var mockTransport = new MockTransport(new[] { mockResponse, mockResponse });
            var options       = new DocumentAnalysisClientOptions()
            {
                Transport = mockTransport
            };
            var client = CreateDocumentAnalysisClient(options);

            var operation = new AnalyzeDocumentOperation(AnalyzeOperationId, client);

            if (IsAsync)
            {
                await operation.UpdateStatusAsync();
            }
            else
            {
                operation.UpdateStatus();
            }

            testListener.AssertScope($"{nameof(AnalyzeDocumentOperation)}.{nameof(AnalyzeDocumentOperation.UpdateStatus)}");
        }
Exemplo n.º 2
0
        public void StartAnalyzeDocumentWithError()
        {
            using var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"
                {
                    ""status"": ""failed"",
                    ""createdDateTime"": ""2021-09-15T23:39:58Z"",
                    ""lastUpdatedDateTime"": ""2021-09-15T23:40:02Z"",
                    ""error"": {
                        ""code"": ""InvalidSomething"",
                        ""message"": ""Invalid Something."",
                        ""details"": [
                            {
                                ""code"": ""InternalServerError"",
                                ""message"": ""An unexpected error occurred.""
                            },
                            {
                                ""code"": ""InvalidContentDimensions"",
                                ""message"": ""The input image dimensions are out of range. Refer to documentation for supported image dimensions."",
                                ""target"": ""2""
                            }
                        ]
                    }
                }"));

            var mockResponse = new MockResponse(200);

            mockResponse.ContentStream = stream;

            var mockTransport = new MockTransport(new[] { mockResponse });
            var client        = CreateDocumentAnalysisClient(new DocumentAnalysisClientOptions()
            {
                Transport = mockTransport
            });

            var operation             = new AnalyzeDocumentOperation("prebuilt-businessCard/analyzeResults/642ca81c-7d23-4fc9-a7a0-183d85a84664", client);
            RequestFailedException ex = Assert.ThrowsAsync <RequestFailedException>(async() => await operation.UpdateStatusAsync());

            Assert.AreEqual("InvalidSomething", ex.ErrorCode);
            Assert.IsTrue(ex.Message.Contains("Invalid Something."));
            Assert.IsTrue(ex.Message.Contains("AdditionInformation"));
        }