예제 #1
0
        public void DeleteCategoryTest1()
        {
            //cascadeDelete = null
            var cateObj = Generator.GenerateCategory(Generator.RandomString(5,
                                                                            Generator.RandomCharacterGroup.AlphaOnly));
            var cate4 = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);

            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate4.Id.Value, null, expectedCode: HttpStatusCode.NoContent);
            CategoryFactory.GetCategory(ApiMsgHandler, cate4.Id.Value, expectedCode: HttpStatusCode.NotFound);
            //cascadeDelete = false
            cateObj = Generator.GenerateCategory(Generator.RandomString(5, Generator.RandomCharacterGroup.AlphaOnly));
            var cate1 = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);

            cateIds1.Add(cate1.Id.Value);
            cate4 = CategoryFactory.AddCategory(ApiMsgHandler, Generator.GenerateCategory("cate4"));
            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate4.Id.Value, false, expectedCode: HttpStatusCode.NoContent);
            CategoryFactory.GetCategory(ApiMsgHandler, cate4.Id.Value, expectedCode: HttpStatusCode.NotFound);
            var result = CategoryFactory.GetCategory(ApiMsgHandler, cate1.Id.Value);

            //cascadeDelete = true
            cateObj = Generator.GenerateCategory(Generator.RandomString(5, Generator.RandomCharacterGroup.AlphaOnly));
            var cate2 = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);

            cateIds1.Add(cate2.Id.Value);
            cate4 = CategoryFactory.AddCategory(ApiMsgHandler, Generator.GenerateCategory("cate4"));
            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate4.Id.Value, true, expectedCode: HttpStatusCode.NoContent);
            CategoryFactory.GetCategory(ApiMsgHandler, cate4.Id.Value, expectedCode: HttpStatusCode.NotFound);
            result = CategoryFactory.GetCategory(ApiMsgHandler, cate2.Id.Value);
        }
예제 #2
0
 public static void CleanUpCategories(ServiceClientMessageHandler handler, List <int> CategoryIds)
 {
     foreach (var id in CategoryIds)
     {
         //should return NoContent, bypass for now
         try
         {
             CategoryFactory.DeleteCategoryById(handler: handler, categoryId: id, cascadeDelete: true);
         }
         catch (TestFailException e)  //work around cascade, not found
         {
             // ToDo: e.ActualReturnCode
         }
     }
 }
예제 #3
0
        public void DeleteCategoryTest3()
        {
            var cateObj = Generator.GenerateCategory(Generator.RandomString(5,
                                                                            Generator.RandomCharacterGroup.AlphaOnly));
            var cate4     = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);
            var myPT      = Generator.GenerateBasicProductType(Generator.RandomString(10, Generator.RandomCharacterGroup.AlphaOnly));
            var createdPT = ProductTypeFactory.AddProductType(ApiMsgHandler, myPT);

            productTypeIds.Add(createdPT.Id.Value);
            var product        = Generator.GenerateProduct(createdPT);
            var createdProduct = ProductFactory.AddProduct(ApiMsgHandler, product);

            productCode1.Add(createdProduct.ProductCode);
            var proInfo = Generator.GenerateProductInCatalogInfo(TestBaseTenant.MasterCatalogs.First().Catalogs.First().Id, cate4.Id, true);

            ProductFactory.AddProductInCatalog(ApiMsgHandler, proInfo, createdProduct.ProductCode);
            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate4.Id.Value, false, expectedCode: HttpStatusCode.Conflict);
            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate4.Id.Value, true, expectedCode: HttpStatusCode.NoContent);
            ProductFactory.GetProduct(ApiMsgHandler, product.ProductCode);
        }
