Esempio n. 1
0
        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"));
        }
Esempio n. 2
0
 public AffectedGraph GetAffectedGraphForChangeSet(IEnumerable<Change<MethodReference>> changes)
 {
     InvokeMinimizerMessage(MessageType.Debug, "getting tests for changes");
     var start = DateTime.Now;
     var graph = new AffectedGraph();
     var breadCrumbs = new Dictionary<string, bool>();
     var affectedItems = GetAffectedItems(changes, graph);
     var rets = affectedItems.ForkAndJoinTo(_numthreads, x =>
                                                             {
                                                                 var tmp = new AffectedGraph();
                                                                 FillAfferentGraph(x.Member, breadCrumbs,
                                                                                   tmp, null, 0, null, false,
                                                                                   new List<string>(),
                                                                                   GenericContext.Empty(), false);
                                                                 return tmp;
                                                             });
     InvokeMinimizerMessage(MessageType.Debug, "there are " + rets.Count() + " graphs returned. Combining.");
     foreach(var g in rets)
     {
         if (g != null)
         {
             InvokeMinimizerMessage(MessageType.Debug,
                                    "there are " + g.AllNodes().Count() + " Nodes in graph. TOTAL=" +
                                    graph.AllNodes().Count());
             graph = graph.Merge(g);
         }
     }
     InvokeMinimizerMessage(MessageType.Debug, "there are " + rets.Count() + " nodes in combined graph."); 
     var end = DateTime.Now;
     InvokeMinimizerMessage(MessageType.Debug, "took " + (end - start) + " to walk graph");
     return graph;
 }
 private static void ConvertToGraphMessage(VisualGraphGeneratedMessage message, AffectedGraph graph)
 {
     foreach (var node in graph.AllNodes())
     {
         message.Nodes.Add(new GraphNode
         {
             Assembly       = node.Assembly,
             DisplayName    = node.DisplayName,
             FullName       = node.FullName,
             IsInterface    = node.IsInterface,
             IsChange       = node.IsChange,
             IsRootNode     = node.IsRootNode,
             IsTest         = node.IsTest,
             Name           = node.Name,
             Type           = node.Type,
             InTestAssembly = node.InTestAssembly,
             IsProfiledTest = node.Profiled,
             Complexity     = node.Complexity,
         });
     }
     foreach (var c in graph.AllConnections())
     {
         message.Connections.Add(new Connection {
             From = c.From, To = c.To
         });
     }
 }
Esempio n. 4
0
        public void adding_a_null_node_does_not_add_node()
        {
            var g = new AffectedGraph();

            g.AddNode(null);
            Assert.AreEqual(0, g.AllNodes().Count());
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        private 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);
        }
 private IEnumerable<TestEntry> BuildEntriesFor(AffectedGraph graph)
 {
     InvokeMinimizerMessage(MessageType.Info, "there are " + graph.AllNodes().Count() + "in the graph.");
     foreach(var n in graph.AllNodes())
     {
         if (n.TestDescriptors == null) continue;
         foreach (var desc in n.TestDescriptors)
         {
             yield return new TestEntry
                              {
                                  TestAssembly = n.Assembly,
                                  TestClass = n.Type,
                                  TestName = desc.Target,
                                  TestRunners = new List<string> {desc.TestRunner}
                              };
         }
     }
 }
Esempio n. 9
0
 static IEnumerable<TestDescriptor> GetTestsInGraph(AffectedGraph graph)
 {
     return graph.AllNodes().Where(entry => entry.IsTest).SelectMany(entry => entry.TestDescriptors);
 }
 private static void ConvertToGraphMessage(VisualGraphGeneratedMessage message, AffectedGraph graph)
 {
     foreach (var node in graph.AllNodes())
     {
         message.Nodes.Add(new GraphNode
                           {
                               Assembly = node.Assembly,
                               DisplayName = node.DisplayName,
                               FullName = node.FullName,
                               IsInterface = node.IsInterface,
                               IsChange = node.IsChange,
                               IsRootNode = node.IsRootNode,
                               IsTest = node.IsTest,
                               Name = node.Name,
                               Type = node.Type,
                               InTestAssembly = node.InTestAssembly,
                               IsProfiledTest = node.Profiled,
                               Complexity = node.Complexity,
                           });
     }
     foreach (var c in graph.AllConnections())
     {
         message.Connections.Add(new Connection {From = c.From, To = c.To});
     }
 }
Esempio n. 11
0
 public void EnrichGraph(AffectedGraph graph)
 {
     foreach (var node in graph.AllNodes())
     {
         var cachenode = TryGetEfferentCouplingNode(node.FullName.Replace('+', '/'));
         if (cachenode != null)
         {
             var r = cachenode.MemberReference;
             if (r != null)
             {
                 node.DisplayName = r.DeclaringType.Name + "::" + r.Name;
                 node.Assembly = r.Module.Assembly.FullName;
                 node.IsInterface = r.DeclaringType.ThreadSafeResolve().IsInterface;
             }
             node.Profiled = true;
             node.IsTest = _testIdentifiers.IsTest(cachenode.MemberReference);
         }
     }
 }
Esempio n. 12
0
 public void the_graph_has_3_nodes()
 {
     Assert.AreEqual(3, _graph.AllNodes().Count());
 }