Ejemplo n.º 1
0
        public void CreateCollections()
        {
            int COUNT = 20;

            CatfishDbContext    db = new CatfishDbContext();
            List <CFEntityType> collectionTypes = db.EntityTypes.Where(t => t.TargetTypes.Contains(CFEntityType.eTarget.Collections.ToString())).ToList();//db.EntityTypes.Where(t => t.TargetType == EntityType.eTarget.Collections).ToList();

            if (collectionTypes.Count == 0)
            {
                throw new Exception("No entity types have been defined for collections.");
            }
            var rand = new Random();
            CollectionService srv = new CollectionService(db);

            for (int i = 0; i < COUNT; ++i)
            {
                CFEntityType cType = collectionTypes[rand.Next(0, collectionTypes.Count)];
                CFCollection c     = srv.CreateEntity <CFCollection>(cType.Id);
                string       name  = TestData.LoremIpsum(5, 10);
                c.SetName("Collection: " + name);
                c.SetDescription(TestData.LoremIpsum(20, 100, 1, 10));
                c.Serialize();
                db.Collections.Add(c);
            }
            db.SaveChanges();
        }