public void MovingNodeAroundHierarchyWithChildRemoves() { ProjectTree aa, ab; var root = ProjectTree.Create("A").WithChildren( aa = ProjectTree.Create("AA").WithChildren( ProjectTree.Create("AAA")), ab = ProjectTree.Create("AB")); var aaModified = aa.RemoveChild(aa.Children[0]); var moved = root.RemoveDescendent(aa).AddDescendent(aaModified, ab); var history = moved.ChangesSince(root); Assert.Equal(2, history.Count); Assert.Equal(ChangeKind.Removed, history[0].Kind); Assert.Same(aa.Children[0], history[0].Before); Assert.Null(history[0].After); Assert.Equal(aa.Children[0].Identity, history[0].Identity); Assert.Equal(ChangeKind.Replaced, history[1].Kind); Assert.Equal(ProjectTreeChangedProperties.Parent, history[1].Changes); Assert.Same(aa, history[1].Before); Assert.Same(aaModified, history[1].After); Assert.Equal(aa.Identity, history[1].Identity); }
public void AsProjectItemTree_OnNonItem() { var root = ProjectTree.Create("hi").AsRoot; var item = root.AsProjectItemTree; Assert.True(item.IsDefault); }
private static void RecursiveAddChildren(ProjectTree template, ProjectTree.Builder receiver) { foreach (var templateChild in template) { var clonedTemplateChild = ProjectTree.Create(templateChild.Caption).ToBuilder(); RecursiveAddChildren(templateChild, clonedTemplateChild); receiver.Children.Add(clonedTemplateChild.ToImmutable()); } }
internal RootedProjectTree CloneProjectTreeRootToLeafWithBuilders(RootedProjectTree templateTree) { var rootBuilder = ProjectTree.Create(templateTree.Caption).ToBuilder(); RecursiveAddChildren(templateTree.ProjectTree, rootBuilder); var root = rootBuilder.ToImmutable(); return(root.AsRoot); }
internal ProjectTree NewTree(string caption, IEnumerable <ProjectTree> children = null) { var tree = ProjectTree.Create(caption); if (children != null) { tree = tree.WithChildren(children); } return(tree); }
internal ProjectTree NewNode(params ProjectTree[] children) { this.nodeCounter++; var tree = ProjectTree.Create(Caption + this.nodeCounter); if (children != null) { tree = tree.WithChildren(children); } return(tree); }
private static RootedProjectTree RecursiveAddChildren(ProjectTree template, RootedProjectTree receiver) { RootedProjectTree latest = receiver; foreach (var templateChild in template) { var clonedTemplateChild = ProjectTree.Create(templateChild.Caption); var asChild = latest.AddChild(clonedTemplateChild).Value; var childWithChildren = RecursiveAddChildren(templateChild, asChild); latest = childWithChildren.Parent; } return(latest); }
public void RepositioningNodeWithinParentsChildren() { ProjectTree aa, ab; var root = ProjectTree.Create("A").WithChildren( aa = ProjectTree.Create("AA"), ab = ProjectTree.Create("AB")); var ac = aa.WithCaption("AC"); var modified = root.ReplaceDescendent(aa, ac); var history = modified.ChangesSince(root); Assert.Equal(1, history.Count); Assert.Equal(ChangeKind.Replaced, history[0].Kind); Assert.Equal(ProjectTreeChangedProperties.Caption | ProjectTreeChangedProperties.PositionUnderParent, history[0].Changes); Assert.Same(aa, history[0].Before); Assert.Same(ac, history[0].After); }
public void MovingNodeAroundHierarchy() { ProjectTree aa, ab; var root = ProjectTree.Create("A").WithChildren( aa = ProjectTree.Create("AA"), ab = ProjectTree.Create("AB")); var moved = root.RemoveDescendent(aa).AddDescendent(aa, ab); var history = moved.ChangesSince(root); Assert.Equal(1, history.Count); Assert.Equal(ChangeKind.Replaced, history[0].Kind); Assert.Same(aa, history[0].Before); Assert.Same(aa, history[0].After); Assert.Equal(ProjectTreeChangedProperties.Parent, history[0].Changes); }
public void ProjectTreeValueComparer() { var tree = ProjectTree.Create("root"); Assert.Equal(tree, tree, ProjectTree.Comparers.Identity); Assert.Equal(tree, tree, ProjectTree.Comparers.ByValue); var newPath = tree.WithFilePath("c:\\some\\path"); Assert.Equal(tree, newPath, ProjectTree.Comparers.Identity); Assert.NotEqual(tree, newPath, ProjectTree.Comparers.ByValue); var changedBackToOriginal = newPath.WithFilePath(tree.FilePath); Assert.Equal(tree, changedBackToOriginal, ProjectTree.Comparers.Identity); Assert.Equal(tree, changedBackToOriginal, ProjectTree.Comparers.ByValue); var derivedType = tree.ToProjectItemTree(new ProjectPropertiesContext()); Assert.Equal(tree, derivedType, ProjectTree.Comparers.Identity); Assert.NotEqual(tree, derivedType, ProjectTree.Comparers.ByValue); }
internal static RootedProjectTree ConstructVeryLargeTree(Random random, int depth, int maxImmediateChildrenCount, int totalNodeCount, Func <string> counter = null) { Requires.NotNull(random, "random"); Requires.Range(depth > 0, "maxDepth"); Requires.Range(totalNodeCount > 0, "totalNodeCount"); if (counter == null) { int counterPosition = 0; counter = () => "Node " + ++counterPosition; } var tree = RootedProjectTree.Create(counter()); int nodesAllocated = 1; int maxChildrenCount = Math.Min(maxImmediateChildrenCount, totalNodeCount - nodesAllocated); if (depth == 1) { tree = tree.AddChildren(Enumerable.Range(1, maxChildrenCount).Select(n => ProjectTree.Create(counter()))); nodesAllocated += maxChildrenCount; } else { int childrenCount = random.Next(maxChildrenCount) + 1; int sizePerBranch = (totalNodeCount - nodesAllocated) / childrenCount; if (sizePerBranch > 0) { tree = tree.AddChildren(Enumerable.Range(1, childrenCount).Select(n => ConstructVeryLargeTree(random, depth - 1, maxImmediateChildrenCount, sizePerBranch, counter).ProjectTree)); } } return(tree); }
internal ProjectTree CloneProjectTreeLeafToRoot(ProjectTree templateTree) { var clone = ProjectTree.Create(templateTree.Caption).AddChildren(templateTree.Children.Select(this.CloneProjectTreeLeafToRoot)); return(clone); }