Esempio n. 1
0
        public void AddsTimeoutToQuery()
        {
            // Arrange
            var client = new BlobServiceClient(_endpoint, _credentials, _clientOptions);

            // Act
            using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout))
            {
                Assert.ThrowsAsync <RequestFailedException>(async() => await client.GetPropertiesAsync());
            }

            // Assert
            StringAssert.Contains($"timeout={ServerTimeoutSeconds}", _transport.SingleRequest.Uri.ToString());
        }
        public async Task DoesNotOverrideAlreadyPresentTimeout()
        {
            // Arrange
            var transport = new MockTransport(r => new MockResponse(200));

            // Act
            using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout))
            {
                await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/?timeout=25"));
            }

            // Assert
            Assert.AreEqual("http://foo.com/?timeout=25", transport.SingleRequest.Uri.ToString());
        }
        public async Task AppendsTimeoutToUriWithNonEmptyQuery()
        {
            // Arrange
            var transport = new MockTransport(r => new MockResponse(200));

            // Act
            using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout))
            {
                await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/?bar=baz"));
            }

            // Assert
            Assert.AreEqual($"http://foo.com/?bar=baz&timeout={ServerTimeoutSeconds}", transport.SingleRequest.Uri.ToString());
        }
        public async Task NestedScopeWins()
        {
            // Arrange
            var transport = new MockTransport(r => new MockResponse(200));

            // Act
            using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout))
            {
                using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout.Add(TimeSpan.FromSeconds(1))))
                {
                    await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/"));
                }
            }

            // Assert
            Assert.AreEqual($"http://foo.com/?timeout={ServerTimeout.TotalSeconds + 1}", transport.SingleRequest.Uri.ToString());
        }
        public async Task CanUnsetTheTimeout()
        {
            // Arrange
            var transport = new MockTransport(r => new MockResponse(200));

            // Act
            using (StorageExtensions.CreateServiceTimeoutScope(ServerTimeout))
            {
                using (StorageExtensions.CreateServiceTimeoutScope(null))
                {
                    await SendGetRequest(transport, StorageServerTimeoutPolicy.Shared, uri : new Uri("http://foo.com/"));
                }
            }

            // Assert
            Assert.AreEqual("http://foo.com/", transport.SingleRequest.Uri.ToString());
        }
Esempio n. 6
0
        public void ApplyServerTimeout()
        {
            // Get a connection string to our Azure Storage account.
            string connectionString = ConnectionString;

            // Create our client options and customize our retries
            BlobClientOptions options = new BlobClientOptions();

            options.Retry.MaxRetries = 5;

            // Create our client and make a simple request
            #region Snippet:Sample_StorageServerTimeout
            BlobServiceClient client = new BlobServiceClient(connectionString, options);
            using (StorageExtensions.CreateServiceTimeoutScope(TimeSpan.FromSeconds(10)))
            {
                client.GetProperties();
            }
            #endregion
        }