예제 #1
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()));
        }