예제 #1
0
        public void RemovesNodesFromToBeGroupedThatArePartOfNestedGroup()
        {
            //In the following test, diagramsymbol will be added in the nested call when grouping arrowView and archView
            //Allthough only arrowView and archView will be sent as input to the nested call, the nested call will also add diagramSymbol, since both of them depend on diagramSymbol
            Node node = new Node(nameof(node));
            Node diagramSymbol = new Node(nameof(diagramSymbol));
            Node CircularDependencyHolder = new Node(nameof(CircularDependencyHolder)) { SiblingDependencies = {node} };
            Node archView = new Node(nameof(archView)) {SiblingDependencies = {diagramSymbol}};
            Node arrowView = new Node(nameof(arrowView)) { SiblingDependencies = { diagramSymbol } };
            Node layerMapper = new Node(nameof(layerMapper)) { SiblingDependencies = {node,archView,diagramSymbol,arrowView}};
            Node bitmapRenderer = new Node(nameof(bitmapRenderer)) {SiblingDependencies = {node,archView,layerMapper}};

            var newList = SiblingReorderer.LayOutSiblingNodes(new HashSet<Node>
            {
                node,diagramSymbol,CircularDependencyHolder,archView,arrowView,layerMapper,bitmapRenderer
            }).ToList();

            // bitmaprender
            // layermapper
            // arrow arch
            // diagramsybol      circulardeps
            //              node

            TestExtesions.TreeAssert.DoesNotContainDuplicates(newList);
        }
예제 #2
0
        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));
        }
예제 #3
0
        public void UnknownErrorCause()
        {
            //Produes duplicate RootScope
            Node rootScope = new Node(nameof(rootScope));
            Node node = new Node(nameof(node));
            Node classNode = new Node(nameof(classNode)) { SiblingDependencies = { node } };
            Node childrenFilter = new Node(nameof(childrenFilter)) { SiblingDependencies = { classNode } };

            Node diagramDefiniton = new Node(nameof(diagramDefiniton)) { SiblingDependencies = { rootScope } };

            Node diagramDefinitionParser = new Node(nameof(diagramDefinitionParser)) { SiblingDependencies = { diagramDefiniton, rootScope } };

            Node smallClassFilter = new Node(nameof(smallClassFilter)) { SiblingDependencies = { childrenFilter } };

            Node modelFilterer = new Node(nameof(modelFilterer)) { SiblingDependencies = { node,classNode,smallClassFilter } };

            Node solutioNode = new Node(nameof(solutioNode)) { SiblingDependencies = { node } };

            Node diagramFromDiagramGenerator = new Node(nameof(diagramFromDiagramGenerator)) {SiblingDependencies = {diagramDefinitionParser, node,diagramDefiniton,rootScope,modelFilterer }};

            var newList = SiblingReorderer.LayOutSiblingNodes(new HashSet<Node>
            {
                rootScope, diagramDefiniton, diagramDefinitionParser, node, classNode, childrenFilter, smallClassFilter,modelFilterer,solutioNode,diagramFromDiagramGenerator
            });

            TestExtesions.TreeAssert.DoesNotContainDuplicates(newList);
        }
예제 #4
0
        public void FindDependencyGroupsTest3()
        {
            Node A = new Node(nameof(A));
            Node B = new Node(nameof(B));
            Node C = new Node(nameof(C));
            Node D = new Node(nameof(D));
            Node E = new Node(nameof(E));
            Node X = new Node(nameof(X));

            C.SiblingDependencies.Add(A);
            C.SiblingDependencies.Add(X);
            D.SiblingDependencies.Add(X);
            D.SiblingDependencies.Add(B);
            E.SiblingDependencies.Add(B);

            //       0
            //1.  A  X   B
            //1.  C     D E
            var firstLayer = new List<Node> { C, D, E };
            var nextLayer = new List<Node> { A, X, B };
            var groups = SiblingReorderer.FindDependencyPatterns(firstLayer, nextLayer);
            groups.Count().Should().Be(2);
            //1 {C -> A , X} Cant choose, would hide D -> X dependency
            //2 {C -> A}
            //3 {C -> X}
            //4 {D -> X , B} Cant choose, would hide E -> B dependency
            //5 {D -> X}
            //6 {C , D -> X} Most referencers, Remove all posibilities of B
            //7 {D -> B}
            //8 {E -> B}
            //9 {D, E -> B}  Most referencers, Remove all posibilities of X
        }
 private static void ApplyPredicate(Node tree,int param, Func<ClassNode, int, bool> predicate)
 {
     var classes = tree.Childs.OfType<ClassNode>();
     var toRemove = classes.Where(x => predicate(x, param)).ToList();
     toRemove.ForEach(tree.FilterChild);
     tree.Childs.ForEach(x => ApplyPredicate(x, param, predicate));
 }
