public void GetCoverage_OneMethodFullCoverage_100()
 {
     CoveredAssembly ca = new CoveredAssembly();
     ca.Methods.Add(new CoveredMethod() { CodeSize = 100, CoveredCodeSize = 100 });
     double coverage = ca.GetCoverage();
     Assert.AreEqual(100, coverage);
 }
        public void GetCoverage_TwoMethodsSomeCoverage_100()
        {
            CoveredAssembly ca = new CoveredAssembly();
            CoveredMethod method1 = new CoveredMethod() { CodeSize = 100, CoveredCodeSize = 100 };
            CoveredMethod method2 = new CoveredMethod() { CodeSize = 100, CoveredCodeSize = 0 };
            ca.Methods.Add(method1);
            ca.Methods.Add(method2);

            double coverage = ca.GetCoverage();
            Assert.AreEqual(50, coverage);
        }
        public static CoveredAssemblySet AnalyzeCoverage(XmlDocument doc)
        {
            XmlNodeList assemblyNodes = doc.SelectNodes("PartCoverReport/Assembly");
            CoveredAssemblySet assemblies = new CoveredAssemblySet();
            foreach (XmlNode assemblyNode in assemblyNodes)
            {
                CoveredAssembly assembly = new CoveredAssembly();
                assemblies.Add(assembly);
                assembly.Name = assemblyNode.Attributes["name"].Value;
                string id = assemblyNode.Attributes["id"].Value;

                string xpath = "//Type[@asmref=" + id + "]/Method";
                XmlNodeList methods = doc.SelectNodes(xpath);

                foreach (XmlNode method in methods)
                {

                    string typeName = method.ParentNode.Attributes["name"].Value;

                    CoveredMethod m = new CoveredMethod();
                    m.Name = method.Attributes["name"].Value;
                    m.TypeName = typeName;
                    assembly.Methods.Add(m);

                    XmlNodeList ptNodes = method.SelectNodes("pt");

                    if (ptNodes.Count == 0)
                    {
                        m.CodeSize += int.Parse(method.Attributes["bodysize"].Value);
                    }
                    else
                    {
                        foreach (XmlNode ptNode in ptNodes)
                        {
                            int length = int.Parse(ptNode.Attributes["len"].Value);
                            int visit = int.Parse(ptNode.Attributes["visit"].Value);
                            m.CodeSize += length;
                            if (visit > 0)
                            {
                                m.CoveredCodeSize += length;
                            }
                        }
                    }
                }
            }
            return assemblies;
        }
        public void LogEvent_BuildFailure_AddEvent_EvellntAdded()
        {
            Settings settings = new Settings();
            settings.BasePath = @"c:\";

            StatisticsLoggerStub stub = new StatisticsLoggerStub();
            
            ProcessResult r = new ProcessResult();
            r.TestResults.CoveredAssemblies = new CoveredAssemblySet();
            CoveredAssembly assembly = new CoveredAssembly();
            assembly.Name = "thename";
            r.TestResults.CoveredAssemblies.Add(assembly);
            
            stub.LogStatistics(settings, r);

            Assert.AreEqual(1, stub.XmlDocument.SelectNodes("timestamps/timestamp/assembly[@id='thename']").Count);
            Assert.IsTrue(stub.IsSaved);
        }
 public void GetCoverage_NoMethods_0()
 {
     CoveredAssembly ca = new CoveredAssembly();
     double coverage = ca.GetCoverage();
     Assert.AreEqual(0, coverage);
 }