Exemple #1
0
        /// <summary>
        /// Try to get the total visited points
        /// </summary>
        /// <param name="totals">The visited point counts if running under AltCover coverage</param>
        /// <returns>True if running under AltCover coverage</returns>
        /// <remarks>Current implementation requires `dotnet test`, or other command-line testing with `--defer` set, in which the cumulative visit numbers are available, rather than everything having been dumped to file instead.</remarks>
        public static bool TryGetVisitTotals(out PointCount totals)
        {
            var counter = TypeInstance("Counter");

            totals = new PointCount();
            var found = false;

            foreach (var t in counter)
            {
                var temp = (Int64)t.GetProperty("branchVisits",
                                                System.Reflection.BindingFlags.NonPublic |
                                                System.Reflection.BindingFlags.Public |
                                                System.Reflection.BindingFlags.Static).GetValue(null, Type.EmptyTypes);
                totals.Branch = (int)temp;

                temp = (Int64)t.GetProperty("totalVisits",
                                            System.Reflection.BindingFlags.NonPublic |
                                            System.Reflection.BindingFlags.Public |
                                            System.Reflection.BindingFlags.Static).GetValue(null, Type.EmptyTypes);
                totals.Code = (int)temp - totals.Branch;

                found = true;
            }

            return(found);
        }
Exemple #2
0
#pragma warning restore IDE0079 // Remove unnecessary suppression
        public static bool TryGetPointTotals(out PointCount totals)
        {
            var instance = TypeInstance("Instance");

            totals = new PointCount();
            var found = false;

            foreach (var i in instance)
            {
                var xml = i.GetProperty("ReportFile").GetValue(null, Type.EmptyTypes).ToString();
                using (var file = File.OpenRead(xml))
                    using (var scans = new Carrier())
                    {
                        var doc = new XmlDocument();
                        doc.Load(file);
                        var seqpnt = scans.Add(doc.DocumentElement.SelectNodes("//seqpnt")).Count;
                        var sp2    = scans.Add(doc.DocumentElement.SelectNodes("//SequencePoint")).Count;

                        foreach (XmlElement m in scans.Add(doc.DocumentElement.SelectNodes("//Method")))
                        {
                            if (scans.Add(m.SelectNodes(".//SequencePoint")).Count == 0)
                            {
                                sp2++;
                            }
                        }

                        totals.Branch = scans.Add(doc.DocumentElement).SelectNodes("//BranchPoint").Count;
                        totals.Code   = Math.Max(seqpnt, sp2);
                        found         = true;
                    }
            }

            return(found);
        }