public void Test_HttpQueryParameter()
        {
            string query = "?$top=10&$skip=12&$customParam=abcd122";
            HttpQueryParameter queryParameter = new HttpQueryParameter(query);

            Assert.IsTrue(queryParameter.Count == 3);
            Assert.IsTrue(queryParameter.ContainsKey("$top"));
            Assert.IsTrue(queryParameter.ContainsKey("$skip"));
            Assert.IsTrue(queryParameter.ContainsKey("$customParam"));

            Assert.AreEqual(
                queryParameter["$top"],
                "10");

            Assert.AreEqual(
                queryParameter["$skip"],
                "12");

            Assert.AreEqual(
                queryParameter["$customParam"],
                "abcd122");

            queryParameter.Add(
                "$prop",
                17);

            Assert.IsTrue(queryParameter.ContainsKey("$prop"));
            Assert.AreEqual(
                queryParameter["$prop"],
                17);

            Assert.IsTrue(queryParameter.Count == 4);

            Assert.AreEqual(
                "$top=10&$skip=12&$customParam=abcd122&$prop=17",
                queryParameter.ToQueryString());

            Assert.IsTrue(queryParameter.Remove("$skip"));
            Assert.AreEqual(
                queryParameter.Count,
                3);

            Assert.AreEqual(
                "$top=10&$customParam=abcd122&$prop=17",
                queryParameter.ToQueryString());
        }
Example #2
0
        /// <summary>
        /// Initialize sync state.
        /// </summary>
        /// <param name="link"></param>
        /// <param name="typeOfToken"></param>
        private void Initialize(string link, TokenType typeOfToken)
        {
            string             token       = this.GetTokenTypeKey(typeOfToken);
            Uri                deltaUri    = new Uri(link);
            HttpQueryParameter queryParams = new HttpQueryParameter(deltaUri.Query);

            if (!queryParams.ContainsKey(token))
            {
                throw new ArgumentException($"Link doesn't contain delta token: '{token}'.");
            }

            this.rawToken  = (string)queryParams[token];
            this.tokenType = typeOfToken;
        }