예제 #1
0
        /// <summary>
        /// Performs the analysis of the source file.
        /// </summary>
        /// <returns>The analysis result.</returns>
        public FileAnalysis AnalyzeFile()
        {
            if (!System.IO.File.Exists(this.Path))
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.FileDoesNotExist, this.Path);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }

            try
            {
                string[] lines = System.IO.File.ReadAllLines(this.Path);

                this.TotalLines = lines.Length;

                int currentLineNumber = 0;

                var result = new FileAnalysis(this.Path);

                foreach (var line in lines)
                {
                    currentLineNumber++;
                    int visits = this.lineCoverage.Length > currentLineNumber ? this.lineCoverage[currentLineNumber] : -1;

                    var lineCoverageByTestMethod = this.lineCoveragesByTestMethod
                                                   .ToDictionary(l => l.Key, l => new ShortLineAnalysis(l.Value.Length > currentLineNumber ? l.Value[currentLineNumber] : -1));

                    result.AddLineAnalysis(new LineAnalysis(visits, lineCoverageByTestMethod, currentLineNumber, line.TrimEnd()));
                }

                return(result);
            }
            catch (IOException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }
            catch (UnauthorizedAccessException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }
        }
예제 #2
0
        /// <summary>
        /// Performs the analysis of the source file.
        /// </summary>
        /// <returns>The analysis result.</returns>
        internal FileAnalysis AnalyzeFile()
        {
            if (!System.IO.File.Exists(this.Path))
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.FileDoesNotExist, this.Path);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }

            try
            {
                string[] lines = System.IO.File.ReadAllLines(this.Path);

                this.TotalLines = lines.Length;

                int currentLineNumber = 0;

                var result = new FileAnalysis(this.Path);
                ICollection <Branch> branchesOfLine = null;

                foreach (var line in lines)
                {
                    currentLineNumber++;
                    int             visits          = this.lineCoverage.Length > currentLineNumber ? this.lineCoverage[currentLineNumber] : -1;
                    LineVisitStatus lineVisitStatus = this.lineVisitStatus.Length > currentLineNumber ? this.lineVisitStatus[currentLineNumber] : LineVisitStatus.NotCoverable;

                    var lineCoverageByTestMethod = this.lineCoveragesByTestMethod
                                                   .ToDictionary(
                        l => l.Key,
                        l =>
                    {
                        if (l.Value.Coverage.Length > currentLineNumber)
                        {
                            return(new ShortLineAnalysis(l.Value.Coverage[currentLineNumber], l.Value.LineVisitStatus[currentLineNumber]));
                        }
                        else
                        {
                            return(new ShortLineAnalysis(-1, LineVisitStatus.NotCoverable));
                        }
                    });

                    if (this.branches != null && this.branches.TryGetValue(currentLineNumber, out branchesOfLine))
                    {
                        result.AddLineAnalysis(
                            new LineAnalysis(
                                visits,
                                lineVisitStatus,
                                lineCoverageByTestMethod,
                                currentLineNumber,
                                line.TrimEnd(),
                                branchesOfLine.Count(b => b.BranchVisits > 0),
                                branchesOfLine.Count));
                    }
                    else
                    {
                        result.AddLineAnalysis(
                            new LineAnalysis(
                                visits,
                                lineVisitStatus,
                                lineCoverageByTestMethod,
                                currentLineNumber,
                                line.TrimEnd()));
                    }
                }

                return(result);
            }
            catch (IOException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }
            catch (UnauthorizedAccessException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }
        }
예제 #3
0
        /// <summary>
        /// Performs the analysis of the source file.
        /// </summary>
        /// <returns>The analysis result.</returns>
        internal FileAnalysis AnalyzeFile()
        {
            if (!System.IO.File.Exists(this.Path))
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.FileDoesNotExist, this.Path);
                Logger.Error(error);
                return new FileAnalysis(this.Path, error);
            }

            try
            {
                string[] lines = System.IO.File.ReadAllLines(this.Path);

                this.TotalLines = lines.Length;

                int currentLineNumber = 0;

                var result = new FileAnalysis(this.Path);
                List<Branch> branchesOfLine = null;

                foreach (var line in lines)
                {
                    currentLineNumber++;
                    int visits = this.lineCoverage.Length > currentLineNumber ? this.lineCoverage[currentLineNumber] : -1;

                    var lineCoverageByTestMethod = this.lineCoveragesByTestMethod
                        .ToDictionary(l => l.Key, l => new ShortLineAnalysis(l.Value.Length > currentLineNumber ? l.Value[currentLineNumber] : -1));

                    if (this.branches != null && this.branches.TryGetValue(currentLineNumber, out branchesOfLine))
                    {
                        result.AddLineAnalysis(
                            new LineAnalysis(
                                visits,
                                lineCoverageByTestMethod,
                                currentLineNumber,
                                line.TrimEnd(),
                                branchesOfLine.Count(b => b.BranchVisits > 0),
                                branchesOfLine.Count));
                    }
                    else
                    {
                        result.AddLineAnalysis(
                            new LineAnalysis(
                                visits,
                                lineCoverageByTestMethod,
                                currentLineNumber,
                                line.TrimEnd()));
                    }
                }

                return result;
            }
            catch (IOException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return new FileAnalysis(this.Path, error);
            }
            catch (UnauthorizedAccessException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return new FileAnalysis(this.Path, error);
            }
        }
