Esempio n. 1
0
        public void Can_Deserialize_Names_With_Underscores_With_Default_Root()
        {
            var doc        = JsonData.CreateJsonWithUnderscores();
            var serializer = new JsonSerializer();
            var response   = new RestResponse {
                Content = doc
            };
            var p = serializer.Deserialize <PersonForJson>(response);

            Assert.AreEqual("John Sheehan", p.Name);
            Assert.AreEqual(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
            Assert.AreEqual(28, p.Age);
            Assert.AreEqual(long.MaxValue, p.BigNumber);
            Assert.AreEqual(99.9999m, p.Percent);
            Assert.AreEqual(false, p.IsCool);
            Assert.AreEqual(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
            Assert.AreEqual(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
            Assert.NotNull(p.Friends);
            Assert.AreEqual(10, p.Friends.Count);
            Assert.NotNull(p.BestFriend);
            Assert.AreEqual("The Fonz", p.BestFriend.Name);
            Assert.AreEqual(1952, p.BestFriend.Since);
            Assert.IsNotEmpty(p.Foes);
            Assert.AreEqual("Foe 1", p.Foes["dict1"].Nickname);
            Assert.AreEqual("Foe 2", p.Foes["dict2"].Nickname);
        }