Пример #1
0
        public void TestStringList()
        {
            var listHolder = new StringListHolder()
            {
                List = new List <string>
                {
                    "First", "Second", "Third"
                }
            };

            var result    = queryStringBuilder.CreateQueryString(listHolder);
            var valueList = QueryStringBuilderTestHelper.CreateValueListFromQueryString(result);

            Assert.IsTrue(result[0] == '?');
            Assert.IsTrue(valueList.Count == 3);

            var sourceIndex = 0;

            foreach (var item in valueList)
            {
                Assert.IsTrue(string.Equals(item[0], "List"));
                Assert.IsTrue(string.Equals(item[1], Uri.EscapeDataString(listHolder.List[sourceIndex])));
                sourceIndex++;
            }
        }
Пример #2
0
        public void TestIntList()
        {
            var listHolder = new IntListHolder()
            {
                List = new List <int>()
                {
                    1, 2, -3
                }
            };

            var result    = queryStringBuilder.CreateQueryString(listHolder);
            var valueList = QueryStringBuilderTestHelper.CreateValueListFromQueryString(result);

            Assert.IsTrue(result[0] == '?');
            Assert.IsTrue(valueList.Count == 3);

            var sourceIndex = 0;

            foreach (var item in valueList)
            {
                Assert.IsTrue(string.Equals(item[0], "List"));
                Assert.IsTrue(string.Equals(item[1], Uri.EscapeDataString(listHolder.List[sourceIndex].ToString(CultureInfo.InvariantCulture))));
                sourceIndex++;
            }
        }
Пример #3
0
        public void TestIntDictionary()
        {
            var dictionaryHolder = new DictionaryHolder()
            {
                Dictionary = new Dictionary <string, int>
                {
                    { "First", 1 },
                    { "Second", 2 },
                    { "Third", 3 }
                }
            };

            var result = queryStringBuilder.CreateQueryString(dictionaryHolder);

            var valueList = QueryStringBuilderTestHelper.CreateValueListFromQueryString(result);

            Assert.IsTrue(result[0] == '?');
            Assert.IsTrue(valueList.Count == dictionaryHolder.Dictionary.Count * 2);

            var dictionaryList      = dictionaryHolder.Dictionary.ToList();
            var dictionaryListIndex = 0;

            foreach (var item in dictionaryList)
            {
                // check key
                Assert.IsTrue(string.Equals(valueList[dictionaryListIndex * 2][0], $"Dictionary[{dictionaryListIndex}].Key"));

                // check value
                Assert.IsTrue(string.Equals(valueList[dictionaryListIndex * 2 + 1][1], Uri.EscapeDataString(item.Value.ToInvariantString())));

                dictionaryListIndex++;
            }
        }
Пример #4
0
        public void TestClassList()
        {
            var listHolder = new ChildListHolder()
            {
                List = new List <Child>
                {
                    new Child {
                        Value = 1
                    },
                    new Child {
                        Value = 2
                    },
                    new Child {
                        Value = 3
                    },
                }
            };

            var result    = queryStringBuilder.CreateQueryString(listHolder);
            var valueList = QueryStringBuilderTestHelper.CreateValueListFromQueryString(result);

            Assert.IsTrue(result[0] == '?');
            Assert.IsTrue(valueList.Count == 3);

            var sourceIndex = 0;

            foreach (var item in valueList)
            {
                Assert.IsTrue(string.Equals(item[0], $"List[{sourceIndex}].Value"));
                Assert.IsTrue(string.Equals(item[1], Uri.EscapeDataString(listHolder.List[sourceIndex].Value.ToInvariantString())));
                sourceIndex++;
            }
        }
Пример #5
0
        public void TestNestedList()
        {
            var nester = new Nester
            {
                Nested = new IntListHolder
                {
                    List = new List <int> {
                        1, 2, 3
                    }
                }
            };

            var result    = queryStringBuilder.CreateQueryString(nester);
            var valueList = QueryStringBuilderTestHelper.CreateValueListFromQueryString(result);

            Assert.IsTrue(result[0] == '?');
            Assert.IsTrue(valueList.Count == 3);

            var sourceIndex = 0;

            foreach (var item in valueList)
            {
                Assert.IsTrue(string.Equals(item[0], "Nested.List"));
                Assert.IsTrue(string.Equals(item[1], Uri.EscapeDataString(nester.Nested.List[sourceIndex].ToInvariantString())));
                sourceIndex++;
            }
        }
Пример #6
0
        public void TestNullList()
        {
            var listHolder = new IntListHolder();

            var result    = queryStringBuilder.CreateQueryString(listHolder);
            var valueList = QueryStringBuilderTestHelper.CreateValueListFromQueryString(result);

            Assert.IsTrue(string.IsNullOrEmpty(result));
            Assert.IsTrue(valueList.Count == 0);
        }