예제 #4
0
        //         cate1
        //       /
        //    cate2
        //    /
        //  cate3
        //   /
        //  cate4
        public void DeleteCategoryTest2()
        {
            var cateObj = Generator.GenerateCategory(Generator.RandomString(5,
                                                                            Generator.RandomCharacterGroup.AlphaOnly));
            var cate1 = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);

            cateIds1.Add(cate1.Id.Value);

            cateObj = Generator.GenerateCategory(Generator.RandomString(5,
                                                                        Generator.RandomCharacterGroup.AlphaOnly), parentCategoryId: cate1.Id);
            var cate2 = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);

            //cateIds1.Add(cate2.Id.Value);

            cateObj = Generator.GenerateCategory(Generator.RandomString(5,
                                                                        Generator.RandomCharacterGroup.AlphaOnly), parentCategoryId: cate2.Id);
            var cate3 = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);

            //cateIds1.Add(cate3.Id.Value);

            cateObj = Generator.GenerateCategory(Generator.RandomString(5,
                                                                        Generator.RandomCharacterGroup.AlphaOnly), parentCategoryId: cate3.Id);
            var cate4 = CategoryFactory.AddCategory(ApiMsgHandler, cateObj);

            //cateIds1.Add(cate4.Id.Value);

            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate2.Id.Value, false, expectedCode: HttpStatusCode.Conflict);
            CategoryFactory.DeleteCategoryById(ApiMsgHandler, cate2.Id.Value, true, expectedCode: HttpStatusCode.NoContent);

            //its parent should not change
            var getCate = CategoryFactory.GetCategory(ApiMsgHandler, cate1.Id.Value);

            Assert.AreEqual(0, getCate.ChildCount);

            // verify its sons
            CategoryFactory.GetCategory(ApiMsgHandler, cate3.Id.Value, expectedCode: HttpStatusCode.NotFound);

            // verify its grandsons
            CategoryFactory.GetCategory(ApiMsgHandler, cate4.Id.Value, expectedCode: HttpStatusCode.NotFound);
        }
예제 #5
0
        /// <summary>
        /// clean up products, attributes, productypes and categories since provisioning the tenant
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="masterCatalogId"></param>
        /// <param name="siteId"></param>
        public static void CleanUpProducts(int tenantId, int masterCatalogId, int?catalogId = null, int?siteId = null)
        {
            var tenant            = TenantFactory.GetTenant(ServiceClientMessageFactory.GetTestClientMessage(), tenantId);
            var ApiMessageHandler = ServiceClientMessageFactory.GetTestClientMessage(tenantId: tenantId, masterCatalogId: masterCatalogId, catalogId: catalogId, siteId: siteId);
            var products          = ProductFactory.GetProducts(ApiMessageHandler, noCount: null, pageSize: null, q: null, qLimit: null, sortBy: null, startIndex: null, filter: "createdate gt " + SinceWhen(DateTime.Now.AddDays(-1)));

            foreach (var pro in products.Items)
            {
                ProductFactory.DeleteProduct(ApiMessageHandler, pro.ProductCode);
            }
            var productTypes = ProductTypeFactory.GetProductTypes(handler: ApiMessageHandler, successCode: HttpStatusCode.OK, expectedCode: HttpStatusCode.OK);

            foreach (var pt in productTypes.Items)
            {
                if (pt.AuditInfo.CreateDate.Value > DateTime.Now.AddDays(-1))
                {
                    try
                    {
                        ProductTypeFactory.DeleteProductType(ApiMessageHandler, pt.Id.Value);
                    }
                    catch (TestFailException e)   //getaround base product type
                    {
                        // ToDo: e.ActualReturnCode
                    }
                }
            }
            var attributes = AttributeFactory.GetAttributes(handler: ApiMessageHandler, successCode: HttpStatusCode.OK, expectedCode: HttpStatusCode.OK);

            if (attributes.TotalCount != 0)
            {
                foreach (var attr in attributes.Items)
                {
                    if (attr.AuditInfo.CreateDate.Value > DateTime.Now.AddDays(-1))
                    {
                        //bug 18745, should return NoContent
                        try
                        {
                            AttributeFactory.DeleteAttribute(ApiMessageHandler, attr.AttributeFQN);
                        }
                        catch (TestFailException e)  //get around the bug
                        {
                            // ToDo: e.ActualReturnCode
                        }
                    }
                }
            }
            var cates = CategoryFactory.GetCategories(ApiMessageHandler, pageSize: null, sortBy: null, startIndex: null, filter: "createdate gt " + SinceWhen(DateTime.Now.AddDays(-1)));

            foreach (var cate in cates.Items)
            {
                var messageHandler1 = ServiceClientMessageFactory.GetTestClientMessage(tenantId: tenantId, masterCatalogId: masterCatalogId, catalogId: catalogId, siteId: siteId);
                try
                {
                    CategoryFactory.DeleteCategoryById(handler: messageHandler1, categoryId: (int)cate.Id, cascadeDelete: true);
                }
                catch (TestFailException e)   //work around notfound
                {
                    // ToDo: e.ActualReturnCode
                }
            }
        }