Beispiel #1
0
        public void GivenObject_DisposeIt()
        {
            var obj     = new object();
            var visitor = new JsonVisitor(obj);

            visitor.Dispose();
        }
Beispiel #2
0
        public void GivenObject_Enumerable_MustVisitAllProperty()
        {
            var obj = new
            {
                A = 1,
                B = 2
            };
            var visitor = new JsonVisitor(obj);

            var map = visitor.ToDictionary(x => x.Key.ToLower(), x => x.Value.ToString());

            Assert.AreEqual(2, map.Count);
            Assert.AreEqual("1", map["a"]);
            Assert.AreEqual("2", map["b"]);

            IEnumerable v = visitor;

            map = new Dictionary <string, string>();
            var enu = v.GetEnumerator();

            while (enu.MoveNext())
            {
                var c = (KeyValuePair <string, IJsonVisitor>)enu.Current;
                map.Add(c.Key.ToLower(), c.Value.ToString());
            }

            Assert.AreEqual(2, map.Count);
            Assert.AreEqual("1", map["a"]);
            Assert.AreEqual("2", map["b"]);

            visitor.Dispose();
        }
Beispiel #3
0
        public void InitWithNull_HasValueMustFalse()
        {
            var visitor = new JsonVisitor((object)null);

            Assert.IsFalse(visitor.HasValue);
            visitor.Dispose();
#if NET45
            visitor = new JsonVisitor((JToken)null);
            Assert.IsFalse(visitor.HasValue);
            visitor.Dispose();
#endif
        }