コード例 #1
0
        public void ShouldSerializeThings()
        {
            InventoryHash inventoryHash = new InventoryHash();
            Thing         thing         = new Thing("thing");

            inventoryHash.Add("in");
            inventoryHash["in"].Add(thing);

            var serializedThing = JsonConvert.SerializeObject(inventoryHash, Formatting.Indented, new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.All,
            });

            Assert.IsTrue(!string.IsNullOrEmpty(serializedThing));

            var newInventoryHash = JsonConvert.DeserializeObject <InventoryHash>(serializedThing);

            Assert.IsTrue(newInventoryHash != null);

            Assert.IsTrue(newInventoryHash.ContainsKey("in"));

            Assert.IsTrue(newInventoryHash["in"].Count == 1);

            Assert.IsTrue(newInventoryHash["in"][0].Name == "thing");
        }
コード例 #2
0
        public void ShouldSerialize()
        {
            InventoryHash inventoryHash = new InventoryHash();

            var serializedThing = JsonConvert.SerializeObject(inventoryHash, Formatting.Indented, new JsonSerializerSettings
            {
                PreserveReferencesHandling = PreserveReferencesHandling.All,
            });

            Assert.IsTrue(!string.IsNullOrEmpty(serializedThing));

            var newInventoryHash = JsonConvert.DeserializeObject <InventoryHash>(serializedThing);

            Assert.IsTrue(newInventoryHash != null);
        }