Ejemplo n.º 1
0
        private void AddChild(AssortmentTree tree, ProductGroupMapping current, List <ProductGroupMapping> productGroupMappings)
        {
            tree.AddToTree(current.ProductGroupMappingID, current.ParentProductGroupMappingID, flattenHierarchy: current.FlattenHierarchy, filterByParent: current.FilterByParentGroup);

            foreach (var childMapping in productGroupMappings.Where(c => c.ParentProductGroupMappingID == current.ProductGroupMappingID))
            {
                AddChild(tree, childMapping, productGroupMappings);
            }
        }
Ejemplo n.º 2
0
        private AssortmentTree BuildTree(List <ProductGroupMapping> productGroupMappings)
        {
            AssortmentTree tree = new AssortmentTree();

            foreach (var mapping in productGroupMappings.Where(c => c.ParentProductGroupMappingID == null).ToList())
            {
                //roots
                tree.AddToTree(mapping.ProductGroupMappingID, flattenHierarchy: mapping.FlattenHierarchy, filterByParent: mapping.FilterByParentGroup);
                foreach (var childMapping in productGroupMappings.Where(c => c.ParentProductGroupMappingID == mapping.ProductGroupMappingID))
                {
                    AddChild(tree, childMapping, productGroupMappings);
                }
            }
            return(tree);
        }
        private void AddChild(AssortmentTree tree, MasterGroupMapping current, IEnumerable <MasterGroupMapping> mappings)
        {
            var retainProducts        = false;
            var retainProductsSetting = current.MasterGroupMappingSettingValues.FirstOrDefault(x => x.MasterGroupMappingSetting.Name == "Retain Products");

            if (retainProductsSetting != null)
            {
                bool.TryParse(retainProductsSetting.Value, out retainProducts);
            }

            tree.AddToTree(current.MasterGroupMappingID, current.ParentMasterGroupMappingID, flattenHierarchy: current.FlattenHierarchy, filterByParent: current.FilterByParentGroup, retainProducts: retainProducts);

            foreach (var childMapping in mappings.Where(c => c.ParentMasterGroupMappingID == current.MasterGroupMappingID))
            {
                AddChild(tree, childMapping, mappings);
            }
        }
        /// <summary>
        /// This is just a performance test
        /// </summary>
        //[TestMethod]
        public void Add_Product_To_Level_1_Should_Attach_The_Products_To_The_Right_Node_500000_Products()
        {
            Random r = new Random();

            _tree.AddToTree(1);
            _tree.AddToTree(2, 1);
            _tree.AddToTree(3, 1);
            _tree.AddToTree(4, 1);
            _tree.AddToTree(5, 1);

            for (int i = 6; i < 700; i++)
            {
                _tree.AddToTree(i, i % 2 == 0 ? 2 : 3);
                _tree.AddProducts(Enumerable.Range(0, r.Next(2000)).ToList(), i, _productProductGroupMapping, false);
            }
        }
        private AssortmentTree BuildTree(IEnumerable <MasterGroupMapping> mappings)
        {
            var tree = new AssortmentTree();

            foreach (var mapping in mappings.Where(c => c.ParentMasterGroupMappingID == null).ToList())
            {
                var retainProducts        = false;
                var retainProductsSetting = mapping.MasterGroupMappingSettingValues.FirstOrDefault(x => x.MasterGroupMappingSetting.Name == "Retain Products");
                if (retainProductsSetting != null)
                {
                    bool.TryParse(retainProductsSetting.Value, out retainProducts);
                }

                tree.AddToTree(mapping.MasterGroupMappingID, flattenHierarchy: mapping.FlattenHierarchy, filterByParent: mapping.FilterByParentGroup, retainProducts: retainProducts);

                foreach (var childMapping in mappings.Where(c => c.ParentMasterGroupMappingID == mapping.MasterGroupMappingID))
                {
                    AddChild(tree, childMapping, mappings);
                }
            }

            return(tree);
        }
Ejemplo n.º 6
0
        public void Add_Product_To_Level_1_Should_Attach_The_Products_To_The_Right_Node()
        {
            _tree.AddToTree(1);
            _tree.AddToTree(2, 1);

            _tree.AddProducts(Enumerable.Range(1, 10000).ToList(), 2, _productProductGroupMapping, false);

            Assert.IsTrue(_tree.GetNode(2).Products.Count == 10000);
        }
Ejemplo n.º 7
0
        public void Add_Category_Should_Be_Added_To_Tree_Root()
        {
            _tree.AddToTree(1);
            var addedNode = _tree.GetNode(1);

            Assert.IsTrue(addedNode != null && addedNode.MasterGroupMappingID == 1 && addedNode.Parent.MasterGroupMappingID == _rootID);
        }