Exemplo n.º 1
0
 public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent, bool advanced = false)
 {
     GroupName   = groupName;
     ParentGroup = parent;
     Advanced    = advanced;
     ChildGroups = new List <ItemFilterBlockGroup>();
 }
 public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent, bool advanced = false)
 {
     GroupName = groupName;
     ParentGroup = parent;
     Advanced = advanced;
     ChildGroups = new List<ItemFilterBlockGroup>();
 }
        public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, ItemFilterBlockGroup startItemGroup)
        {
            var inputGroups = groupStrings.ToList();
            var firstGroup = inputGroups.First().Trim();
            if (firstGroup.StartsWith("~"))
            {
                firstGroup = firstGroup.Substring(1);
            }

            ItemFilterBlockGroup matchingChildItemGroup = null;
            if (startItemGroup.ChildGroups.Count(g => g.GroupName == firstGroup) > 0)
            {
                matchingChildItemGroup = startItemGroup.ChildGroups.First(c => c.GroupName == firstGroup);
            }

            if (matchingChildItemGroup == null)
            {
                var newItemGroup = CreateBlockGroup(inputGroups.First().Trim(), startItemGroup);
                startItemGroup.ChildGroups.Add(newItemGroup);
                inputGroups = inputGroups.Skip(1).ToList();
                return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, newItemGroup) : newItemGroup;
            }
            inputGroups = inputGroups.Skip(1).ToList();
            return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, matchingChildItemGroup) : matchingChildItemGroup;
        }
Exemplo n.º 4
0
        public bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup)
        {
            if (startingBlockGroup == targetBlockGroup)
            {
                return(true);
            }
            if (BlockGroup == null)
            {
                return(false);
            }

            return(startingBlockGroup.ParentGroup != null && HasBlockGroupInParentHierarchy(targetBlockGroup, startingBlockGroup.ParentGroup));
        }
        public void IntegrateStringListIntoBlockGroupHierarchy_AdvancedBlockGroup_ChildrenAreCreatedAsAdvanced()
        {
            // Arrange
            var inputStrings = new List<string> { "~Advanced Block Group", "This should be advanced too" };

            var rootBlock = new ItemFilterBlockGroup("Root", null);
            var builder = new BlockGroupHierarchyBuilder();

            // Act
            var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);

            // Assert
            Assert.AreEqual(1, rootBlock.ChildGroups.Count);
            Assert.AreEqual(true, result.Advanced);
        }
        public void IntegrateStringListIntoBlockGroupHierarchy_AdvancedBlockGroup_MarksBlockGroupAsAdvanced()
        {
            // Arrange
            var inputStrings = new List<string> { "~Block Group" };

            var rootBlock = new ItemFilterBlockGroup("Root", null);
            var builder = new BlockGroupHierarchyBuilder();

            // Act
            var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);

            // Assert
            Assert.AreEqual(1, rootBlock.ChildGroups.Count);
            Assert.AreEqual("Block Group", result.GroupName);
            Assert.AreEqual(true, result.Advanced);
        }
        private ItemFilterBlockGroup CreateBlockGroup(string groupNameString, ItemFilterBlockGroup parentGroup)
        {
            var advanced = false;

            if (groupNameString.StartsWith("~"))
            {
                groupNameString = groupNameString.Substring(1);
                advanced = true;
            }

            if (parentGroup.Advanced)
            {
                advanced = true;
            }

            return new ItemFilterBlockGroup(groupNameString, parentGroup, advanced);
        }
        public void IntegrateStringListIntoBlockGroupHierarchy_MultipleBlockGroups()
        {
            // Arrange
            var rootBlock = new ItemFilterBlockGroup("Root", null);
            var builder = new BlockGroupHierarchyBuilder();

            // Act
            var inputStrings = new List<string> { "Block Group" };
            builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
            inputStrings = new List<string> { "Block Group 2" };
            builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);
            inputStrings = new List<string> { "Block Group", "Sub Block Group" };
            var result = builder.IntegrateStringListIntoBlockGroupHierarchy(inputStrings, rootBlock);

            // Assert
            Assert.AreEqual(2, rootBlock.ChildGroups.Count);
            Assert.AreEqual("Sub Block Group", result.GroupName);
        }
Exemplo n.º 9
0
        public void AddOrJoinBlockGroup(ItemFilterBlockGroup blockGroup)
        {
            var childIndex = ChildGroups.FindIndex(item => item.GroupName.Equals(blockGroup.GroupName));

            if (!blockGroup.IsLeafNode && childIndex >= 0)
            {
                while (blockGroup.ChildGroups.Count > 0)
                {
                    ChildGroups[childIndex].AddOrJoinBlockGroup(blockGroup.ChildGroups[0]);
                }
            }
            else
            {
                if (blockGroup.ParentGroup != null)
                {
                    blockGroup.ParentGroup.ChildGroups.Remove(blockGroup);
                }
                blockGroup.ParentGroup = this;
                ChildGroups.Add(blockGroup);
            }
        }
        public void TranslateStringToItemFilterBlock_BlockGroupComment_SetsBlockItemGroupCorrectly()
        {
            // Arrange
            var inputString = "Show # Test Block Group - Test Sub Block Group - Test Another Block Group" + Environment.NewLine;
            var testBlockGroup = new ItemFilterBlockGroup("zzzzz", null);

            // Act
            _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Returns(testBlockGroup).Verifiable();
            var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null);

            // Assert
            Assert.AreEqual(testBlockGroup, result.BlockGroup);
            _testUtility.MockBlockGroupHierarchyBuilder.Verify();
        }
        public void TranslateStringToItemFilterBlock_BlockGroupComment_CallsBlockGroupHierarchyBuilder()
        {
            // Arrange
            var inputString = "Show # TestBlockGroup" + Environment.NewLine;
            var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);

            // Act
            _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Returns(inputBlockGroup).Verifiable();
            _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null);

            // Assert
            _testUtility.MockBlockGroupHierarchyBuilder.Verify();
        }
        public void TranslateItemFilterBlockToString_HasBlockGroup_ReturnsCorrectString()
        {
            // Arrange
            var expectedResult = "Show # Child 1 Block Group - Child 2 Block Group";

            var rootBlockGroup = new ItemFilterBlockGroup("Root Block Group", null);
            var child1BlockGroup = new ItemFilterBlockGroup("Child 1 Block Group", rootBlockGroup);
            var child2BlockGroup = new ItemFilterBlockGroup("Child 2 Block Group", child1BlockGroup);
            _testUtility.TestBlock.BlockGroup = child2BlockGroup;

            // Act
            var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }
        public void TranslateStringToItemFilterBlock_ShowBlock_SetsBlockGroupIsCheckedCorrectly()
        {
            // Arrange
            var inputString = "Show # TestBlockGroup" + Environment.NewLine;
            var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);

            // Act
            _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Returns(inputBlockGroup).Verifiable();
            _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null);

            // Assert
            Assert.AreEqual(true, inputBlockGroup.IsChecked);
        }
 public void Initialise(ItemFilterBlockGroup rootBlockGroup)
 {
     _rootBlockGroup = rootBlockGroup;
 }
 public void Cleanup()
 {
     _rootBlockGroup = null;
 }