public void StartAnalyzeDocumentFromUriArgumentValidation() { var client = CreateInstrumentedClient(); var fakeUri = new Uri("http://localhost"); var options = new AnalyzeDocumentOptions(); Assert.ThrowsAsync <ArgumentNullException>(async() => await client.StartAnalyzeDocumentFromUriAsync(null, fakeUri, options)); Assert.ThrowsAsync <ArgumentException>(async() => await client.StartAnalyzeDocumentFromUriAsync("", fakeUri, options)); Assert.ThrowsAsync <ArgumentNullException>(async() => await client.StartAnalyzeDocumentFromUriAsync("modelId", null, options)); }
public void StartAnalyzeDocumentRespectsTheCancellationToken() { var client = CreateInstrumentedClient(); var options = new AnalyzeDocumentOptions(); using var stream = new MemoryStream(Array.Empty <byte>()); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.ThrowsAsync(Is.InstanceOf <OperationCanceledException>(), async() => await client.StartAnalyzeDocumentAsync("modelId", stream, options, cancellationSource.Token)); }
public void StartAnalyzeDocumentArgumentValidation() { var client = CreateInstrumentedClient(); using var stream = new MemoryStream(Array.Empty <byte>()); var options = new AnalyzeDocumentOptions(); Assert.ThrowsAsync <ArgumentNullException>(async() => await client.StartAnalyzeDocumentAsync(null, stream, options)); Assert.ThrowsAsync <ArgumentException>(async() => await client.StartAnalyzeDocumentAsync("", stream, options)); Assert.ThrowsAsync <ArgumentNullException>(async() => await client.StartAnalyzeDocumentAsync("modelId", null, options)); }
public void StartAnalyzeDocumentFromUriRespectsTheCancellationToken() { var client = CreateInstrumentedClient(); var options = new AnalyzeDocumentOptions(); var fakeUri = new Uri("http://localhost"); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.ThrowsAsync(Is.InstanceOf <OperationCanceledException>(), async() => await client.StartAnalyzeDocumentFromUriAsync("modelId", fakeUri, options, cancellationSource.Token)); }
public async Task StartAnalyzeDocumentSendsUserSpecifiedLocale(string locale) { var mockResponse = new MockResponse(202); mockResponse.AddHeader(new HttpHeader(Constants.OperationLocationHeader, OperationId)); var mockTransport = new MockTransport(new[] { mockResponse, mockResponse }); var options = new DocumentAnalysisClientOptions() { Transport = mockTransport }; var client = CreateInstrumentedClient(options); using var stream = DocumentAnalysisTestEnvironment.CreateStream(TestFile.ReceiptJpg); var analyzeOptions = new AnalyzeDocumentOptions { Locale = locale }; await client.StartAnalyzeDocumentAsync(FakeGuid, stream, analyzeOptions); var requestUriQuery = mockTransport.Requests.Single().Uri.Query; var expectedSubstring = $"locale={locale}"; Assert.True(requestUriQuery.Contains(expectedSubstring)); }
public async Task StartAnalyzeDocumentFromUriSendsMultiplePageArgument(string page1, string page2) { var mockResponse = new MockResponse(202); mockResponse.AddHeader(new HttpHeader(Constants.OperationLocationHeader, OperationId)); var mockTransport = new MockTransport(new[] { mockResponse, mockResponse }); var options = new DocumentAnalysisClientOptions() { Transport = mockTransport }; var client = CreateInstrumentedClient(options); var uri = new Uri("https://fakeuri.com/"); var analyzeOptions = new AnalyzeDocumentOptions { Pages = { page1, page2 } }; await client.StartAnalyzeDocumentFromUriAsync(FakeGuid, uri, analyzeOptions); var requestUriQuery = mockTransport.Requests.Single().Uri.Query; var expectedSubstring = $"pages={page1}%2C{page2}"; Assert.True(requestUriQuery.Contains(expectedSubstring)); }