Exemple #1
0
        public void RootClass_TestFamily()
        {
            var date = new DateTime(1981, 12, 01, 14, 23, 20, DateTimeKind.Utc);
            var data = new TestFamily {
                Husband = new TestPerson {
                    Name = "Gagarin", DOB = date, Assets = 1000000, IsRegistered = true, Luck = 0.02312, Respect = PersonRespect.Guru
                },
                Wife = new TestPerson {
                    Name = "Tereshkova", DOB = date, Assets = 2000000, IsRegistered = true, Luck = 678.12, Respect = PersonRespect.Normal
                },
                Kid = new TestPerson {
                    Name = "Savik Shuster", DOB = date, Assets = 3000000, IsRegistered = false, Luck = -23.0032763, Respect = PersonRespect.Low
                },
            };


            var json = JW.Write(data, new JSONWritingOptions {
                SpaceSymbols = true
            });

            Console.WriteLine(json);

            Assert.AreEqual(
                "{\"Husband\": {\"Assets\": 1000000, \"DOB\": \"1981-12-01T14:23:20Z\", \"IsRegistered\": true, \"Luck\": 0.02312, \"Name\": \"Gagarin\", \"Respect\": \"Guru\"}, \"Kid\": {\"Assets\": 3000000, \"DOB\": \"1981-12-01T14:23:20Z\", \"IsRegistered\": false, \"Luck\": -23.0032763, \"Name\": \"Savik Shuster\", \"Respect\": \"Low\"}, \"Wife\": {\"Assets\": 2000000, \"DOB\": \"1981-12-01T14:23:20Z\", \"IsRegistered\": true, \"Luck\": 678.12, \"Name\": \"Tereshkova\", \"Respect\": \"Normal\"}}"
                , json);
        }
Exemple #2
0
        public void RootCompositeWriteRead_Family()
        {
            var originalData =
                new TestFamily {
                Husband = new TestPerson {
                    Name = "Kolyan", DOB = DateTime.Now, Assets = 2000000, IsRegistered = true, Luck = 150.5489
                },
                Wife = new TestPerson {
                    Name = "Feiga", DOB = DateTime.Now, Assets = 578, IsRegistered = false, Luck = 250.489
                },
                Kid = new TestPerson {
                    Name = "Yasha", DOB = DateTime.Now, Assets = 12, IsRegistered = true, Luck = 350.189
                },
            };


            var doc = new PortableObjectDocument(originalData);

            var convertedData = doc.ToOriginalObject() as TestFamily;

            Assert.IsFalse(object.ReferenceEquals(originalData, convertedData));

            Assert.IsTrue(originalData.Equals(convertedData));
        }