Ejemplo n.º 1
0
        public void getcollectablefromjson_deserialize_bad_format_throws_exception()
        {
            string jsonCollectable = "invalid JSON";

            foreach (Type collectableType in CollectableBaseFactory.CollectableTypes)
            {
                bool fail = false;
                try
                {
                    ICollectableBase newCollectable = HomeCollectionRepository.GetCollectableFromJson(jsonCollectable, collectableType);
                }
                catch (CollectableParseException)
                {
                    fail = true;
                    Assert.IsTrue(fail, "Expected exception to be thrown when JSON is invalid and cannot be parsed to an object");
                }
            }
        }
Ejemplo n.º 2
0
        public void collectable_serialize_deserialize_stamp_success()
        {
            StampBase collectable = GetTestStampBase(5);

            collectable.AddItem(GetTestStampItem(0));
            collectable.AddItem(GetTestStampItem(1));
            collectable.AddItem(GetTestStampItem(2));

            string    jsonItem       = JsonConvert.SerializeObject(collectable);
            StampBase newCollectable = (StampBase)HomeCollectionRepository.GetCollectableFromJson(jsonItem, collectable.CollectableType); //JsonConvert.DeserializeObject<StampBase>(jsonItem);

            Assert.AreEqual(collectable.CollectableType, newCollectable.CollectableType);
            Assert.AreEqual(collectable.AlternateId, newCollectable.AlternateId);
            Assert.AreEqual(collectable.Country, newCollectable.Country);
            Assert.AreEqual(collectable.Description, newCollectable.Description);
            Assert.AreEqual(collectable.DisplayName, newCollectable.DisplayName);
            Assert.AreEqual(collectable.FirstDayOfIssue, newCollectable.FirstDayOfIssue);
            Assert.AreEqual(collectable.IsPostageStamp, newCollectable.IsPostageStamp);
            Assert.AreEqual(collectable.ScottNumber, newCollectable.ScottNumber);
            Assert.AreEqual(collectable.IssueYearStart, newCollectable.IssueYearStart);
        }
Ejemplo n.º 3
0
        public void collectable_serialize_deserialize_book_success()
        {
            BookBase collectable = GetTestBookBase(2);

            collectable.AddItem(GetTestBookItem(0));
            collectable.AddItem(GetTestBookItem(1));

            string   jsonCollectable = JsonConvert.SerializeObject(collectable);
            BookBase newCollectable  = (BookBase)HomeCollectionRepository.GetCollectableFromJson(jsonCollectable, collectable.CollectableType); //JsonConvert.DeserializeObject<BookBase>(jsonCollectable);

            Assert.AreEqual(collectable.CollectableType, newCollectable.CollectableType);
            Assert.AreEqual(collectable.Author, newCollectable.Author);
            Assert.AreEqual(collectable.BookCode, newCollectable.BookCode);
            Assert.AreEqual(collectable.Month, newCollectable.Month);
            Assert.AreEqual(collectable.Description, newCollectable.Description);
            Assert.AreEqual(collectable.DisplayName, newCollectable.DisplayName);
            Assert.AreEqual(collectable.Edition, newCollectable.Edition);
            Assert.AreEqual(collectable.ISBN, newCollectable.ISBN);
            Assert.AreEqual(collectable.Publisher, newCollectable.Publisher);
            Assert.AreEqual(collectable.Series, newCollectable.Series);
            Assert.AreEqual(collectable.Title, newCollectable.Title);
            Assert.AreEqual(collectable.Year, newCollectable.Year);
        }