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); } }
// 如需統合的詳細資訊,請瀏覽 https://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) { //bundles.Add(new ScriptBundle("~/bundles/jquery").Include( // "~/Scripts/jquery-{version}.js")); // 使用開發版本的 Modernizr 進行開發並學習。然後,當您 // 準備好可進行生產時,請使用 https://modernizr.com 的建置工具,只挑選您需要的測試。 //bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( // "~/Scripts/modernizr-*")); //bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( // "~/Scripts/bootstrap.js")); //bundles.Add(new StyleBundle("~/Content/css").Include( // "~/Content/bootstrap.css", // "~/Content/site.css")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/jquery.validate*")); //首頁 JS & CSS HomeCollection.Initial(bundles); //BackEndSystem JS & CSS設定檔 BackEndSystemCollection.Initial(bundles); //原始 MiniShop & ElaAdmin JS CSS SampleCollection.Initial(bundles); //壓縮 //BundleTable.EnableOptimizations = true; }
private ICollectionBase GetTestCollection(string collectionName, Type collectableType, int numberOfCollectables, int numberOfItemsPerCollectable = 0) { ICollectableBase collectable = null; ICollectableItem item = null; Type collectionType = collectableType; ICollectionBase testCollection = new HomeCollection(collectionName, collectionType); for (int i = 0; i < numberOfCollectables; i++) { if (collectionType == CollectableBaseFactory.BookType) { collectable = GetTestBookBase(i); } else if (collectionType == CollectableBaseFactory.StampType) { collectable = GetTestStampBase(i); } testCollection.AddToCollection(collectable); for (int j = 0; j < numberOfItemsPerCollectable; j++) { if (collectionType == CollectableBaseFactory.BookType) { item = GetTestBookItem(i); } else if (collectionType == CollectableBaseFactory.StampType) { item = GetTestStampItem(i); } collectable.AddItem(item); } } return(testCollection); }
public void initialize_collection_invalid_collectiontype_throws_exception() { Type invalidCollectionType = typeof(Int64); // anything that is not ICollectableBase ICollectionBase testCollection = new HomeCollection("initial", invalidCollectionType); Assert.IsFalse(true, "Expected collection initialization to fail with invalid collection type"); }
public void initialize_collection_with_empty_collectionname_throws_exception() { string collectionName = ""; ICollectionBase testCollection = new HomeCollection(collectionName, CollectableBaseFactory.CollectableTypes[0]); Assert.IsFalse(true, "Expected collection initialization to fail with empty collection name"); }
public void initialize_collection_with_null_collectiontype_throws_exception() { Type collectionType = null; ICollectionBase testCollection = new HomeCollection("initial", collectionType); Assert.IsFalse(true, "Expected collection initialization to fail with null collection type"); }
public void add_invalid_type_to_book_collection_throws_exception() { ICollectionBase bookCollection = new HomeCollection("initial", CollectableBaseFactory.CollectableTypes[0]); bookCollection.AddToCollection(new StampBase()); Assert.IsFalse(true, "Expected that an exception is thrown when an invalid type is added to the collection"); }
public void initialize_collection_sets_name_property_successfully() { string collectionName = "Test Collection"; ICollectionBase testCollection = new HomeCollection(collectionName, CollectableBaseFactory.CollectableTypes[0]); Assert.AreEqual(collectionName, testCollection.CollectionName); }
public void initialize_collection_sets_collectiontype_successfully() { foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { ICollectionBase testCollection = new HomeCollection("initial", collectableType); Assert.AreEqual(collectableType, testCollection.CollectionType); } }
public void set_collectionname_with_null_throws_exception() { ICollectionBase testCollection = new HomeCollection("initial", CollectableBaseFactory.CollectableTypes[0]); string nullCollectionName = null; testCollection.CollectionName = nullCollectionName; Assert.IsFalse(true, "Expected set collectionname to fail with null value"); }
public void get_collectiontype_returns_initialized_type() { foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { ICollectionBase collection = new HomeCollection("initial", collectableType); Assert.AreEqual(collectableType, collection.CollectionType); } }
public void add_null_collectable_to_collection_throws_exception() { ICollectionBase testCollection = new HomeCollection("initial", CollectableBaseFactory.CollectableTypes[0]); ICollectableBase nullCollectable = null; testCollection.AddToCollection(nullCollectable); Assert.IsFalse(true, "Expected that an exception is thrown when a null value is added to the collection"); }
public void add_valid_type_to_collection_succeeds() { foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { ICollectionBase collection = new HomeCollection("initial", collectableType); ICollectableBase collectable = GetMockCollectableObject(collectableType); collection.AddToCollection(collectable); Assert.AreEqual(1, collection.Collectables.Count); } }
public void convertcollectiontojson_serializes_new_collection_successfully() { string collectionName = "test"; Type collectableType = CollectableBaseFactory.CollectableTypes[0]; ICollectionBase collection = new HomeCollection(collectionName, collectableType); string expected = @"{""CollectionName"":""test"",""CollectionType"":""HomeCollector.Models.BookBase, HomeCollector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"",""Collectables"":[]}"; string json = HomeCollectionRepository.ConvertCollectionToJson(collection); // This is a very fragile test. Should look for expected tokens instead. Assert.AreEqual(expected, json); }
public void gettypefromfullname_returns_collectable_type_successfully() { foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { ICollectionBase collection = new HomeCollection("name", collectableType); string fullName = collection.CollectionType.FullName; Type collectionType = CollectableBaseFactory.GetTypeFromFullName(fullName); Assert.AreEqual(collectableType, collectionType); } }
public void collectionname_returns_set_value() { foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { ICollectionBase testCollection = new HomeCollection("initial", collectableType); string validCollectionName = "Test Collection"; testCollection.CollectionName = validCollectionName; Assert.AreEqual(validCollectionName, testCollection.CollectionName); } }
private ICollectionBase GetMockCollection(int N, Type collectableType) { Type collectionType = collectableType; ICollectionBase testCollection = new HomeCollection("initial", collectionType); for (int i = 0; i < N; i++) { ICollectableBase collectable = GetMockCollectableObject(collectableType); testCollection.AddToCollection(collectable); } return(testCollection); }
public WorkSpaceViewModel() { if (CurrentUserID.ProjectID != default(int)) { DBRepository <UserProject> dBProject = new DBRepository <UserProject>(new BuildEntities()); CurrentProject = dBProject.GetAll().Where(s => s.ID == CurrentUserID.ProjectID).First(); CurrentUserID.ProjectID = default(int); DBRepository <WorkField> dBWorkField = new DBRepository <WorkField>(new BuildEntities()); DBRepository <Elements> dbElement = new DBRepository <Elements>(new BuildEntities()); foreach (var item in dBWorkField.GetAll().Where(s => s.ID_UP == CurrentProject.ID)) { try { HomeCollection.Add(new HomeElements(item, dbElement.GetAll().Where(s => s.ID == item.Element_ID).First())); TotalPrice = (Convert.ToDecimal(TotalPrice) + (decimal)item.Elements.Price).ToString(); } catch { } } dBProject.Dispose(); dBWorkField.Dispose(); dbElement.Dispose(); } BackHistory.History.Push(HomeCollection.ToList()); var windows = Application.Current.Windows; if (windows.Count > 1) { try { Window window = null; foreach (var item in windows) { if (item as Loading != null) { window = (item as Loading); } } window.Close(); } catch { } } }
public void add_invalid_type_to_collection_throws_exception() { bool threwException = false; foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { threwException = false; ICollectionBase collection = new HomeCollection("initial", collectableType); ICollectableBase collectable = GetDifferentTypeMockCollectable(collectableType).Object; //CollectableBaseFactory.CreateCollectableBase(collectableType); try { collection.AddToCollection(collectable); } catch (CollectionException) { threwException = true; } Assert.IsTrue(threwException, "Expected that an exception is thrown when an invalid type is added to the collection"); } }
public void getcollection_returns_all_collectables_added_to_collection() { int N = 3; foreach (Type collectableType in CollectableBaseFactory.CollectableTypes) { Type collectionType = collectableType; IList <ICollectableBase> collectables = new List <ICollectableBase>(); ICollectionBase testCollection = new HomeCollection("initial", collectionType); for (int i = 0; i < N; i++) { ICollectableBase collectable = GetMockCollectableObject(collectionType); collectables.Add(collectable); testCollection.AddToCollection(collectable); } for (int i = 0; i < N; i++) { Assert.AreEqual(collectables[i], testCollection.Collectables[i]); } } }
private void DropSelectedIcon() { if (currentElement != null || ChangeWorkField != null) { DBRepository <Elements> dBRepository = new DBRepository <Elements>(new BuildEntities()); try { if (Choose && !Change) { int x = (int)CursorPoint.X - (int)CurrentElement.Size / 2; int y = (int)CursorPoint.Y; WorkField workField = new WorkField { Element_ID = CurrentElement.ID, Rotate = 0, PositionX = x, PositionY = y }; if (CurrentProject != null) { workField.ID_UP = CurrentProject.ID; } HomeCollection.Add(new HomeElements(workField, dBRepository.GetAll().Where(s => s.ID == CurrentElement.ID).First())); Choose = false; Change = false; ChangeWorkField = null; TotalPrice = (Convert.ToDecimal(TotalPrice) + (decimal)CurrentElement.Price).ToString(); BackHistory.History.Push(HomeCollection.ToList()); if (BackHistory.History.Count() > 30) { BuildHistory helpstack = new BuildHistory(); foreach (var item in BackHistory.History) { if (helpstack.History.Count < 30) { helpstack.History.Push(item); } } BackHistory.History.Clear(); foreach (var item in helpstack.History) { BackHistory.History.Push(item); } } } else if (Choose && Change) { HomeCollection.Remove(ChangeWorkField); int x = (int)CursorPoint.X - (int)ChangeWorkField.Element.Size / 2; int y = (int)CursorPoint.Y; ChangeWorkField.Field.PositionX = x; ChangeWorkField.Field.PositionY = y; HomeCollection.Add(ChangeWorkField); Choose = false; Change = false; ChangeWorkField = null; } } catch { } dBRepository.Dispose(); } }