public void DeleteItemCategoryByParentId(string categoryId)
 {
     ItemCategory category = new ItemCategory();
     ItemCategoryManager manager = new ItemCategoryManager();
     string sqlDelete = manager.GetDeleteSql(category);
     sqlDelete += string.Format("WHERE [ParentId] = N'{0}'", categoryId);
     using (DbOperator dbOperator = new DbOperator(ConnString))
     {
         dbOperator.ExecSql(sqlDelete);
     }
 }
        public void DeleteItemCategoryByParentId(string categoryId)
        {
            ItemCategory        category = new ItemCategory();
            ItemCategoryManager manager  = new ItemCategoryManager();
            string sqlDelete             = manager.GetDeleteSql(category);

            sqlDelete += string.Format("WHERE [ParentId] = N'{0}'", categoryId);
            using (DbOperator dbOperator = new DbOperator(ConnString))
            {
                dbOperator.ExecSql(sqlDelete);
            }
        }
        public string AddItemCategory(string id, string categoryId, string parentId, string name, bool isParent, string status, int sortOrder)
        {
            #region 构造要新增的对象

            if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString())
            {
                id = Guid.NewGuid().ToString();
            }

            ItemCategory category = new ItemCategory();
            category.Id = id;
            category.CategoryId = categoryId;
            category.ParentId = parentId;
            category.Name = name;
            category.IsParent = isParent;
            category.Status = status;
            category.SortOrder = sortOrder;

            #endregion

            #region 执行SQL以创建对象

            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(ConnString))
            {
                try
                {
                    dbOperator.BeginTran();
                    dbOperator.ExecSql(sqlCreate);
                    dbOperator.CommintTran();

                    return id;
                }
                catch (Exception ex)
                {
                    dbOperator.RollbackTran();
                    throw new FacadeException("新增类目发生异常 - ", ex);
                }
            }

            #endregion
        }
        public string AddItemCategory(string id, string categoryId, string parentId, string name, bool isParent, string status, int sortOrder)
        {
            #region 构造要新增的对象

            if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString())
            {
                id = Guid.NewGuid().ToString();
            }

            ItemCategory category = new ItemCategory();
            category.Id         = id;
            category.CategoryId = categoryId;
            category.ParentId   = parentId;
            category.Name       = name;
            category.IsParent   = isParent;
            category.Status     = status;
            category.SortOrder  = sortOrder;

            #endregion

            #region 执行SQL以创建对象

            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate            = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(ConnString))
            {
                try
                {
                    dbOperator.BeginTran();
                    dbOperator.ExecSql(sqlCreate);
                    dbOperator.CommintTran();

                    return(id);
                }
                catch (Exception ex)
                {
                    dbOperator.RollbackTran();
                    throw new FacadeException("新增类目发生异常 - ", ex);
                }
            }

            #endregion
        }
        public void TestIsItemCategoryExist_已经存在的情况()
        {
            #region 验证前置条件

            ItemCategory category = new ItemCategory();
            category.Id         = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category.CategoryId = "50011665";
            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate            = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate);
            }

            #endregion

            ItemCategoryFacade facade = new ItemCategoryFacade();
            bool isExist = facade.IsItemCategoryExist("50011665");

            Assert.AreEqual(true, isExist);
        }
        public void TestGetItemCategoryListByParent_有一条根数据()
        {
            #region 验证前置条件

            ItemCategory category = new ItemCategory();
            category.Id         = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category.CategoryId = "50011665";
            category.Name       = "测试类目";
            category.ParentId   = "0";
            category.IsParent   = true;
            category.SortOrder  = 1;
            category.Status     = "normal";
            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate            = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate);
            }

            #endregion

            ItemCategoryFacade      facade = new ItemCategoryFacade();
            List <ItemCategoryInfo> list   = facade.GetItemCategoryListByParent(string.Empty);

            #region 验证后置条件

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", list[0].Id);
            Assert.AreEqual("50011665", list[0].CategoryId);
            Assert.AreEqual("测试类目", list[0].Name);
            Assert.AreEqual("0", list[0].ParentId);
            Assert.AreEqual(true, list[0].IsParent);
            Assert.AreEqual(1, list[0].SortOrder);
            Assert.AreEqual("normal", list[0].Status);

            #endregion
        }
        public void TestGetItemCategory_已经存在的情况()
        {
            #region 验证前置条件

            ItemCategory category = new ItemCategory();
            category.Id         = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category.CategoryId = "50011665";
            category.Name       = "测试类目";
            category.ParentId   = "0";
            category.IsParent   = true;
            category.SortOrder  = 1;
            category.Status     = "normal";
            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate            = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate);
            }

            #endregion

            ItemCategoryFacade facade       = new ItemCategoryFacade();
            ItemCategoryInfo   categoryInfo = facade.GetItemCategoryById("50011665");

            #region 验证后置条件

            Assert.IsNotNull(categoryInfo);
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", categoryInfo.Id);
            Assert.AreEqual("50011665", categoryInfo.CategoryId);
            Assert.AreEqual("测试类目", categoryInfo.Name);
            Assert.AreEqual("0", categoryInfo.ParentId);
            Assert.AreEqual(true, categoryInfo.IsParent);
            Assert.AreEqual(1, categoryInfo.SortOrder);
            Assert.AreEqual("normal", categoryInfo.Status);

            #endregion
        }
        public void TestIsItemCategoryExist_已经存在的情况()
        {
            #region 验证前置条件

            ItemCategory category = new ItemCategory();
            category.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category.CategoryId = "50011665";
            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate);
            }

            #endregion

            ItemCategoryFacade facade = new ItemCategoryFacade();
            bool isExist = facade.IsItemCategoryExist("50011665");

            Assert.AreEqual(true, isExist);
        }
        public void TestGetItemCategory_已经存在的情况()
        {
            #region 验证前置条件

            ItemCategory category = new ItemCategory();
            category.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category.CategoryId = "50011665";
            category.Name = "测试类目";
            category.ParentId = "0";
            category.IsParent = true;
            category.SortOrder = 1;
            category.Status = "normal";
            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate);
            }

            #endregion

            ItemCategoryFacade facade = new ItemCategoryFacade();
            ItemCategoryInfo categoryInfo = facade.GetItemCategoryById("50011665");

            #region 验证后置条件

            Assert.IsNotNull(categoryInfo);
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", categoryInfo.Id);
            Assert.AreEqual("50011665", categoryInfo.CategoryId);
            Assert.AreEqual("测试类目", categoryInfo.Name);
            Assert.AreEqual("0", categoryInfo.ParentId);
            Assert.AreEqual(true, categoryInfo.IsParent);
            Assert.AreEqual(1, categoryInfo.SortOrder);
            Assert.AreEqual("normal", categoryInfo.Status);

            #endregion
        }
        public void TestGetItemCategoryListByParent_父子数据情况()
        {
            #region 验证前置条件

            ItemCategory category1 = new ItemCategory();
            category1.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category1.CategoryId = "50011665";
            category1.Name = "测试类目1";
            category1.ParentId = "0";
            category1.IsParent = true;
            category1.SortOrder = 1;
            category1.Status = "normal";

            ItemCategory category2 = new ItemCategory();
            category2.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53929";
            category2.CategoryId = "50011667";
            category2.Name = "测试类目2";
            category2.ParentId = "50011665";
            category2.IsParent = true;
            category2.SortOrder = 0;
            category2.Status = "deleted";

            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate1 = manager.GetCreateSql(category1);
            string sqlCreate2 = manager.GetCreateSql(category2);

            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate1);
                dbOperator.ExecSql(sqlCreate2);
            }

            #endregion

            ItemCategoryFacade facade = new ItemCategoryFacade();

            #region 验证后置条件

            List<ItemCategoryInfo> list1 = facade.GetItemCategoryListByParent(string.Empty);

            Assert.AreEqual(1, list1.Count);
            ItemCategoryInfo categoryInfo1 = list1[0];
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", categoryInfo1.Id);
            Assert.AreEqual("50011665", categoryInfo1.CategoryId);
            Assert.AreEqual("测试类目1", categoryInfo1.Name);
            Assert.AreEqual("0", categoryInfo1.ParentId);
            Assert.AreEqual(true, categoryInfo1.IsParent);
            Assert.AreEqual(1, categoryInfo1.SortOrder);
            Assert.AreEqual("normal", categoryInfo1.Status);

            List<ItemCategoryInfo> list2 = facade.GetItemCategoryListByParent("50011665");

            ItemCategoryInfo categoryInfo2 = list2[0];
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53929", categoryInfo2.Id);
            Assert.AreEqual("50011667", categoryInfo2.CategoryId);
            Assert.AreEqual("测试类目2", categoryInfo2.Name);
            Assert.AreEqual("50011665", categoryInfo2.ParentId);
            Assert.AreEqual(true, categoryInfo2.IsParent);
            Assert.AreEqual(0, categoryInfo2.SortOrder);
            Assert.AreEqual("deleted", categoryInfo2.Status);

            #endregion
        }
        public void TestGetItemCategoryListByParent_有一条根数据()
        {
            #region 验证前置条件

            ItemCategory category = new ItemCategory();
            category.Id = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category.CategoryId = "50011665";
            category.Name = "测试类目";
            category.ParentId = "0";
            category.IsParent = true;
            category.SortOrder = 1;
            category.Status = "normal";
            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate = manager.GetCreateSql(category);
            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate);
            }

            #endregion

            ItemCategoryFacade facade = new ItemCategoryFacade();
            List<ItemCategoryInfo> list = facade.GetItemCategoryListByParent(string.Empty);

            #region 验证后置条件

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", list[0].Id);
            Assert.AreEqual("50011665", list[0].CategoryId);
            Assert.AreEqual("测试类目", list[0].Name);
            Assert.AreEqual("0", list[0].ParentId);
            Assert.AreEqual(true, list[0].IsParent);
            Assert.AreEqual(1, list[0].SortOrder);
            Assert.AreEqual("normal", list[0].Status);

            #endregion
        }
 public void TestSetup()
 {
     _itemCategoryAccessor = new FakeItemCategoryAccessor();
     _itemCategoryManager  = new ItemCategoryManager(_itemCategoryAccessor);
 }
 public void TestTearDown()
 {
     _itemCategory         = null;
     _itemCategoryAccessor = null;
     _itemCategoryManager  = null;
 }
        public void TestGetItemCategoryListByParent_父子数据情况()
        {
            #region 验证前置条件

            ItemCategory category1 = new ItemCategory();
            category1.Id         = "c2ecf0ef-dc5b-4308-9f38-047453d53919";
            category1.CategoryId = "50011665";
            category1.Name       = "测试类目1";
            category1.ParentId   = "0";
            category1.IsParent   = true;
            category1.SortOrder  = 1;
            category1.Status     = "normal";

            ItemCategory category2 = new ItemCategory();
            category2.Id         = "c2ecf0ef-dc5b-4308-9f38-047453d53929";
            category2.CategoryId = "50011667";
            category2.Name       = "测试类目2";
            category2.ParentId   = "50011665";
            category2.IsParent   = true;
            category2.SortOrder  = 0;
            category2.Status     = "deleted";

            ItemCategoryManager manager = new ItemCategoryManager();
            string sqlCreate1           = manager.GetCreateSql(category1);
            string sqlCreate2           = manager.GetCreateSql(category2);

            using (DbOperator dbOperator = new DbOperator(connString))
            {
                dbOperator.ExecSql(sqlCreate1);
                dbOperator.ExecSql(sqlCreate2);
            }

            #endregion

            ItemCategoryFacade facade = new ItemCategoryFacade();

            #region 验证后置条件

            List <ItemCategoryInfo> list1 = facade.GetItemCategoryListByParent(string.Empty);

            Assert.AreEqual(1, list1.Count);
            ItemCategoryInfo categoryInfo1 = list1[0];
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53919", categoryInfo1.Id);
            Assert.AreEqual("50011665", categoryInfo1.CategoryId);
            Assert.AreEqual("测试类目1", categoryInfo1.Name);
            Assert.AreEqual("0", categoryInfo1.ParentId);
            Assert.AreEqual(true, categoryInfo1.IsParent);
            Assert.AreEqual(1, categoryInfo1.SortOrder);
            Assert.AreEqual("normal", categoryInfo1.Status);

            List <ItemCategoryInfo> list2 = facade.GetItemCategoryListByParent("50011665");

            ItemCategoryInfo categoryInfo2 = list2[0];
            Assert.AreEqual("c2ecf0ef-dc5b-4308-9f38-047453d53929", categoryInfo2.Id);
            Assert.AreEqual("50011667", categoryInfo2.CategoryId);
            Assert.AreEqual("测试类目2", categoryInfo2.Name);
            Assert.AreEqual("50011665", categoryInfo2.ParentId);
            Assert.AreEqual(true, categoryInfo2.IsParent);
            Assert.AreEqual(0, categoryInfo2.SortOrder);
            Assert.AreEqual("deleted", categoryInfo2.Status);

            #endregion
        }