コード例 #1
0
        public void DuplicatesGroupingNodeChildrenAffectSuffixes()
        {
            var nodeToDuplicateLabel = "node";
            var nodeToDuplicate      = new ConfigurableDictionaryNode {
                Label = nodeToDuplicateLabel, LabelSuffix = null
            };
            var dupUnderGroup = new ConfigurableDictionaryNode {
                Label = nodeToDuplicateLabel, LabelSuffix = "1"
            };
            var groupingNode = new ConfigurableDictionaryNode
            {
                Label    = "groupNode", DictionaryNodeOptions = new DictionaryNodeGroupingOptions(),
                Children = new List <ConfigurableDictionaryNode> {
                    dupUnderGroup
                }
            };
            var parent = new ConfigurableDictionaryNode {
                Children = new List <ConfigurableDictionaryNode> {
                    nodeToDuplicate, groupingNode
                }
            };

            CssGeneratorTests.PopulateFieldsForTesting(parent);

            // SUT
            var duplicate  = nodeToDuplicate.DuplicateAmongSiblings();
            var inGroupDup = dupUnderGroup.DuplicateAmongSiblings();

            Assert.That(duplicate.Label, Is.EqualTo(nodeToDuplicateLabel), "should not have changed original node label");
            Assert.That(nodeToDuplicate.LabelSuffix, Is.Null, "should not have changed original node label suffix");
            Assert.That(duplicate.LabelSuffix, Is.EqualTo("2"), "(1) was used in the group, so the suffix should be 2");
            Assert.That(inGroupDup.LabelSuffix, Is.EqualTo("3"), "(2) was used in the group parent, so the suffix should be 3");
        }
コード例 #2
0
        public void DuplicatesHaveUniqueLabelSuffixes()
        {
            var parent = new ConfigurableDictionaryNode {
                Children = new List <ConfigurableDictionaryNode>()
            };
            var nodeToDuplicateLabel = "node";
            var nodeToDuplicate      = new ConfigurableDictionaryNode {
                Parent = parent, Label = nodeToDuplicateLabel, LabelSuffix = null
            };
            var otherNodeA = new ConfigurableDictionaryNode {
                Parent = parent, Label = "node", LabelSuffix = "1"
            };
            var otherNodeB = new ConfigurableDictionaryNode {
                Parent = parent, Label = "node", LabelSuffix = "B"
            };

            parent.Children.Add(nodeToDuplicate);
            parent.Children.Add(otherNodeA);
            parent.Children.Add(otherNodeB);

            // SUT
            var duplicate = nodeToDuplicate.DuplicateAmongSiblings();

            Assert.That(parent.Children.FindAll(node => node.LabelSuffix == nodeToDuplicate.LabelSuffix).Count, Is.EqualTo(1), "Should not have any more nodes with the original label suffix. Was the duplicate node's label suffix not changed?");
            Assert.That(parent.Children.FindAll(node => node.LabelSuffix == duplicate.LabelSuffix).Count, Is.EqualTo(1), "The duplicate node was not given a unique label suffix among the siblings.");
            Assert.That(nodeToDuplicate.Label, Is.EqualTo(nodeToDuplicateLabel), "should not have changed original node label");
            Assert.That(nodeToDuplicate.LabelSuffix, Is.Null, "should not have changed original node label suffix");
        }
コード例 #3
0
        public void DuplicateIsPutAmongSiblings()
        {
            var parent = new ConfigurableDictionaryNode();
            var childA = new ConfigurableDictionaryNode {
                After = "after", IsEnabled = true, Parent = parent
            };
            var grandchildA = new ConfigurableDictionaryNode {
                Before = "childBefore", Parent = childA
            };

            childA.Children = new List <ConfigurableDictionaryNode> {
                grandchildA
            };
            var childB = new ConfigurableDictionaryNode {
                After = "nodeBAfter", Parent = parent
            };

            parent.Children = new List <ConfigurableDictionaryNode> {
                childA, childB
            };

            // SUT
            var duplicate = childA.DuplicateAmongSiblings();

            VerifyDuplication(duplicate, childA);
            Assert.That(parent.Children.Count, Is.EqualTo(3), "should have increased");
            Assert.That(parent.Children.Contains(duplicate), Is.True, "duplicate should be listed among siblings, added to the parent's list of children");
        }
コード例 #4
0
        public void DuplicateLastItemDoesNotThrow()
        {
            var parent = new ConfigurableDictionaryNode();
            var nodeA  = new ConfigurableDictionaryNode {
                Parent = parent
            };
            var nodeB = new ConfigurableDictionaryNode {
                Parent = parent
            };

            parent.Children = new List <ConfigurableDictionaryNode> {
                nodeA, nodeB
            };

            // SUT
            Assert.DoesNotThrow(() => nodeB.DuplicateAmongSiblings(), "problem with edge case");
        }
コード例 #5
0
        public void DuplicatesAreMarkedAsSuch()
        {
            var parent = new ConfigurableDictionaryNode {
                Children = new List <ConfigurableDictionaryNode>()
            };
            var node = new ConfigurableDictionaryNode {
                Parent = parent
            };

            parent.Children.Add(node);
            Assert.That(node.IsDuplicate, Is.False);

            // SUT
            var duplicate = node.DuplicateAmongSiblings();

            Assert.That(duplicate.IsDuplicate, Is.True);
            Assert.That(node.IsDuplicate, Is.False, "Original should not have been marked as a duplicate.");
        }