예제 #6
0
        public void FindDependencyGroupsTest()
        {
            Node A = new Node(nameof(A));
            Node B = new Node(nameof(B));
            Node C = new Node(nameof(C));
            Node D = new Node(nameof(D));
            Node E = new Node(nameof(E));
            Node X = new Node(nameof(X));

            C.SiblingDependencies.Add(A);
            C.SiblingDependencies.Add(X);
            D.SiblingDependencies.Add(X);
            D.SiblingDependencies.Add(B);
            E.SiblingDependencies.Add(B);

            //       0
            //1.  A  X   B
            //1.  C     D E
            var firstLayer = new List<Node> { C, D, E };
            var nextLayer = new List<Node> { A, X, B };
            var dependencies = SiblingReorderer.FindDependencies(firstLayer, nextLayer).ToList();
            var groups = SiblingReorderer.FindPotentialDependencyGroups(dependencies);
            groups.Count().Should().Be(9);
            Assert.IsTrue(groups.Any(x => x.Referencers.SetEquals(new []{D , E})));
            //1 {C -> A , X}
            //2 {C -> A}     SELECT
            //3 {C -> X}
            //4 {D -> X , B}
            //5 {D -> X}
            //6 {C , D -> X}
            //7 {D -> B}
            //8 {E -> B}
            //9 {D, E -> B}  Most referencers, Remove all posibilities of X
        }
예제 #7
0
 public static ArchViewModel TreeModelToArchViewModel(Node model,bool dependencyDown, bool hideAnonymousNodes)
 {
     _pallette = new HueRangeDivisor(model.Height());
     return new ArchViewModel
     {
         Layers = PaintAndMapNodes(model.Childs,dependencyDown, hideAnonymousNodes)
     };
 }
예제 #8
0
 private static Node GetSolutionFolderNode(Project folder)
 {
     var node = new Node(folder.Name);
     var childs = folder.ProjectItems.Cast<ProjectItem>().Where(x => x.SubProject != null)
         .Select(x => GetProjectItemNode(x.SubProject)).ToList();
     node.AddChilds(childs);
     return node;
 }
예제 #9
0
 public static Node AddClassesInDocument(Document doc)
 {
     var semanticModels = doc.GetSemanticModelAsync().Result;
     var classes = SemanticModelWalker.GetClassesInModel(semanticModels).ToList();
     DependencyResolver.ResolveDependencies(classes);
     var docNode = new Node(doc.Name);
     docNode.AddChilds(BuildTreeFromClasses(classes));
     return docNode;
 }
예제 #10
0
 public static Node AncestorIsSibling(Node parent, Node dependency)
 {
     for (var p = dependency; p != null; p = p.Parent)
     {
         if (p.Parent?.Id == parent.Id)
             return p;
     }
     return null;
 }
예제 #11
0
 private static new void Apply(Node tree)
 {
     var projects = tree.Projects();
     var withDefaultNamespaces = projects.Where(p => p.Childs.Count() == 1 && p.Childs.First().Name == p.Name);
     foreach (var projectNode in withDefaultNamespaces)
     {
         var childNode = projectNode.Childs.First();
         TakeOver(projectNode, childNode);
     }
 }
예제 #12
0
        public void FindCircularReference()
        {
            var a = new Node("A");
            var b = new Node("B");

            a.SiblingDependencies.Add(b);
            b.SiblingDependencies.Add(a);

            var newList = SiblingReorderer.OrderChildsBySiblingsDependencies(new List<Node> { a , b });
            Assert.IsTrue(newList.First() is CircularDependencyHolderNode);
        }
