Пример #1
0
        /// <summary>
        /// Copies the properties from another <see cref="HttpRequestMessage"/>.
        /// </summary>
        /// <param name="subRequest">The sub-request.</param>
        /// <param name="batchRequest">The batch request that contains the properties to copy.</param>
        public static void CopyBatchRequestProperties(this HttpRequestMessage subRequest, HttpRequestMessage batchRequest)
        {
            if (subRequest == null)
            {
                throw new ArgumentNullException("subRequest");
            }
            if (batchRequest == null)
            {
                throw new ArgumentNullException("batchRequest");
            }

            foreach (KeyValuePair <string, object> property in batchRequest.Properties)
            {
                if (!BatchRequestPropertyExclusions.Contains(property.Key))
                {
                    subRequest.Properties.Add(property);
                }
            }

            HttpRequestContext originalContext = subRequest.GetRequestContext();

            if (originalContext != null)
            {
                BatchHttpRequestContext subRequestContext = new BatchHttpRequestContext(originalContext)
                {
                    Url = new UrlHelper(subRequest)
                };

                subRequest.SetRequestContext(subRequestContext);
            }
        }
        /// <summary>
        /// Copies the properties from another <see cref="HttpRequestMessage"/>.
        /// </summary>
        /// <param name="subRequest">The sub-request.</param>
        /// <param name="batchRequest">The batch request that contains the properties to copy.</param>
        public static void CopyBatchRequestProperties(this HttpRequestMessage subRequest, HttpRequestMessage batchRequest)
        {
            if (subRequest == null)
            {
                throw new ArgumentNullException("subRequest");
            }
            if (batchRequest == null)
            {
                throw new ArgumentNullException("batchRequest");
            }

            foreach (KeyValuePair<string, object> property in batchRequest.Properties)
            {
                if (!BatchRequestPropertyExclusions.Contains(property.Key))
                {
                    subRequest.Properties.Add(property);
                }
            }

            HttpRequestContext originalContext = subRequest.GetRequestContext();

            if (originalContext != null)
            {
                BatchHttpRequestContext subRequestContext = new BatchHttpRequestContext(originalContext)
                {
                    Url = new UrlHelper(subRequest)
                };

                subRequest.SetRequestContext(subRequestContext);
            }
        }
Пример #3
0
        public void BatchContext_ReturnsProvidedInstance()
        {
            // Arrange
            HttpRequestContext      expectedBatchContext = CreateDummyContext();
            BatchHttpRequestContext context = CreateProductUnderTest(expectedBatchContext);

            // Act
            HttpRequestContext batchContext = context.BatchContext;

            // Assert
            Assert.Same(expectedBatchContext, batchContext);
        }
Пример #4
0
        public void CopyBatchRequestProperties_AddsBatchHttpRequestContext()
        {
            using (HttpRequestMessage subRequest = new HttpRequestMessage())
                using (HttpRequestMessage batchRequest = new HttpRequestMessage())
                {
                    HttpRequestContext expectedOriginalContext = new HttpRequestContext();
                    subRequest.SetRequestContext(expectedOriginalContext);

                    // Act
                    BatchHttpRequestMessageExtensions.CopyBatchRequestProperties(subRequest, batchRequest);

                    // Assert
                    HttpRequestContext      context      = subRequest.GetRequestContext();
                    BatchHttpRequestContext typedContext = Assert.IsType <BatchHttpRequestContext>(context);
                    Assert.Same(expectedOriginalContext, typedContext.BatchContext);
                }
        }