public void empty_graphs_merge_to_empty_graph()
 {
     var graph1 = new AffectedGraph();
     var graph2 = new AffectedGraph();
     var merged = graph1.Merge(graph2);
     Assert.AreEqual(0, merged.AllNodes().Count());
 }
 private void AddConnections(AffectedGraph to, IEnumerable <NodeConnection> allConnections)
 {
     foreach (var c in allConnections)
     {
         to.AddConnection(c.From, c.To, c.IsForward);
     }
 }
 public void SetUp()
 {
     var paths = new[]
                     {
                         new List<string> {"GrandChild", "Child3", "Root"},
                     };
     _graph = GraphBuilder.BuildGraphFor(paths);
 }
 public int CalculateRiskFor(AffectedGraph g)
 {
     var root = g.AllNodes().FirstOrDefault(x => x.IsRootNode);
     if (root == null) return -1;
     var connections = GetHashFrom(g);
     var risk = RecurseRisk(root.FullName, connections, new Dictionary<string, bool>());
     if (risk.nottested + risk.tested == 0) return 0;
     return (int)(risk.tested / (decimal)(risk.nottested + risk.tested) * 100.0m);
 }
 public void a_node_can_be_added()
 {
     var g = new AffectedGraph();
     g.AddNode(new AffectedGraphNode("foo", false, false, false, "name", "bar::foo", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     Assert.AreEqual(1, g.AllNodes().Count());
     Assert.AreEqual("foo", g.AllNodes().First().DisplayName);
     Assert.AreEqual("bar::foo", g.AllNodes().First().FullName);
     Assert.IsNotNull(g.GetNode("bar::foo"));
 }
 public void nodes_from_both_graphs_get_added_to_output()
 {
     var graph1 = new AffectedGraph();
     graph1.AddNode(new AffectedGraphNode("test1", false, false, false, "test", "test12", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     var graph2 = new AffectedGraph();
     graph2.AddNode(new AffectedGraphNode("test1", false, false, false, "test", "test123", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     var merged = graph1.Merge(graph2);
     Assert.AreEqual(2, merged.AllNodes().Count());
 }
 public AffectedGraph Merge(AffectedGraph graph2)
 {
     var ret = new AffectedGraph();
     AddIfNotExist(ret, this.AllNodes());
     AddIfNotExist(ret, graph2.AllNodes());
     AddConnections(ret, this.AllConnections());
     AddConnections(ret, graph2.AllConnections());
     return ret;
 }
 public int CalculateRiskFor(AffectedGraph graph)
 {
     if (graph == null) return 0;
     var root = graph.GetRootNode();
     if (root == null) return 0;
     var connections = GraphNodeHashBuilder.GetHashFrom(graph);
     var risk = RecurseRisk(root.FullName, connections, new Dictionary<string, bool>());
     if (risk.nottested + risk.tested == 0) return 0;
     return (int)(risk.tested / (decimal)(risk.nottested + risk.tested) * 100.0m);
 }
        public AffectedGraph Merge(AffectedGraph graph2)
        {
            var ret = new AffectedGraph();

            AddIfNotExist(ret, this.AllNodes());
            AddIfNotExist(ret, graph2.AllNodes());
            AddConnections(ret, this.AllConnections());
            AddConnections(ret, graph2.AllConnections());
            return(ret);
        }
 private void AddIfNotExist(AffectedGraph to, IEnumerable<AffectedGraphNode> nodes)
 {
     int x = 5;
     foreach (var node in nodes)
     {
         if (!to.ContainsNode(node.FullName))
         {
             to.AddNode(node);
         }
     }
 }
        private void AddIfNotExist(AffectedGraph to, IEnumerable <AffectedGraphNode> nodes)
        {
            int x = 5;

            foreach (var node in nodes)
            {
                if (!to.ContainsNode(node.FullName))
                {
                    to.AddNode(node);
                }
            }
        }
 public int CalculateRiskFor(AffectedGraph graph)
 {
     //TODO make interface take the hash not the graph (so it canbe reused between strategies instead of built n times)
     if (graph == null) return 0;
     var root = graph.GetRootNode();
     if (root == null) return 0;
     var visited = new Dictionary<string, int>();
     var hash = GraphNodeHashBuilder.GetHashFrom(graph);
     var testsScore = RecurseFrom(root.FullName, hash, 0, 0, visited);
     var complexity = root.Complexity > 1.0m ? root.Complexity : 1.0m;
     var overallScore = testsScore/complexity;
     var ret = overallScore > 1.0m ? 1.0m : overallScore;
     return (int) (ret * 100m);
 }
 public void single_node_in_graph_that_is_not_a_test()
 {
     var graph = new AffectedGraph();
     graph.AddNode(new AffectedGraphNode(displayName: "display",
                                         isInterface: false,
                                         isTest: false,
                                         isRootNode: true,
                                         name: "A name",
                                         fullName: "name",
                                         assembly: "foo.dll",
                                         type: "Type",
                                         testDescriptors: new List<TestDescriptor>(),
                                         isChange: false, inTestAssembly: false, complexity:0));
     var classifier = new TestPathsGraphRiskClassifier();
     Assert.AreEqual(0, classifier.CalculateRiskFor(graph));
 }
 public static Dictionary<string, RiskNode> GetHashFrom(AffectedGraph graph)
 {
     var ret = new Dictionary<string, RiskNode>();
     foreach (var node in graph.AllNodes())
     {
         ret.Add(node.FullName, new RiskNode() { Node = node });
     }
     foreach (var connection in graph.AllConnections())
     {
         RiskNode item;
         if (!ret.TryGetValue(connection.From, out item))
         {
             ret.Add(connection.From, item);
         }
         item.connections.Add(connection.To);
     }
     return ret;
 }
 public void single_node_nodein_graph_that_is_a_covered_test()
 {
     var graph = new AffectedGraph();
     graph.AddNode(new AffectedGraphNode(displayName: "display",
                                         isInterface: false,
                                         isTest: true,
                                         isRootNode: true,
                                         name: "A name",
                                         fullName: "name",
                                         assembly: "foo.dll",
                                         type: "Type",
                                         testDescriptors: new List<TestDescriptor>(),
                                         isChange: false,
                                         inTestAssembly: false,
                                         complexity: 0));
     graph.AllNodes().First().MarkAsProfiled();
     var classifier = new CoverageDistanceAndComplexityGraphRiskClassifier();
     Assert.AreEqual(100, classifier.CalculateRiskFor(graph));
 }        
 public static AffectedGraph BuildGraphFor(IEnumerable<IEnumerable<string>> paths)
 {
     bool first = true;
     var ret = new AffectedGraph();
     foreach(var path in paths)
     {
         string last = null;
         foreach(var node in path)
         {
             if(!ret.ContainsNode(node))
             {
                 ret.AddNode(new AffectedGraphNode(node, false, false, first, node, node, "", "", new List<TestDescriptor>(), false, false, 0));
                 first = false;
             }
             if(last != null)
             {
                 ret.AddConnection(last, node, false);
             }
             last = node;
         }
     }
     return ret;
 }
 private void AddConnections(AffectedGraph to, IEnumerable<NodeConnection> allConnections)
 {
     foreach(var c in allConnections) to.AddConnection(c.From, c.To, c.IsForward);
 }
 public void a_connection_from_a_non_existant_node_does_not_add_connection()
 {
     var g = new AffectedGraph();
     g.AddNode(new AffectedGraphNode("foo", false, false, false, "name", "bar::foo", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     g.AddConnection("somethingnon-existant", "bar::foo", false);
     Assert.AreEqual(0, g.AllConnections().Count());
 }
 public void connection_can_be_added_between_same_nodes()
 {
     var g = new AffectedGraph();
     g.AddNode(new AffectedGraphNode("foo", false, false, false, "name", "bar::foo", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     g.AddConnection("bar::foo", "bar::foo", false);
     Assert.AreEqual(1, g.AllConnections().Count());
 }
 public void multiple_connections_can_be_added_between_two_valid_nodes_but_only_one_appears()
 {
     var g = new AffectedGraph();
     g.AddNode(new AffectedGraphNode("foo", false, false, false, "name", "bar::foo", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     g.AddNode(new AffectedGraphNode("foo", false, false, false, "name", "bar::foo2", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     g.AddConnection("bar::foo2", "bar::foo", false);
     g.AddConnection("bar::foo2", "bar::foo", false);
     Assert.AreEqual(1, g.AllConnections().Count());
 }
 public void adding_a_null_to_connection_does_not_add_node()
 {
     var g = new AffectedGraph();
     g.AddConnection("FROM", null, false);
     Assert.AreEqual(0, g.AllConnections().Count());
 }
 public void adding_a_null_node_does_not_add_node()
 {
     var g = new AffectedGraph();
     g.AddNode(null);
     Assert.AreEqual(0, g.AllNodes().Count());
 }
 public void when_no_root_node_get_root_node_returns_null()
 {
     var g = new AffectedGraph();
     g.AddNode(new AffectedGraphNode("foo", false, false, false, "name", "bar::foo", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     Assert.IsNull(g.GetRootNode());
 }
 public void when_root_node_get_root_node_returns_root_node()
 {
     var g = new AffectedGraph();
     var root = new AffectedGraphNode("foo", false, false, true, "name", "bar::foo", "assembly", "type", new List<TestDescriptor>(), false, false, 0);
     g.AddNode(root);
     g.AddNode(new AffectedGraphNode("foo", false, false, false, "name", "bar::foo2", "assembly", "type", new List<TestDescriptor>(), false, false, 0));
     Assert.AreEqual(root, g.GetRootNode());
 }
 public void adding_null_node_throws_argument_null_exception()
 {
     var graph = new AffectedGraph();
     //Assert.Throws<ArgumentNullException>(() => graph.AddNode(null));
 }
 public AffectedGraph GetProfiledGraphFor(string method)
 {
     var graph = new AffectedGraph();
     var tests = GetTestsFor(method);
     if (tests == null || !tests.Any()) return graph;
     var paths = new List<IEnumerable<string>>();
     foreach(var test in tests)
     {
         var info = GetTestInformationFor(test);
         if (info != null)
         {
             var path = PathFinder.FindPathsTo(info, method);
             paths.AddRange(path);
         }
     }
     return GraphBuilder.BuildGraphFor(paths);
 }
 public void node_and_direct_test_in_graph()
 {
     var graph = new AffectedGraph();
     graph.AddNode(new AffectedGraphNode(displayName: "display",
                                         isInterface: false,
                                         isTest: false,
                                         isRootNode: true,
                                         name: "A name",
                                         fullName: "fullnamecode",
                                         assembly: "foo.dll",
                                         type: "Type",
                                         testDescriptors: new List<TestDescriptor>(),
                                         isChange: false, inTestAssembly: false, complexity:0));
     graph.AddNode(new AffectedGraphNode(displayName: "display",
                                         isInterface: false,
                                         isTest: true,
                                         isRootNode: true,
                                         name: "A name",
                                         fullName: "fullnametest",
                                         assembly: "foo.dll",
                                         type: "Type",
                                         testDescriptors: new List<TestDescriptor>(),
                                         isChange: false, inTestAssembly: true, complexity:0));
     graph.AddConnection("fullnamecode", "fullnametest", false);
     var classifier = new TestPathsGraphRiskClassifier();
     Assert.AreEqual(100, classifier.CalculateRiskFor(graph));
 }