public void Initialize()
        {
            _expectedReportStream = new MemoryStream();
            StreamWriter sw = new StreamWriter(_expectedReportStream);
            sw.Write(Resources.TestResources.ExpectedOutputReportXML);
            sw.Flush();
            _expectedReportStream.Seek(0, SeekOrigin.Begin);

            _report = MSBuildCodeMetricsReport.Deserialize(_expectedReportStream);
        }
 private void RunBuildFailChecks(MSBuildCodeMetricsReport report, TaskMetricList ml)
 {
     ml.ForEach(m =>
     {
         if (!String.IsNullOrEmpty(m.HigherRangeFailMessage))
             if (report.Summary.Metrics.First(metric => metric.MetricName == m.MetricName).Ranges[0].Count > 0)
                 throw new MSBuildCodeMetricsTaskException(m.HigherRangeFailMessage);
         if (!String.IsNullOrEmpty(m.LowerRangeFailMessage))
         {
             var ranges = report.Summary.Metrics.First(metric => metric.MetricName == m.MetricName).Ranges;
             if (ranges[ranges.Count - 1].Count > 0)
                 throw new MSBuildCodeMetricsTaskException(m.LowerRangeFailMessage);
         }
     });
 }
 private void GenerateSummaryReportConsoleOutput(MSBuildCodeMetricsReport report)
 {
     foreach (MetricReport m in report.Summary.Metrics)
     {
         Log.LogMessage("");
         Log.LogMessage(m.ProviderName + ": " + m.MetricName);
         foreach (SummaryRangeReport r in m.Ranges)
         {
             Log.LogMessage(r.Name + ": " + r.Count.ToString());
         }
     }
 }
 private void GenerateFileOutput(MSBuildCodeMetricsReport report)
 {
     Stream outputReportStream = _streamFactory.CreateStream(OutputFileName);
     report.Serialize(outputReportStream);
     _streamFactory.CloseStream(outputReportStream);
 }
 private void GenerateDetailsReportConsoleOutput(MSBuildCodeMetricsReport report)
 {
     foreach (MetricReport m in report.Details.Metrics)
     {
         Log.LogMessage("");
         Log.LogMessage(m.ProviderName + ": " + m.MetricName);
         foreach (MeasureReport measure in m.Measures)
             Log.LogMessage(measure.MeasureName + ": " + measure.Value.ToString());
     }
 }
        private void GenerateConsoleOutput(MSBuildCodeMetricsReport report)
        {
            if (ShowSummaryReport)
                GenerateSummaryReportConsoleOutput(report);

            if (ShowDetailsReport)
                GenerateDetailsReportConsoleOutput(report);
        }
 /// <summary>
 /// Creates a new details report and hooks the parent report.
 /// </summary>
 /// <param name="report">The parent report</param>
 public DetailsReport(MSBuildCodeMetricsReport report)
 {
     _report = report;
 }
        /// <summary>
        /// Generates the report with the specified parameters
        /// </summary>
        /// <param name="metricList">List of metrics to include in the report</param>
        /// <param name="summary">Specify if the summary report should be generated</param>
        /// <param name="details">Specify if the details report should be generated</param>
        /// <returns>the generated report</returns>
        public MSBuildCodeMetricsReport GenerateReport(List<Metric> metricList, bool summary, bool details)
        {
            if (metricList == null)
                throw new ArgumentNullException("metricList");
            if (metricList.Count <= 0)
                throw new ArgumentOutOfRangeException("metricList");
            if (!summary && !details)
                throw new ArgumentOutOfRangeException("", "At least one report must be set to true");

            MSBuildCodeMetricsReport result = new MSBuildCodeMetricsReport();

            foreach (Metric p in metricList)
            {
                if (summary)
                    AppendSummaryReport(result, p.ProviderName, p.MetricName, GetSummaryReport(p.ProviderName, p.MetricName, p.Range));
                if (details)
                    AppendDetailsReport(result, p.ProviderName, p.MetricName, GetDetailedReport(p.ProviderName, p.MetricName));
            }

            return result;
        }
        private void AppendSummaryReport(MSBuildCodeMetricsReport result, string providerName, string metricName,
            IList<SummaryReportRange> summaryReport)
        {
            if (result.Summary == null)
                result.CreateSummary();

            MetricReport metricSummaryReport = result.Summary.AddMetric(providerName, metricName).CreateRanges();

            foreach (SummaryReportRange r in summaryReport)
                metricSummaryReport.AddRange(r.Range.Name, r.Count);
        }
        private void AppendDetailsReport(MSBuildCodeMetricsReport result, string providerName, string metricName, IEnumerable<RunnerMeasure> detailedReport)
        {
            if (result.Details == null)
                result.CreateDetails();

            MetricReport detailsReport = result.Details.AddMetric(providerName, metricName).CreateMeasures();

            foreach (RunnerMeasure rm in detailedReport)
                detailsReport.AddMeasure(rm.MeasureName, rm.Value);
        }
 /// <summary>
 /// Creates a new summary report and hooks the parent report
 /// </summary>
 /// <param name="report">The parent report</param>
 public SummaryReport(MSBuildCodeMetricsReport report)
 {
     _report = report;
 }