예제 #4
0
        /// <summary>
        /// Performs the analysis of the source file.
        /// </summary>
        /// <returns>The analysis result.</returns>
        internal FileAnalysis AnalyzeFile()
        {
            if (!System.IO.File.Exists(this.Path))
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.FileDoesNotExist, this.Path);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }

            try
            {
                string[] lines = System.IO.File.ReadAllLines(this.Path);
                this.TotalLines = lines.Length;
                int currentLineNumber = 0;
                testlinescount = 0;
                newlinescount  = 0;
                var result = new FileAnalysis(this.Path);
                ICollection <Branch> branchesOfLine = null;
                //string[] files = Directory.GetFiles(@"d:\test2\");
                //string val = this.Path.Split('\\').Last();
                Dictionary <int, string>          diffvalue      = new Dictionary <int, string>();
                List <CompareHelper.BuildChanges> buildlineslist = new List <CompareHelper.BuildChanges>();



                string[] fname = this.Path.Split('\\');
                string   temp  = string.Empty;
                int      len   = fname.Length;
                temp = "\\" + fname[len - 1] + "_"; // + fname[len - 3] + "_" + fname[len - 2] + "_"
                string reportPath = @System.Configuration.ConfigurationManager.AppSettings["ComparePath"] + temp + "_report.xml";

                if (File.Exists(reportPath))
                {
                    diffvalue = CompareHelper.Report(reportPath);
                }
                buildlineslist = Reporting.ReportGenerator.buildclasses;
                foreach (var line in lines)
                {
                    currentLineNumber++;
                    int             visits          = this.lineCoverage.Length > currentLineNumber ? this.lineCoverage[currentLineNumber] : -1;
                    LineVisitStatus lineVisitStatus = this.lineVisitStatus.Length > currentLineNumber ? this.lineVisitStatus[currentLineNumber] : LineVisitStatus.NotCoverable;
                    LineVisitStatus tempstatus      = lineVisitStatus;
                    if (diffvalue != null && diffvalue.Count > 0 && diffvalue.ContainsKey(currentLineNumber) && diffvalue[currentLineNumber].Contains(line) && lineVisitStatus != LineVisitStatus.NotCoverable)// && lineVisitStatus != LineVisitStatus.NotCoverable
                    {
                        ChangesCount.Add(currentLineNumber.ToString() + "###" + line);
                        newlinescount++;
                        lineVisitStatus = LineVisitStatus.newline;
                    }
                    else if (buildlineslist != null && buildlineslist.Any(x => x.buildlines.Contains(currentLineNumber.ToString() + "###" + line)) && tempstatus != LineVisitStatus.NotCoverable)
                    {
                        ChangesCount.Add(currentLineNumber.ToString() + "###" + line);
                        newlinescount++;
                        //lineVisitStatus = LineVisitStatus.newline;
                    }
                    if ((diffvalue != null && diffvalue.Count > 0 && diffvalue.ContainsKey(currentLineNumber) && diffvalue[currentLineNumber].Contains(line)) && (tempstatus == LineVisitStatus.Covered))//|| lineVisitStatus == LineVisitStatus.NotCoverable)) //
                    {
                        TestedlinesCount.Add(currentLineNumber.ToString() + "###" + line);
                        testlinescount++;
                        lineVisitStatus = LineVisitStatus.Covered;
                    }
                    if (buildlineslist != null && buildlineslist.Any(x => x.buildtestedlines.Contains(currentLineNumber.ToString() + "###" + line)) && tempstatus != LineVisitStatus.NotCoverable)
                    {
                        TestedlinesCount.Add(currentLineNumber.ToString() + "###" + line);
                        testlinescount++;
                        lineVisitStatus = LineVisitStatus.Covered;
                    }
                    var lineCoverageByTestMethod = this.lineCoveragesByTestMethod
                                                   .ToDictionary(
                        l => l.Key,
                        l =>
                    {
                        if (l.Value.Coverage.Length > currentLineNumber)
                        {
                            return(new ShortLineAnalysis(l.Value.Coverage[currentLineNumber], l.Value.LineVisitStatus[currentLineNumber]));
                        }
                        else
                        {
                            return(new ShortLineAnalysis(-1, LineVisitStatus.NotCoverable));
                        }
                    });

                    if (this.branches != null && this.branches.TryGetValue(currentLineNumber, out branchesOfLine))
                    {
                        result.AddLineAnalysis(
                            new LineAnalysis(
                                visits,
                                lineVisitStatus,
                                lineCoverageByTestMethod,
                                currentLineNumber,
                                line.TrimEnd(),
                                branchesOfLine.Count(b => b.BranchVisits > 0),
                                branchesOfLine.Count));
                    }
                    else
                    {
                        result.AddLineAnalysis(
                            new LineAnalysis(
                                visits,
                                lineVisitStatus,
                                lineCoverageByTestMethod,
                                currentLineNumber,
                                line.TrimEnd()));
                    }
                }
                return(result);
            }
            catch (IOException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }
            catch (UnauthorizedAccessException ex)
            {
                string error = string.Format(CultureInfo.InvariantCulture, " " + Resources.ErrorDuringReadingFile, this.Path, ex.Message);
                Logger.Error(error);
                return(new FileAnalysis(this.Path, error));
            }
        }