Beispiel #1
0
        public IEnumerable <BrandBoardGroup> GroupBrandData(IEnumerable <BrandBoardItem> items)
        {
            // group items by rule from customised group utility
            // groupItemNumber is optional parameter. It is futureproof consideration for different groupping rule
            // "others" tag is replaced with "z" to make it alway display at last.
            var groups = items
                         .GroupBy(l => GroupUtility.GetGroupName(l.BrandName, groupItemNumber: 2))
                         .OrderBy(l => l.Key.Replace("Others", "z"));


            var result = new List <BrandBoardGroup>();

            foreach (var group in groups)
            {
                // loop group and sort items in each group with custimised rule
                // the order in given example does not meet any unified rule from my humble option
                // here is a temp rule to match the example
                // rule1: case is not sensitive
                // rule2: if words start with b/e/l [space] is sorted like "s"
                // rule3: "ABC" is after "ABCD"
                var resultItem = new BrandBoardGroup()
                {
                    GroupName = group.Key,
                    Items     = group.ToList()
                                .OrderBy(l => ("BEL".Contains(l.BrandName[0]) ? l.BrandName.Replace(" ", "s") : (l.BrandName + "{")), StringComparer.OrdinalIgnoreCase)
                };
                result.Add(resultItem);
            }
            return(result);
        }
Beispiel #2
0
        public void GetGroupName_CustomizedGroupItemNumber3_ReturnRightName()
        {
            // Arrange
            string itemName = "A2";
            // Act
            var result = GroupUtility.GetGroupName(itemName, 3);

            // Assert
            Assert.Equal("A-C", result);
        }
Beispiel #3
0
        public void GetGroupName_BoundaryGroupItemNumber3_ReturnRightName()
        {
            // Arrange
            string itemName = "Zoo";
            // Act
            var result = GroupUtility.GetGroupName(itemName, 2);

            // Assert
            Assert.Equal("Y-Z", result);
        }
Beispiel #4
0
        public void GetGroupName_DefaultGroupItemNumber_ReturnRightName()
        {
            // Arrange
            string itemName = "A2";
            // Act
            var result = GroupUtility.GetGroupName(itemName);

            // Assert
            Assert.Equal("A-B", result);
        }