public void Can_delete_category_with_cascade()
        {
            var repository = GetRepository();

            var          items     = new Item[] { };
            const string catalogId = "testCatalog";

            CreateFullGraphCatalog(repository, ref items, catalogId);

            var allCategories = repository.Categories
                                .Where(x => x.CatalogId == catalogId && x.ParentCategoryId == null)
                                .ToList();
            var innerItem = allCategories.FirstOrDefault();

            // create a sub category
            var subcategory = new Category
            {
                Code             = "a-code",
                Name             = "categoryName",
                StartDate        = DateTime.Today,
                CatalogId        = catalogId,
                ParentCategoryId = innerItem.CategoryId
            };

            repository.Add(subcategory);

            var linkedCategory = new LinkedCategory
            {
                Code             = "l-code",
                CatalogId        = catalogId,
                LinkedCatalogId  = catalogId,
                LinkedCategoryId = innerItem.CategoryId
            };

            repository.Add(linkedCategory);
            repository.UnitOfWork.Commit();

            RefreshRepository(ref repository);

            var categoryRemove = repository.Categories.Where(x => x.CategoryId == innerItem.CategoryId).FirstOrDefault();

            repository.Remove(categoryRemove);
            repository.UnitOfWork.Commit();


            // Assert passed.
        }
Esempio n. 2
0
        protected override OpResult _Store(LinkedCategory _obj)
        {
            if (_obj == null)
            {
                return(OpResult.NotifyStoreAction(OpResult.ResultStatus.ObjectIsNull, _obj, "LinkedCategory object cannot be created as it is null"));
            }

            if (Exists(_obj))
            {
                ExecuteNonQuery(GetQuery_UpdateQuery(_obj));
                return(OpResult.NotifyStoreAction(OpResult.ResultStatus.Updated, _obj));
            }

            ExecuteNonQuery(GetQuery_InsertQuery(_obj));
            _obj.FromDb = true;

            return(OpResult.NotifyStoreAction(OpResult.ResultStatus.Created, _obj));
        }
Esempio n. 3
0
 private DbUpdateStatement GetQuery_UpdateQuery(LinkedCategory _obj)
 {
     return(DbMgr.CreateUpdateClause("LinkedCategories", GetFields(_obj), "LinkedCategoryID", _obj.LinkedCategoryID));
 }
Esempio n. 4
0
        private DbInsertStatement GetQuery_InsertQuery(LinkedCategory _obj)
        {
            Dictionary <string, DbFieldEntry> fields = GetFields(_obj);

            return(DbMgr.CreateInsertClause("LinkedCategories", fields));
        }