public void gettypefromfriendlyname_returns_collectable_type_successfully() { string friendlyName = null; foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { switch (collectableType.Name) { case "BookBase": friendlyName = "Book"; break; case "StampBase": friendlyName = "Stamp"; break; default: friendlyName = ""; break; } Type friendlyType = CollectableBaseFactory.GetTypeFromFriendlyName(friendlyName); Assert.AreEqual(collectableType, friendlyType); } }
public void create_new_book_from_factory_datepublished_defaults_to_min_date() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); Assert.AreEqual(0, book.Year); Assert.AreEqual(0, book.Month); }
internal static ICollectionBase ConvertJsonToCollection(string jsonCollection) { string collectionTypeName = null; try { dynamic collection = JsonConvert.DeserializeObject(jsonCollection); // This is not working as expected when it has child members //ICollectionBase collection = JsonConvert.DeserializeObject<HomeCollection>(jsonCollection); string collectionName = collection.CollectionName; collectionTypeName = collection.CollectionType; Type collectionType = CollectableBaseFactory.GetTypeFromFullName(collectionTypeName); ICollectionBase newCollection = new HomeCollection(collectionName, collectionType); var collectables = collection.Collectables; foreach (var c in collectables) { string jsonCollectable = c.ToString(); // add custom try/catch?? ICollectableBase collectable = GetCollectableFromJson(jsonCollectable, collectionType); newCollection.AddToCollection(collectable); } return(newCollection); } catch (Exception ex) { throw new CollectionParseException($"Unable to parse Json into a collection object. Type={collectionTypeName}, Json={jsonCollection}", ex); } }
public void getfriendlynamefromtype_returns_collectable_type_successfully() { foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { //string expectedName = collectableType.Name.Replace("Base", ""); string expectedFriendlyName = null; switch (collectableType.Name) { case "BookBase": expectedFriendlyName = "Book"; break; case "StampBase": expectedFriendlyName = "Stamp"; break; default: expectedFriendlyName = ""; break; } string friendlyName = CollectableBaseFactory.GetFriendlyNameFromType(collectableType); Assert.AreEqual(expectedFriendlyName, friendlyName); } }
public void display_name_initialized_to_default_value() { string expectedValue = BookBase.DISPLAYNAME_DEFAULT; BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); Assert.AreEqual(expectedValue, book.DisplayName); }
public void gettypefromfullname_blank_name_throws_exception() { string invalidName = ""; Type collectionType = CollectableBaseFactory.GetTypeFromFullName(invalidName); Assert.Fail("Expected GetTypeFromFullName to fail when unable to parse type from name"); }
public void createandaddcollectableitem_null_collectable_throws_exception() { ICollectableBase nullCollectable = null; CollectableBaseFactory.CreateAndAddCollectableItem(nullCollectable); Assert.Fail("Expected CreateAndAddCollectableItem to fail when passed a null collectable"); }
public void iswatermarked_initialized_to_default_value() { bool expectedValue = false; StampBase stamp = (StampBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.StampType); Assert.AreEqual(expectedValue, stamp.IsWatermarked); }
public void country_name_initialized_to_default_value() { string expectedValue = StampBase.COUNTRY_DEFAULT; StampBase stamp = (StampBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.StampType); Assert.AreEqual(expectedValue, stamp.Country); }
public void book_year_cannot_be_set_to_negative() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.Year = -100; Assert.IsFalse(true, "Expected an exception to be thrown if a negative year is set"); }
public void create_new_collectable_from_interface_type_throws_exception() { Type invalidType = typeof(IStampBase); ICollectableBase newItem = CollectableBaseFactory.CreateCollectableBase(invalidType); Assert.IsFalse(true, "Expected test to fail if passed an interface instead of valid collectable base type"); }
public void create_new_factory_instance_from_valid_collectable_base_name_case_insensitive_succeeds() { string validTypeName = "BOOkBaSe"; // implements ICollectableBase ICollectableBase newItem = CollectableBaseFactory.CreateCollectableBase(validTypeName); Assert.AreEqual(validTypeName.ToUpper(), newItem.CollectableType.Name.ToUpper(), "Expected to get instance of a book base type"); }
public void create_new_stamp_from_factory_isPostageStamp_defaults_to_true() { Type stampType = CollectableBaseFactory.StampType; StampBase newStamp = (StampBase)CollectableBaseFactory.CreateCollectableBase(stampType); Assert.IsTrue(newStamp.IsPostageStamp); }
public void create_new_stamp_from_factory_country_set_to_country_default() { Type stampType = CollectableBaseFactory.StampType; StampBase newStamp = (StampBase)CollectableBaseFactory.CreateCollectableBase(stampType); Assert.IsTrue(newStamp.Country == StampBase.COUNTRY_DEFAULT); }
public void create_new_stamp_from_factory_returns_stampbase_type() { Type stampType = CollectableBaseFactory.StampType; ICollectableBase newStamp = CollectableBaseFactory.CreateCollectableBase(stampType); Assert.IsTrue(stampType == newStamp.CollectableType); }
public void gettypefromfriendlyname_null_name_throws_exceptions() { string friendlyName = null; Type CollectableType = CollectableBaseFactory.GetTypeFromFriendlyName(friendlyName); Assert.Fail("Exception should have been thrown"); }
public void create_new_collectable_from_interface_type_string_throws_exception() { string validTypeName = "ICollectableBase"; ICollectableBase newItem = CollectableBaseFactory.CreateCollectableBase(validTypeName); Assert.IsFalse(true, "Expected test to fail if passed an interface type name"); }
public void iscollectabletype_null_type_returns_false() { Type invalidType = null; bool isCollectable = CollectableBaseFactory.IsCollectableType(invalidType); Assert.IsFalse(isCollectable, "Expected to return false if passed a null type"); }
public void book_year_can_be_set_to_zero_successfully() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.Year = 0; Assert.AreEqual(0, book.Year); }
public void create_new_collectable_from_empty_string_throws_exception() { string invalidTypeName = ""; ICollectableBase newItem = CollectableBaseFactory.CreateCollectableBase(invalidTypeName); Assert.IsFalse(true, "Expected test to fail if passed a null type"); }
public void create_new_collectable_from_null_type_throws_exception() { Type invalidType = null; ICollectableBase newItem = CollectableBaseFactory.CreateCollectableBase(invalidType); Assert.IsFalse(true, "Expected test to fail if passed a null type"); }
public void display_name_initialized_to_default_value() { string expectedValue = StampBase.DISPLAYNAME_DEFAULT; StampBase stamp = (StampBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.StampType); Assert.AreEqual(expectedValue, stamp.DisplayName); }
public void iscollectabletype_interface_type_returns_false() { Type invalidType = typeof(ICollectableBase); bool isCollectable = CollectableBaseFactory.IsCollectableType(invalidType); Assert.IsFalse(isCollectable, "Expected to return false if passed the ICollectable interface type"); }
public void ispostagestamp_initialized_to_default_value() { bool expectedValue = true; StampBase stamp = (StampBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.StampType); Assert.AreEqual(expectedValue, stamp.IsPostageStamp); }
public void createcollectableitem_invalid_type_throws_exception() { Type collectableType = typeof(double); CollectableBaseFactory.CreateCollectableItem(collectableType); Assert.Fail("Expected CreateCollectableItem to fail when passed an invalid collectable type"); }
public void getfriendlynamefromtype_null_type_throws_exceptions() { Type collectableType = null; string friendlyName = CollectableBaseFactory.GetFriendlyNameFromType(collectableType); Assert.Fail("Exception should have been thrown"); }
public void display_name_cannot_be_set_to_blank_string() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); book.DisplayName = ""; Assert.IsFalse(true, "Expected an exception to be thrown if a blank display name is set"); }
public void create_new_book_from_factory_getitems_does_not_return_null_list() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); IList <ICollectableItem> bookItems = book.ItemInstances; Assert.IsNotNull(bookItems); }
public void create_new_book_from_factory_getitems_defaults_to_zero_items_in_list() { BookBase book = (BookBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.BookType); IList <ICollectableItem> bookItems = book.ItemInstances; Assert.AreEqual(0, bookItems.Count); }
public void issueyearend_set_to_nonnegative_succeeds() { int validEnd = 2005; StampBase stamp = (StampBase)CollectableBaseFactory.CreateCollectableBase(CollectableBaseFactory.StampType); stamp.IssueYearEnd = validEnd; Assert.AreEqual(validEnd, stamp.IssueYearEnd); }