Пример #1
0
        public void TestRemove(HeaderType headerType)
        {
            INameValueCollection headers = this.CreateHeaders(headerType);
            string value = Guid.NewGuid().ToString();

            headers[Key] = value;
            Assert.AreEqual(value, headers[Key]);
            headers.Remove(Key);
            Assert.IsNull(headers[Key]);
        }
Пример #2
0
        public void VerifyUnKnownHeader(HeaderType headerType)
        {
            INameValueCollection headers = this.CreateHeaders(headerType);
            string key   = Guid.NewGuid().ToString();
            string value = Guid.NewGuid().ToString();

            headers[key] = value;
            Assert.AreEqual(value, headers[key]);
            Assert.AreEqual(value, headers[key.ToLower()]);
            Assert.AreEqual(value, headers[key.ToUpper()]);
            Assert.AreEqual(value, headers.Get(key));
            Assert.AreEqual(value, headers.Get(key.ToLower()));
            Assert.AreEqual(value, headers.Get(key.ToUpper()));
            Assert.AreEqual(key, headers.Keys().First());

            headers.Remove(key);
            Assert.IsNull(headers[key]);
        }
        public virtual Range <string> ExtractPartitionKeyRangeFromContinuationToken(INameValueCollection headers, out List <CompositeContinuationToken> compositeContinuationTokens)
        {
            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            compositeContinuationTokens = null;

            Range <string> range = Range <string> .GetEmptyRange(PartitionKeyInternal.MinimumInclusiveEffectivePartitionKey);

            if (string.IsNullOrEmpty(headers[HttpConstants.HttpHeaders.Continuation]))
            {
                return(range);
            }

            string providedContinuation = headers[HttpConstants.HttpHeaders.Continuation];
            CompositeContinuationToken initialContinuationToken = null;

            if (!string.IsNullOrEmpty(providedContinuation))
            {
                try
                {
                    if (providedContinuation.Trim().StartsWith("[", StringComparison.Ordinal))
                    {
                        compositeContinuationTokens = JsonConvert.DeserializeObject <List <CompositeContinuationToken> >(providedContinuation);

                        if (compositeContinuationTokens != null && compositeContinuationTokens.Count > 0)
                        {
                            headers[HttpConstants.HttpHeaders.Continuation] = compositeContinuationTokens[0].Token;
                            initialContinuationToken = compositeContinuationTokens[0];
                        }
                        else
                        {
                            headers.Remove(HttpConstants.HttpHeaders.Continuation);
                        }
                    }
                    else
                    {
                        // TODO: Remove the else logic after the gateway deployment is complete
                        initialContinuationToken = JsonConvert.DeserializeObject <CompositeContinuationToken>(providedContinuation);
                        if (initialContinuationToken != null)
                        {
                            compositeContinuationTokens = new List <CompositeContinuationToken> {
                                initialContinuationToken
                            };
                        }
                        else
                        {
                            throw new BadRequestException(RMResources.InvalidContinuationToken);
                        }
                    }

                    if (initialContinuationToken != null && initialContinuationToken.Range != null)
                    {
                        range = initialContinuationToken.Range;
                    }

                    if (initialContinuationToken != null && !string.IsNullOrEmpty(initialContinuationToken.Token))
                    {
                        headers[HttpConstants.HttpHeaders.Continuation] = initialContinuationToken.Token;
                    }
                    else
                    {
                        headers.Remove(HttpConstants.HttpHeaders.Continuation);
                    }
                }
                catch (JsonException ex)
                {
                    DefaultTrace.TraceWarning(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "{0} Invalid JSON in the continuation token {1}",
                            DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture),
                            providedContinuation));
                    throw new BadRequestException(RMResources.InvalidContinuationToken, ex);
                }
            }
            else
            {
                headers.Remove(HttpConstants.HttpHeaders.Continuation);
            }

            return(range);
        }