예제 #1
0
 public static void CleanUpProductTypes(ServiceClientMessageHandler handler, List <int> productTypeIds)
 {
     foreach (var id in productTypeIds)
     {
         ProductTypeFactory.DeleteProductType(handler, id);
     }
 }
예제 #2
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
                }
            }
        }