예제 #13
0
        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)");
        }
예제 #14
0
 private static IEnumerable<ClassNode> FindClasses(Node tree)
 {
     foreach (var child in tree.Childs)
     {
         if (child is ClassNode)
             yield return child as ClassNode;
         else
         {
             foreach (var node in FindClasses(child))
                 yield return node;
         }
     }
 }
예제 #15
0
        public void FindsDirectionBetweenMultiLayers()
        {
            var a = new Node("A");//-
            var b = new Node("B");//^
            var c = new Node("C");//^^

            c.SiblingDependencies.Add(b);
            c.SiblingDependencies.Add(a);
            b.SiblingDependencies.Add(a);

            var newList = SiblingReorderer.LayOutSiblingNodes(new HashSet<Node> { c,b,a});
            Assert.IsTrue(newList.SequenceEqual(new List<Node> {a,b,c}));
        }
예제 #16
0
        public void ClonesChildren()
        {
            var child = new Node("c1");
            var parent = new ClassNode(null, null, 1);
            parent.AddChild(child);
            var parent2 = parent.DeepClone();

            //Assert
            parent2.Childs.Should()
                .NotBeEmpty()
                .And.NotContain(child);
            parent2.Childs.First().Name.Should().Be("c1");
        }
예제 #17
0
 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"));
 }
예제 #18
0
        public void ModifyingClonedTreeDoesNotModifyOriginal()
        {
            var originalChild1 = new Node("c1");
            var parent = new ClassNode(null, null, 1);
            parent.AddChild(originalChild1);

            var clonedParent = parent.DeepClone();
            var clonedParent2 = parent.DeepClone();
            clonedParent.FilterAllChilds();

            // Assert:
            clonedParent.Childs.Should().BeEmpty();
            clonedParent2.Childs.Should().NotBeEmpty();
        }
예제 #19
0
        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);
        }
예제 #20
0
 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());
 }
예제 #21
0
        public void DiscoversAnonymousLayer()
        {
            var a = new Node("A");
            var b = new Node("B");
            var c = new Node("C");

            b.SiblingDependencies.Add(a);
            c.SiblingDependencies.Add(a);

            var newSiblings = SiblingReorderer.OrderChildsBySiblingsDependencies(new List<Node> {a, b, c});

            var anonymousLayer = newSiblings.OfType<SiblingHolderNode>().LastOrDefault();
            Assert.IsNotNull(anonymousLayer);
            CollectionAssert.Contains(anonymousLayer.Childs.ToArray(),b);
            CollectionAssert.Contains(anonymousLayer.Childs.ToArray(), c);
        }
예제 #22
0
        public static void RemoveNodesWithMoreDepthThan(Node tree, int maxDepth, int currDepth = -1)
        {
            if (!(tree is SiblingHolderNode))
                currDepth += 1;

            if (currDepth == maxDepth)
            {
                tree.FilterAllChilds();
            }
            else
            {
                foreach (var child in tree.Childs)
                {
                    RemoveNodesWithMoreDepthThan(child, maxDepth, currDepth);
                }
            }
        }
예제 #23
0
        public static Node FindSiblingDependencies(Node node)
        {
            node.SetChildren(node.Childs.Select(FindSiblingDependencies).ToList());
            if (node.Parent == null) return node;
            var allSubDependencies = node.AllSubDependencies().ToList();
            var dependenciesWhereAncestorsAreSiblings = allSubDependencies
                .Select(dependency => AncestorIsSibling(node.Parent, dependency)).ToList();
            foreach (
                var sibling in
                    dependenciesWhereAncestorsAreSiblings
                        .Where(sibling => sibling != null && sibling != node))
            {
                node.SiblingDependencies.Add(sibling);
            }

            return node;
        }
