Example #1
0
        public void ThrowsIfRequestIdPropertyIsNotAString()
        {
            var transport = new MockTransport(r => new MockResponse(200));

            using (HttpPipeline.CreateHttpMessagePropertiesScope(
                       new Dictionary <string, object> {
                { ReadClientRequestIdPolicy.MessagePropertyKey, new List <string>() }
            }))
            {
                Assert.ThrowsAsync <ArgumentException>(async() => await SendGetRequest(transport, ReadClientRequestIdPolicy.Shared));
            }
        }
Example #2
0
        public async Task MessageHasScopedProperty()
        {
            var transport = new MockTransport(r => new MockResponse(200));

            using (HttpPipeline.CreateHttpMessagePropertiesScope(new Dictionary <string, object>()
            {
                { "foo", "bar" }
            }))
            {
                await SendGetRequest(transport, _policyMock.Object);
            }

            Assert.AreEqual(1, _messages.Count);
            _messages[0].TryGetProperty("foo", out var fooProperty);
            Assert.AreEqual("bar", fooProperty);
        }
Example #3
0
        public async Task ScopeIsTerminated()
        {
            var transport = new MockTransport(r => new MockResponse(200));

            using (HttpPipeline.CreateHttpMessagePropertiesScope(new Dictionary <string, object>()
            {
                { "foo", "bar" }
            }))
            {
                await SendGetRequest(transport, _policyMock.Object);
            }

            await SendGetRequest(transport, _policyMock.Object);

            Assert.AreEqual(2, _messages.Count);
            Assert.IsTrue(_messages[0].TryGetProperty("foo", out var _));
            Assert.IsFalse(_messages[1].TryGetProperty("foo", out var _));
        }
Example #4
0
 /// <summary>
 /// Allows you to specify a server timeout for any Storage operations executing on this thread for the duration of the scope.
 ///
 /// For more information, see
 /// <see href="https://docs.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations">
 /// Setting timeouts for Blob service operations</see>,
 /// <see href="https://docs.microsoft.com/rest/api/storageservices/setting-timeouts-for-file-service-operations">
 /// Setting timeouts for File service operations</see>,
 /// <see href="https://docs.microsoft.com/rest/api/storageservices/setting-timeouts-for-queue-service-operations">
 /// Setting timeouts for Queue service operations</see>.
 /// </summary>
 /// <param name="timeout">The server timeout for each HTTP request.</param>
 /// <returns>The <see cref="IDisposable"/> instance that needs to be disposed when server timeout shouldn't be used anymore.</returns>
 /// <example>
 /// Sample usage:
 /// <code snippet="Snippet:Sample_StorageServerTimeout">
 /// BlobServiceClient client = new BlobServiceClient(connectionString, options);
 /// using (StorageExtensions.CreateServiceTimeoutScope(TimeSpan.FromSeconds(10)))
 /// {
 ///     client.GetProperties();
 /// }
 /// </code>
 /// </example>
 /// <remarks>
 /// The server timeout is sent to the Azure Storage service for each REST request made within the scope.
 /// This value is not tracked or validated on the client, it is only passed to the Storage service.
 ///
 /// Consider passing a <see cref="CancellationToken"/> to client methods
 /// and properly sizing <see cref="RetryOptions.NetworkTimeout"/> when configuring storage clients
 /// as prefered way of enforcing upper boundary of execution time.
 /// </remarks>
 public static IDisposable CreateServiceTimeoutScope(TimeSpan?timeout)
 {
     return(HttpPipeline.CreateHttpMessagePropertiesScope(new Dictionary <string, object> {
         { Constants.ServerTimeout.HttpMessagePropertyKey, timeout }
     }));
 }