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"); }
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"); }
public void CanDeepClone() { var option = new DictionaryNodeListOptions.DictionaryNodeOption { Id = "option id", IsEnabled = true }; var options = new DictionaryNodeListOptions { Options = new List <DictionaryNodeListOptions.DictionaryNodeOption> { option } }; var parent = new ConfigurableDictionaryNode(); var child = new ConfigurableDictionaryNode { Before = "before", IsEnabled = true, CSSClassNameOverride = "class", Parent = parent }; var grandchild = new ConfigurableDictionaryNode { Between = "childBetween", FieldDescription = "FieldDesc", Parent = child }; var grandsibling = new ConfigurableDictionaryNode { DictionaryNodeOptions = options, Style = "stylish", LabelSuffix = "1", Parent = parent }; parent.Children = new List <ConfigurableDictionaryNode> { child }; child.Children = new List <ConfigurableDictionaryNode> { grandchild, grandsibling }; // SUT var clone = child.DeepCloneUnderSameParent(); VerifyDuplication(clone, child); }
public void IsMasterParent() { var children = new List <ConfigurableDictionaryNode> { new ConfigurableDictionaryNode() }; var sharedNode = new ConfigurableDictionaryNode { Children = children }; var masterParent = new ConfigurableDictionaryNode { ReferencedNode = sharedNode }; var otherParent = new ConfigurableDictionaryNode { ReferencedNode = sharedNode }; sharedNode.Parent = masterParent; var standaloneParent = new ConfigurableDictionaryNode { Children = children }; Assert.True(masterParent.IsMasterParent, "Shared Node's Parent should be Master Parent"); Assert.False(otherParent.IsMasterParent, "Other node referring to Shared node should not be Master Parent"); Assert.False(standaloneParent.IsMasterParent, "node with only direct children should not be Master Parent"); Assert.False(masterParent.IsSubordinateParent, "Shared Node's Parent should not be Subordinate Parent"); Assert.True(otherParent.IsSubordinateParent, "Other node referring to Shared node should be Subordinate Parent"); Assert.False(standaloneParent.IsSubordinateParent, "node with only direct children should not be Subordinate Parent (to whom would it subord?)"); }
private static ConfigurableDictionaryNode CreatePictureModel() { var thumbNailNode = new ConfigurableDictionaryNode { FieldDescription = "PictureFileRA", CSSClassNameOverride = "picture" }; var pictureNode = new ConfigurableDictionaryNode { FieldDescription = "PicturesOfSenses", CSSClassNameOverride = "Pictures", Children = new List <ConfigurableDictionaryNode> { thumbNailNode } }; var sensesNode = new ConfigurableDictionaryNode { FieldDescription = "Senses" }; var mainEntryNode = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode> { sensesNode, pictureNode }, FieldDescription = "LexEntry" }; CssGeneratorTests.PopulateFieldsForTesting(mainEntryNode); return(mainEntryNode); }
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"); }
public void TryGetMasterParent() { var child = new ConfigurableDictionaryNode(); var sharedNode = new ConfigurableDictionaryNode { Label = "Shared", Children = new List <ConfigurableDictionaryNode> { child } }; var masterParent = new ConfigurableDictionaryNode { ReferenceItem = "Shared" }; var root = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode> { masterParent } }; CssGeneratorTests.PopulateFieldsForTesting(DictionaryConfigurationModelTests.CreateSimpleSharingModel(root, sharedNode)); ConfigurableDictionaryNode returnedMasterParent; Assert.True(child.TryGetMasterParent(out returnedMasterParent)); // SUT Assert.AreSame(masterParent, returnedMasterParent); Assert.False(masterParent.TryGetMasterParent(out returnedMasterParent), "The master parent doesn't *have* a master parent, it *is* one"); // SUT Assert.IsNull(returnedMasterParent, "Master Parent"); Assert.False(root.TryGetMasterParent(out returnedMasterParent), "The root node *certainly* doesn't have a master parent"); // SUT Assert.IsNull(returnedMasterParent, "Root Node"); }
/// <summary> /// Returns the top-level ancestor of the given node /// </summary> private static ConfigurableDictionaryNode GetTopLevelNode(ConfigurableDictionaryNode childNode) { while (childNode.Parent != null) { childNode = childNode.Parent; } return(childNode); }
public void IsMainEntry_MainReversalIndexEntry_True() { var mainEntryNode = new ConfigurableDictionaryNode { FieldDescription = "ReversalIndexEntry", CSSClassNameOverride = "reversalindexentry", Parent = null }; Assert.True(mainEntryNode.IsMainEntry, "Main Entry"); }
public void IsMainEntry_MinorEntry_False() { var minorEntryNode = new ConfigurableDictionaryNode { FieldDescription = "LexEntry", CSSClassNameOverride = "minorentry", Parent = null }; Assert.False(minorEntryNode.IsMainEntry, "Main Entry"); }
public void Equals_DifferentLabelsAndSuffixesAreNotEqual() { var firstNode = new ConfigurableDictionaryNode { Label = "same", LabelSuffix = "suffixA" }; var secondNode = new ConfigurableDictionaryNode { Label = "different", LabelSuffix = "suffixB" }; Assert.AreNotEqual(firstNode, secondNode); }
public void IsMainEntry_OtherEntry_False() { var mainEntryNode = new ConfigurableDictionaryNode { FieldDescription = "LexEntry", CSSClassNameOverride = "entry", Parent = null }; var someNode = new ConfigurableDictionaryNode { FieldDescription = "MLHeadWord", CSSClassNameOverride = "mainheadword", Parent = mainEntryNode }; Assert.False(someNode.IsMainEntry, "Main Entry"); }
/// <summary> /// Finds the nearest Master Parent in this node's ancestry if this is a SharedItem or descendent; /// returns false (out null) if this is a direct descendent of a Part. /// </summary> internal bool TryGetMasterParent(out ConfigurableDictionaryNode masterParent) { for (masterParent = Parent; masterParent != null; masterParent = masterParent.Parent) { if (masterParent.ReferencedNode != null) { return(true); } } return(false); }
/// <summary> /// A match is two nodes with the same label and suffix in the same hierarchy (all ancestors have same labels & suffixes) /// </summary> private static bool CheckParents(ConfigurableDictionaryNode first, ConfigurableDictionaryNode second) { if (first == null && second == null) { return(true); } if ((first == null ^ second == null) || (first.Parent == null ^ second.Parent == null)) // ^ is XOR { return(false); } return(first.Label == second.Label && first.LabelSuffix == second.LabelSuffix && CheckParents(first.Parent, second.Parent)); }
private static bool DoesGeckoElementOriginateFromConfigNode(ConfigurableDictionaryNode configNode, GeckoElement element, ConfigurableDictionaryNode topLevelNode) { Guid dummyGuid; GeckoElement dummyElement; var classListForGeckoElement = XhtmlDocView.GetClassListFromGeckoElement(element, out dummyGuid, out dummyElement); classListForGeckoElement.RemoveAt(0); // don't need the top level class var nodeToMatch = DictionaryConfigurationController.FindConfigNode(topLevelNode, classListForGeckoElement); return(Equals(nodeToMatch, configNode)); }
public void IsMainEntry_StemBasedMainEntry_ComplexForms_True_ButNotReadonly() { var mainEntryNode = new ConfigurableDictionaryNode { FieldDescription = "LexEntry", CSSClassNameOverride = "mainentrycomplex", DictionaryNodeOptions = new DictionaryNodeListOptions(), Parent = null }; Assert.True(mainEntryNode.IsMainEntry, "Main Entry"); }
public void ReferencedOrDirectChildren_FallsBackOnDirectChildren() { var child = new ConfigurableDictionaryNode { Label = "DirectChild" }; var parent = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode> { child } }; Assert.AreSame(child, parent.ReferencedOrDirectChildren.First()); }
public void DuplicateSharedNodeParentMaintainsLink() { var sharedItem = new ConfigurableDictionaryNode { Label = "Shared" }; var masterParent = new ConfigurableDictionaryNode { ReferenceItem = "Shared", ReferencedNode = sharedItem }; var clone = masterParent.DeepCloneUnderParent(null, true); // SUT: pretend this is a recursive call Assert.AreEqual(masterParent.ReferenceItem, clone.ReferenceItem); Assert.AreSame(masterParent.ReferencedNode, clone.ReferencedNode); }
/// <summary> /// Clone this node, point to the given Parent. Deep-clone Children and DictionaryNodeOptions /// </summary> /// <remarks> /// Grouping node children are cloned only if this is a recursive call. /// Referenced children are cloned only if this is NOT a recursive call. /// </remarks> internal ConfigurableDictionaryNode DeepCloneUnderParent(ConfigurableDictionaryNode parent, bool isRecursiveCall = false) { var clone = new ConfigurableDictionaryNode(); // Copy everything over at first, importantly handling strings, bools. var properties = typeof(ConfigurableDictionaryNode).GetProperties(); foreach (var property in properties) { // Skip Parent and read-only properties (eg DisplayLabel) if (!property.CanWrite || property.Name == "Parent") { continue; } var originalValue = property.GetValue(this, null); property.SetValue(clone, originalValue, null); } clone.ReferencedNode = ReferencedNode; // GetProperties() doesn't return internal properties; copy here clone.Parent = parent; // Deep-clone Children if (Children != null && Children.Any()) { if (isRecursiveCall || !(DictionaryNodeOptions is DictionaryNodeGroupingOptions)) { // Cloned children should point to their newly-cloned parent clone.Children = Children.Select(child => child.DeepCloneUnderParent(clone, true)).ToList(); } else { // Cloning children of a group creates problems because the children can be moved out of the group. // Also the only expected use of cloning a group is to get a new group to group different children. clone.Children = null; } } else if (!isRecursiveCall && ReferencedNode != null && ReferencedNode.Children != null) { // Allow users to configure copies of Shared nodes (e.g. Subentries) separately clone.ReferencedNode = null; clone.ReferenceItem = null; clone.Children = ReferencedNode.Children.Select(child => child.DeepCloneUnderParent(clone, true)).ToList(); } // Deep-clone DictionaryNodeOptions if (DictionaryNodeOptions != null) { clone.DictionaryNodeOptions = DictionaryNodeOptions.DeepClone(); } return(clone); }
public void Equals_DifferentSuffixesAndSameParentsAreNotEqual() { var parentNode = new ConfigurableDictionaryNode { Label = "Parent" }; var firstNode = new ConfigurableDictionaryNode { Label = "label", LabelSuffix = "same", Parent = parentNode }; var secondNode = new ConfigurableDictionaryNode { Label = "label", LabelSuffix = "different", Parent = parentNode }; Assert.AreNotEqual(firstNode, secondNode); }
public void Equals_SameLabelsAndSameParentsAreEqual() { var parentNode = new ConfigurableDictionaryNode { Label = "Parent" }; var firstNode = new ConfigurableDictionaryNode { Label = "same", Parent = parentNode, LabelSuffix = null }; var secondNode = new ConfigurableDictionaryNode { Label = "same", Parent = parentNode, LabelSuffix = null }; Assert.AreEqual(firstNode, secondNode); }
public void Equals_OneParentNullAreNotEqual() { var firstNode = new ConfigurableDictionaryNode { Label = "same" }; var secondNode = new ConfigurableDictionaryNode { Label = "same", Parent = firstNode }; Assert.AreNotEqual(firstNode, secondNode); secondNode.Parent = null; firstNode.Parent = secondNode; Assert.AreNotEqual(firstNode, secondNode); }
public void CanUnlinkTwice() { var parent = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode>(), Parent = null }; var node = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode>(), Parent = parent }; parent.Children.Add(node); node.UnlinkFromParent(); Assert.That(node.Parent, Is.Null); // node is now at the root of a hierarchy // SUT Assert.DoesNotThrow(() => node.UnlinkFromParent()); }
public void CanUnlink() { var parent = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode>(), Parent = null }; var node = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode>(), Parent = parent }; parent.Children.Add(node); // SUT node.UnlinkFromParent(); Assert.That(parent.Children.Count, Is.EqualTo(0), "Parent should not link to unlinked child"); Assert.That(node.Parent, Is.Null, "Node should not still claim the original parent"); }
public void CanChangeSuffixOfRootNode() { var rootNode = new ConfigurableDictionaryNode { Parent = null, Label = "rootNode", LabelSuffix = "orig" }; var rootNodes = new List <ConfigurableDictionaryNode> { rootNode }; // SUT var result = rootNode.ChangeSuffix("new", rootNodes); Assert.That(result, Is.True, "allow changing suffix of root"); Assert.That(rootNode.LabelSuffix, Is.EqualTo("new"), "failed to change suffix"); }
public void ChildlessCanDeepClone() { var parent = new ConfigurableDictionaryNode(); var child = new ConfigurableDictionaryNode { After = "after", IsEnabled = true, SubField = "sub", IsCustomField = true, HideCustomFields = true, Parent = parent }; parent.Children = new List <ConfigurableDictionaryNode> { child }; // SUT var clone = child.DeepCloneUnderSameParent(); VerifyDuplication(clone, child); }
public void ReportSuccessfulChangedSuffix() { var parent = new ConfigurableDictionaryNode { Children = new List <ConfigurableDictionaryNode>(), Parent = null }; var node = new ConfigurableDictionaryNode { Parent = parent, Label = "originalLabel", LabelSuffix = "blah" }; parent.Children.Add(node); // SUT var result = node.ChangeSuffix("new"); Assert.That(result, Is.True); }
public void HasCorrectDisplayLabel() { var nodeWithNullSuffix = new ConfigurableDictionaryNode { Label = "label", LabelSuffix = null }; // SUT Assert.That(nodeWithNullSuffix.DisplayLabel, Is.EqualTo("label"), "DisplayLabel should omit parentheses and suffix if suffix is null"); var nodeWithSuffix = new ConfigurableDictionaryNode { Label = "label2", LabelSuffix = "suffix2" }; // SUT Assert.That(nodeWithSuffix.DisplayLabel, Is.EqualTo("label2 (suffix2)"), "DisplayLabel should include suffix"); }
public void HasCorrectDisplayLabelForGroup() { var nodeWithNullSuffix = new ConfigurableDictionaryNode { Label = "label", LabelSuffix = null, DictionaryNodeOptions = new DictionaryNodeGroupingOptions() }; // SUT Assert.That(nodeWithNullSuffix.DisplayLabel, Is.EqualTo("[label]"), "GroupingNodes should be bracketed"); var nodeWithSuffix = new ConfigurableDictionaryNode { Label = "label2", LabelSuffix = "suffix2", DictionaryNodeOptions = new DictionaryNodeGroupingOptions() }; // SUT Assert.That(nodeWithSuffix.DisplayLabel, Is.EqualTo("[label2 (suffix2)]"), "Suffic should be inside the bracket for a grouping node"); }
public void Equals_DifferentParentsAreNotEqual() { var firstParent = new ConfigurableDictionaryNode { Label = "firstParent" }; var secondParent = new ConfigurableDictionaryNode { Label = "secondParent" }; var firstNode = new ConfigurableDictionaryNode { Label = "same", Parent = firstParent }; var secondNode = new ConfigurableDictionaryNode { Label = "same", Parent = secondParent }; Assert.AreNotEqual(firstNode, secondNode); }