Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var artifactRepository = new NodeRepository();

            var solutionRepository = new NodeRepository();

            var finder          = new GraphBuilder(solutionRepository, artifactRepository);
            var circleFormatter = new CircleFormattingService(new NodeFormattingService());
            var solutionPaths   = Directory.GetFiles(@"E:\Cadence\ESIETooLink\Main", "Bhi.Esie.Toolink.sln", SearchOption.AllDirectories);

            solutionPaths.ToList().ForEach(p => {
                finder.BuildArtifactsOfSolution(p);
            });
            artifactRepository.Nodes.ToList().ForEach(n => {
                finder.ResolveDependencies((ArtifactNode)n);
            });

            // Here we've built the graph, would be nice to show it, wouldn't it

            var circleService = new CirclesService();

            solutionRepository.Nodes.ToList().ForEach(node =>
            {
                var circles = circleService.FindCircles(node);
                if (circles.Any())
                {
                    Console.WriteLine($"{node.Name} {circles.Count()}");
                    circles.ToList().ForEach(circle => Console.WriteLine(circleFormatter.FormatCircle(circle)));
                }
            });
        }
        public void ManyNode()
        {
            var circlesService = new CirclesService();
            var nodeRepository = new NodeRepository();
            var nodeA          = new Node("a");
            var nodeB          = new Node("b");
            var nodeC          = new Node("c");
            var nodeD          = new Node("d");
            var nodeE          = new Node("e");
            var nodeF          = new Node("f");
            var nodeG          = new Node("g");
            var nodeH          = new Node("h");

            nodeA.Add(nodeC).Add(nodeG);
            nodeB.Add(nodeC).Add(nodeH);
            nodeC.Add(nodeE);
            nodeD.Add(nodeA).Add(nodeB);
            nodeE.Add(nodeD);
            nodeF.Add(nodeE);
            nodeH.Add(nodeA);

            IList <ICircle> circles = circlesService.FindCircles(nodeE);

            Assert.IsNotNull(circles, "Even when there is no circle, there should be a valid list");
            Assert.AreEqual(1, circles.Count, "list should have one circle");
            Assert.AreEqual("e,d,a,c,e", circles[0].ToString());
        }
        public void RepoSolutionCircle()
        {
            var circlesService = new CirclesService();
            var solutionA      = new SolutionNode("SolutionA");
            var solutionB      = new SolutionNode("SolutionB");
            var solutionC      = new SolutionNode("SolutionC");
            var artifactA      = solutionA.CreatesArtifact("ArtifactA", "a");
            var artifactD      = solutionA.CreatesArtifact("ArtifactD", "d");

            var artifactB = solutionB.CreatesArtifact("ArtifactB", "b");
            var artifactC = solutionC.CreatesArtifact("ArtifactC", "c");

            // the circle
            artifactA.DependsOn(artifactB);
            artifactB.DependsOn(artifactC);
            artifactC.DependsOn(artifactD);

            NodeRepository repo = new NodeRepository();

            repo.Add(solutionA);
            repo.Add(solutionB);
            repo.Add(solutionC);
            IList <ICircle> circles = circlesService.FindCircles(repo);

            Assert.IsNotNull(circles, "Even when there is no circle, there should be a valid list");
            Assert.AreEqual(1, circles.Count, "list should have one circles");
            Assert.AreEqual("SolutionA:ArtifactA,SolutionB:ArtifactB,SolutionC:ArtifactC,SolutionA:ArtifactD", circles[0].ToString());
        }
        public void OneNode()
        {
            var circlesService = new CirclesService();
            var nodeRepository = new NodeRepository();
            var node           = new Node("a");

            nodeRepository.Add(node);

            IList <ICircle> circles = circlesService.FindCircles(node);

            Assert.IsNotNull(circles, "Even when there is no circle, there should be a valid list");
            Assert.AreEqual(0, circles.Count, "list should be empty");
        }
        public void TwosNode()
        {
            var circlesService = new CirclesService();
            var nodeRepository = new NodeRepository();
            var nodeA          = new Node("a");
            var nodeB          = new Node("b");

            nodeA.Children.Add(nodeB);
            nodeB.Children.Add(nodeA);
            nodeRepository.Add(nodeA);

            IList <ICircle> circles = circlesService.FindCircles(nodeA);

            Assert.IsNotNull(circles, "Even when there is no circle, there should be a valid list");
            Assert.AreEqual(1, circles.Count, "list should have two circles");
        }