예제 #24
0
        public void SolvesCircularReferenceInvolvingMoreThreeComponents()
        {
            var top = new Node("top");
            var left = new Node("left");
            var right = new Node("right");

            //Left and right depend on eachother
            left.SiblingDependencies.Add(right);
            right.SiblingDependencies.Add(left);
            //Left depends on top, top depends on right
            left.SiblingDependencies.Add(top);
            top.SiblingDependencies.Add(right);

            var childList = new HashSet<Node> { top, left, right };
            CircularReferenceFinder.FindCircularReferences(childList);
            Assert.AreEqual(typeof(CircularDependencyHolderNode), childList.First().GetType());
            //TODO: Define wanted behaviour
        }
예제 #25
0
        public void ClonesDependencies()
        {
            var originalChild1 = new Node("c1");
            var originalChild2 = new Node("c2");
            var parent = new ClassNode(null, null, 1);
            parent.AddChild(originalChild1);
            parent.AddChild(originalChild2);
            originalChild1.Dependencies.Add(originalChild2);

            var parent2 = parent.DeepClone();

            var clonedChild1 = parent2.Childs.WithName("c1");
            var clonedChild2 = parent2.Childs.WithName("c2");
            //Assert
            clonedChild1.Dependencies.Should()
                .Contain(clonedChild2)
                .And
                .NotContain(originalChild2);
        }
예제 #26
0
        public void FindDependencyGroupsTest2()
        {
            Node A = new Node(nameof(A));
            Node B = new Node(nameof(B));
            Node C = new Node(nameof(C));

            A.SiblingDependencies.Add(B);
            A.SiblingDependencies.Add(C);

            //0.  B   C
            //1.    A
            var firstLayer = new List<Node> { A, B, C };
            var nextLayer = new List<Node> { A, B, C };
            var dependencies = SiblingReorderer.FindDependencies(firstLayer, nextLayer).ToList();
            var groups = SiblingReorderer.FindPotentialDependencyGroups(dependencies);
            groups.Count().Should().Be(3);
            Assert.IsTrue(groups.Last().Dependants.SetEquals(new List<Node>{B,C}));
            //1 {A -> B , C}
            //2 {A -> B}
            //3 {A -> C}
        }
예제 #27
0
        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);
        }
예제 #28
0
        public void RemovesNodesFromNextTargetGroupedThatArePartOfNestedGroup()
        {
            //Produes duplicate RootScope
            Node rootScope = new Node(nameof(rootScope));
            Node diagramSymbol = new Node(nameof(diagramSymbol));
            Node layerMapper = new Node(nameof(layerMapper)) { SiblingDependencies = { diagramSymbol } };
            Node diagramDefiniton = new Node(nameof(diagramDefiniton)) { SiblingDependencies = { rootScope } };
            Node diagramDefinitionParser = new Node(nameof(diagramDefinitionParser)) { SiblingDependencies = { diagramDefiniton,rootScope } };

            Node smallClassFilter= new Node(nameof(smallClassFilter));
            Node patternFinder = new Node(nameof(patternFinder));
            Node modelFilterer = new Node(nameof(modelFilterer)) { SiblingDependencies = { smallClassFilter,patternFinder }};
            Node diagramDefinitonGenerator = new Node(nameof(diagramDefinitonGenerator))
            {
                SiblingDependencies = { diagramDefinitionParser, diagramDefiniton,rootScope,modelFilterer }
            };

            var newList = SiblingReorderer.LayOutSiblingNodes(new HashSet<Node>
            {
                rootScope,patternFinder,smallClassFilter,diagramSymbol,diagramDefiniton,diagramDefinitonGenerator,diagramDefinitionParser,layerMapper,modelFilterer
            });

            TestExtesions.TreeAssert.DoesNotContainDuplicates(newList);
        }
예제 #29
0
        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);
        }
예제 #30
0
 private static bool IndirectlyDependsOnItself(Node target,Node current,ref HashSet<Node> traveledPath)
 {
     foreach (var dependency in current.SiblingDependencies)
     {
         if(traveledPath.Contains(dependency))
             continue;
         if (dependency == target)
             return true;
         var newPath = traveledPath.Union(new[]{dependency}).ToHashSet();
         if (IndirectlyDependsOnItself(target, dependency, ref newPath))
         {
             traveledPath = newPath;
             return true;
         }
     }
     return false;
 }