Ejemplo n.º 1
0
        public void instanceitem_serialize_deserialize_stamp_type_success()
        {
            StampItem item     = GetTestStampItem(4);
            string    jsonItem = JsonConvert.SerializeObject(item);

            StampItem newItem = (StampItem)HomeCollectionRepository.GetCollectableItemFromJson(jsonItem, item.CollectableType);

            Assert.AreEqual(item.CollectableType, newItem.CollectableType);
            Assert.AreEqual(item.EstimatedValue, newItem.EstimatedValue);
            Assert.AreEqual(item.ItemDetails, newItem.ItemDetails);
            Assert.AreEqual(item.IsFavorite, newItem.IsFavorite);
            Assert.AreEqual(item.Condition, newItem.Condition);
        }
Ejemplo n.º 2
0
        public void getcollectableitemfromjson_deserialize_bad_format_throws_exception()
        {
            string jsonItem = "invalid JSON";

            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                bool fail = false;
                try
                {
                    ICollectableItem newItem = HomeCollectionRepository.GetCollectableItemFromJson(jsonItem, collectableType);
                }
                catch (CollectableItemInstanceParseException)
                {
                    fail = true;
                    Assert.IsTrue(fail, "Expected exception to be thrown when JSON is invalid and cannot be parsed to an object");
                }
            }
        }