コード例 #6
0
        public void CanDuplicateRootNode()
        {
            var rootNodeA = new ConfigurableDictionaryNode {
                Parent = null, Before = "beforeA"
            };
            var rootNodeB = new ConfigurableDictionaryNode {
                Parent = null
            };
            var rootNodes = new List <ConfigurableDictionaryNode> {
                rootNodeA, rootNodeB
            };

            // SUT
            var duplicate = rootNodeA.DuplicateAmongSiblings(rootNodes);

            Assert.That(rootNodes.Count, Is.EqualTo(3), "should have more nodes now");
            Assert.That(rootNodes.Contains(duplicate), "duplicate isn't among expected list of nodes");
            VerifyDuplication(duplicate, rootNodeA);
        }
コード例 #7
0
        public void DuplicateIsPutImmediatelyAfterOriginal()
        {
            var parent = new ConfigurableDictionaryNode();
            var nodeA  = new ConfigurableDictionaryNode {
                Parent = parent
            };
            var nodeB = new ConfigurableDictionaryNode {
                Parent = parent
            };

            parent.Children = new List <ConfigurableDictionaryNode> {
                nodeA, nodeB
            };
            Assert.That(parent.Children[0], Is.SameAs(nodeA));

            // SUT
            var duplicate = nodeA.DuplicateAmongSiblings();

            Assert.That(parent.Children[1], Is.SameAs(duplicate), "duplicate node should be placed immediately after duplicated node");
            Assert.That(parent.Children[2], Is.SameAs(nodeB), "second node in original list did not move into expected position");
        }
コード例 #8
0
        public void DuplicateGroupNodeParentDoesDuplicateGroupNodeChildren()
        {
            var parent    = new ConfigurableDictionaryNode();
            var groupNode = new ConfigurableDictionaryNode {
                Parent = parent, DictionaryNodeOptions = new DictionaryNodeGroupingOptions()
            };
            var nodeB = new ConfigurableDictionaryNode {
                Parent = groupNode
            };

            groupNode.Children = new List <ConfigurableDictionaryNode> {
                nodeB
            };
            parent.Children = new List <ConfigurableDictionaryNode> {
                groupNode
            };

            // SUT
            var duplicate = parent.DuplicateAmongSiblings(new List <ConfigurableDictionaryNode>());

            VerifyDuplication(duplicate, parent);
        }
コード例 #9
0
        public void DuplicateGroupNodeDoesNotDuplicateChildren()
        {
            var parent    = new ConfigurableDictionaryNode();
            var groupNode = new ConfigurableDictionaryNode {
                Parent = parent, DictionaryNodeOptions = new DictionaryNodeGroupingOptions()
            };
            var nodeB = new ConfigurableDictionaryNode {
                Parent = groupNode
            };

            groupNode.Children = new List <ConfigurableDictionaryNode> {
                nodeB
            };
            parent.Children = new List <ConfigurableDictionaryNode> {
                groupNode
            };

            // SUT
            var duplicate = groupNode.DuplicateAmongSiblings();

            Assert.AreEqual(1, groupNode.Children.Count);
            Assert.IsNull(duplicate.Children);
        }
コード例 #10
0
        public void DuplicatesSharedGroupingNodeChildrenAffectSuffixes()
        {
            var nodeToDuplicateLabel = "node";
            var nodeToDuplicate      = new ConfigurableDictionaryNode {
                FieldDescription = nodeToDuplicateLabel
            };
            var dupUnderShardGroup = new ConfigurableDictionaryNode {
                FieldDescription = nodeToDuplicateLabel, LabelSuffix = "1"
            };
            var sharedNode = new ConfigurableDictionaryNode
            {
                Label    = "Shared",
                Children = new List <ConfigurableDictionaryNode> {
                    dupUnderShardGroup
                },
                DictionaryNodeOptions = new DictionaryNodeGroupingOptions()
            };
            var sharedGroupRefNode = new ConfigurableDictionaryNode {
                ReferenceItem = "Shared", DictionaryNodeOptions = new DictionaryNodeGroupingOptions()
            };
            var root = new ConfigurableDictionaryNode {
                Children = new List <ConfigurableDictionaryNode> {
                    sharedGroupRefNode, nodeToDuplicate
                }
            };

            CssGeneratorTests.PopulateFieldsForTesting(DictionaryConfigurationModelTests.CreateSimpleSharingModel(root, sharedNode));

            // SUT
            var duplicate  = nodeToDuplicate.DuplicateAmongSiblings();
            var inGroupDup = dupUnderShardGroup.DuplicateAmongSiblings();

            Assert.That(duplicate.Label, Is.EqualTo(nodeToDuplicateLabel), "should not have changed original node label");
            Assert.That(nodeToDuplicate.LabelSuffix, Is.Null, "should not have changed original node label suffix");
            Assert.That(duplicate.LabelSuffix, Is.EqualTo("2"), "(1) was used in the group, so the suffix should be 2");
            Assert.That(inGroupDup.LabelSuffix, Is.EqualTo("3"), "(2) was used in the group parent, so the suffix should be 3");
        }