Ejemplo n.º 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++;
            }
        }
Ejemplo n.º 2
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++;
            }
        }
Ejemplo n.º 3
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++;
            }
        }
Ejemplo n.º 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++;
            }
        }
Ejemplo n.º 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++;
            }
        }
        public void SerializesTypesWithNesting()
        {
            var queryObject = new QueryWithNesting
            {
                AString = "Parent",
                First   = new QueryWithTypes
                {
                    AString = "Nesting1"
                },
                Second = new QueryWithNesting
                {
                    AString = "Nesting2",
                    Second  = new QueryWithNesting
                    {
                        AString = "Nesting3"
                    },
                }
            };

            var result          = queryStringBuilder.CreateQueryString(queryObject);
            var valueDictionary = QueryStringBuilderTestHelper.CreateValueDictionaryFromQueryString(result);

            Assert.IsTrue(result[0] == '?');
            Assert.IsTrue(valueDictionary.Count == 4);
            Assert.IsTrue(valueDictionary["AString"] == queryObject.AString);
            Assert.IsTrue(valueDictionary["First.AString"] == queryObject.First.AString);
            Assert.IsTrue(valueDictionary["Second.AString"] == queryObject.Second.AString);
            Assert.IsTrue(valueDictionary["Second.Second.AString"] == queryObject.Second.Second.AString);
        }
Ejemplo n.º 7
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);
        }
        public void SerializesTypesWithValues()
        {
            var queryObject = new QueryWithTypes
            {
                ABool           = true,
                AString         = "Tree",
                AInt            = 5,
                ALong           = 11L,
                AFloat          = 0.5f,
                ADouble         = 1.7,
                AEnum           = TestEnum.Value1,
                ADateTime       = new DateTime(2000, 5, 4, 3, 2, 1),
                ATimeSpan       = new TimeSpan(5, 4, 3, 2, 1),
                ADecimal        = 9,
                ANullableInt    = 2,
                ADateTimeOffset = new DateTimeOffset(2001, 11, 23, 18, 10, 5, new TimeSpan(0, 2, 0, 0))
            };

            var result          = queryStringBuilder.CreateQueryString(queryObject);
            var valueDictionary = QueryStringBuilderTestHelper.CreateValueDictionaryFromQueryString(result);

            Assert.IsTrue(result[0] == '?');
            Assert.IsTrue(valueDictionary.Count == 12);
            Assert.IsTrue(valueDictionary["ABool"] == queryObject.ABool.ToString());
            Assert.IsTrue(valueDictionary["AString"] == queryObject.AString);
            Assert.IsTrue(valueDictionary["AInt"] == queryObject.AInt.ToInvariantString());
            Assert.IsTrue(valueDictionary["ALong"] == queryObject.ALong.ToInvariantString());
            Assert.IsTrue(valueDictionary["AFloat"] == Uri.EscapeDataString(queryObject.AFloat.ToInvariantString()));
            Assert.IsTrue(valueDictionary["ADouble"] == Uri.EscapeDataString(queryObject.ADouble.ToInvariantString()));
            Assert.IsTrue(valueDictionary["AEnum"] == queryObject.AEnum.ToString());
            Assert.IsTrue(valueDictionary["ADateTime"] == Uri.EscapeDataString(queryObject.ADateTime.ToInvariantString()));
            Assert.IsTrue(valueDictionary["ATimeSpan"] == Uri.EscapeDataString(queryObject.ATimeSpan.ToString()));
            Assert.IsTrue(valueDictionary["ADecimal"] == Uri.EscapeDataString(queryObject.ADecimal.ToInvariantString()));
            Assert.IsTrue(valueDictionary["ANullableInt"] == queryObject.ANullableInt.ToString());
            Assert.IsTrue(valueDictionary["ADateTimeOffset"] == Uri.EscapeDataString(queryObject.ADateTimeOffset.ToInvariantString()));
        }