public void ParentTakesOverFilteredDependencies() { var lib = new Node("Lib"); var logic = new Node("Logic"); var presentation = new Node("Presentation"); var windows = new Node("Windows"); var service = new Node("Service"); var root = new Node("root"); root.AddChild(lib); lib.AddChild(logic); lib.AddChild(presentation); presentation.AddChild(windows); logic.AddChild(service); windows.Dependencies.Add(service); root.ApplyFilters(new List<Filter> { new MaxDepth(2) }); var filtered = ModelFilterer.FindSiblingDependencies(root); var lib2 = filtered.Childs.First(); var pres = lib2.Childs.WithName("Presentation"); Assert.IsTrue(pres.DependsOn(logic)); }
public void TestSerializeSmallTree() { var top = new Node("Top"); var left = new Node("Left"); var right = new Node("Right"); top.AddChild(left); top.AddChild(right); // Assert top.ToString().Should().Be("Top = (Left,Right)"); }
public void DependenciesAreConvertedToSiblingsIfAvailible() { var root = new Node("ROOT"); var a = new Node("A"); var b = new Node("B"); var childOfB = new Node("C"); root.AddChild(a); root.AddChild(b); b.AddChild(childOfB); a.Dependencies.Add(childOfB); var newRoot = ModelFilterer.FindSiblingDependencies(root); var newA = newRoot.Childs.WithName("A"); Assert.IsNotNull(newA.SiblingDependencies.WithName("B")); }
public void PutsIndependentSiblingsIntoHorizontalLayer() { var a = new Node("A"); var b = new Node("B"); var c = new Node("C"); a.AddChild(b); a.AddChild(c); var newSiblings = SiblingReorderer.OrderChildsBySiblingsDependencies(new List<Node> {a}); var newRoot = newSiblings.First(); Assert.AreEqual(OrientationKind.Horizontal,newRoot.Orientation); CollectionAssert.Contains(newRoot.Childs.ToArray(), b); CollectionAssert.Contains(newRoot.Childs.ToArray(), c); }
public void AddsArrows() { var rootroot = new Node("RootRoot"); var root = new Node("Root"); var top = new Node("Top") {Orientation = OrientationKind.Horizontal}; var bottom = new Node("Bottom") {Orientation = OrientationKind.Horizontal}; var left = new Node("Left"); var right = new Node("Right"); rootroot.AddChild(root); root.AddChild(top); root.AddChild(bottom); top.AddChild(left); top.AddChild(right); bottom.AddChild(left); bottom.AddChild(right); var viewModelRoot = LayerMapper.TreeModelToArchViewModel(rootroot, true, true); var viewModel = viewModelRoot.Layers.First() as LayerViewModel; viewModel.Children.Count().Should().Be(3); var vtop = viewModel.Children.First() as LayerViewModel; var arrow = viewModel.Children.ElementAt(1); var vbottom = viewModel.Children.Last() as LayerViewModel; vtop.Columns.Should().Be(2); vbottom.Columns.Should().Be(2); vtop.Row.Should().Be(0); arrow.Row.Should().Be(1); vbottom.Row.Should().Be(2); vtop.Children.First().Column.Should().Be(0); vtop.Children.Last().Column.Should().Be(1); vbottom.Children.First().Column.Should().Be(0); vbottom.Children.Last().Column.Should().Be(1); }
public void NodeViewModelToLayerViewModelTest() { var root = new Node("Root"); var top = new Node("Top") {Orientation = OrientationKind.Horizontal}; var bottom = new Node("Bottom") { Orientation = OrientationKind.Horizontal }; var left = new Node("Left"); var right = new Node("Right"); root.AddChild(top); root.AddChild(bottom); top.AddChild(left); top.AddChild(right); bottom.AddChild(left); bottom.AddChild(right); var viewModel = LayerMapper.NodeViewModelToLayerViewModel(root,true); var vtop = viewModel.Children.First() as LayerViewModel; var vbottom = viewModel.Children.Last() as LayerViewModel; vtop.Columns.Should().Be(2); vbottom.Columns.Should().Be(2); vtop.Row.Should().Be(0); vbottom.Row.Should().Be(2); vbottom.Row.Should().Be(2); vtop.Children.First().Column.Should().Be(0); vtop.Children.Last().Column.Should().Be(1); vbottom.Children.First().Column.Should().Be(0); vbottom.Children.Last().Column.Should().Be(1); }
public void RemoveNodesWithMoreDepthThanTest() { var t = new Node("ROOT"); var a = new Node("A"); var b = new Node("B"); var c = new Node("C"); var d = new Node("D"); t.AddChild(a); a.AddChild(b); b.AddChild(c); c.AddChild(d); Assert.IsTrue(b.Childs.Any()); ModelFilterer.RemoveNodesWithMoreDepthThan(t,2); Assert.IsTrue(!b.Childs.Any()); }
/* public static void RemoveSingleChildAnonymous(Node tree) { foreach (var oldChild in tree.Childs.ToList()) { RemoveSingleChildAnonymous(oldChild); if (oldChild is SiblingHolderNode) { if(!oldChild.Childs.Any()) tree.RemoveChild(oldChild); if(oldChild.Childs.Count == 1) { var newChild = oldChild.Childs?.First(); tree.ReplaceChild(oldChild, newChild); } } } }*/ private static Node FindSiblingPatterns(Node tree) { if (!tree.Childs.Any()) return tree; if(!tree.Childs.Any(x => x.HasChildren())) { var baseClassPattern = PatternFinder.FindBaseClassPattern(tree.Childs); if (baseClassPattern != null) { tree.SetChildren(new List<Node>()); tree.AddChild(new Node(baseClassPattern + "s")); } else { var namingPatterns = PatternFinder.FindNamingPatterns(tree.Childs.Select(x => x.Name)).ToList(); if (namingPatterns.Any()) { foreach (var pattern in namingPatterns.ToList()) { var followspattern = tree.Childs.Where(x => PatternFinder.FollowsPattern(x.Name,pattern)).ToList(); foreach (var node in followspattern) { tree.RemoveChild(node); } tree.AddChild(new Node(pattern + "s")); } } } } tree.SetChildren(tree.Childs.Select(FindSiblingPatterns)); return tree; }