public void AddMetric_AddSingleMetric_MetricIsStored() { MethodMetric sut = new MethodMetric("Test"); var metric = new Metric("Metric1", 10); sut.AddMetric(metric); Assert.AreEqual(metric, sut.Metrics.First(), "Not equal"); Assert.AreEqual(1, sut.Metrics.Count(), "Wrong number of classes"); }
public void Equals() { var target1 = new MethodMetric("Test"); var target2 = new MethodMetric("Test"); var target3 = new MethodMetric("Other"); Assert.IsTrue(target1.Equals(target2), "Objects are not equal"); Assert.IsFalse(target1.Equals(target3), "Objects are equal"); Assert.IsFalse(target1.Equals(null), "Objects are equal"); Assert.IsFalse(target1.Equals(new object()), "Objects are equal"); }
public void Merge_MergeMethodMetric_MetricsAreStored() { var metric1 = new Metric("Metric1", 10); var metric2 = new Metric("Metric1", 15); var metric3 = new Metric("Metric2", 20); MethodMetric sut = new MethodMetric("Test", new[] { metric1 }); var methodMetricToMerge = new MethodMetric("Test", new[] { metric2, metric3 }); sut.Merge(methodMetricToMerge); Assert.AreEqual(2, sut.Metrics.Count(), "Wrong number of classes"); Assert.AreEqual(metric1, sut.Metrics.First(), "Not equal"); Assert.AreEqual(15, sut.Metrics.First().Value, "Not equal"); Assert.AreEqual(metric3, sut.Metrics.ElementAt(1), "Not equal"); }
public void Merge_MergeClassWithOneFileAndOneMethodMetric_FileIsStored() { var assembly = new Assembly("C:\\test\\TestAssembly.dll"); var sut = new Class("Test", assembly); var classToMerge = new Class("Test", assembly); var file = new CodeFile("C:\\temp\\Program.cs", new int[0]); var methodMetric = new MethodMetric("Test"); classToMerge.AddFile(file); classToMerge.AddMethodMetric(methodMetric); sut.Merge(classToMerge); Assert.AreEqual(file, sut.Files.First(), "Not equal"); Assert.AreEqual(1, sut.Files.Count(), "Wrong number of classes"); Assert.AreEqual(methodMetric, sut.MethodMetrics.First(), "Not equal"); Assert.AreEqual(1, sut.MethodMetrics.Count(), "Wrong number of method metrics"); }
/// <summary> /// Merges the given method metric with the current instance. /// </summary> /// <param name="methodMetric">The method metric to merge.</param> public void Merge(MethodMetric methodMetric) { if (methodMetric == null) { throw new ArgumentNullException("methodMetric"); } foreach (var metric in methodMetric.metrics) { var existingMetric = this.metrics.FirstOrDefault(m => m.Name == metric.Name); if (existingMetric != null) { existingMetric.Value = Math.Max(existingMetric.Value, metric.Value); } else { this.AddMetric(metric); } } }
/// <summary> /// Adds the given metric values to the report. /// </summary> /// <param name="metric">The metric.</param> public void MetricsRow(MethodMetric metric) { if (metric == null) { throw new ArgumentNullException("metric"); } string metrics = string.Join(" & ", metric.Metrics.Select(m => m.Value.ToString(CultureInfo.InvariantCulture))); string row = string.Format( CultureInfo.InvariantCulture, @"\textbf{{{0}}} & {1}\\", EscapeLatexChars(ShortenString(metric.ShortName, 20)), metrics); this.reportTextWriter.WriteLine(row); this.reportTextWriter.WriteLine(@"\hline"); }
public void Constructor() { MethodMetric sut = new MethodMetric("Test"); Assert.AreEqual("Test", sut.Name, "Not equal"); }
/// <summary> /// Adds the given metric values to the report. /// </summary> /// <param name="metric">The metric.</param> public void MetricsRow(MethodMetric metric) { if (metric == null) { throw new ArgumentNullException("metric"); } this.currentElement.Add(new XElement( ReplaceInvalidXmlChars(metric.Name), metric.Metrics.Select(m => new XElement(ReplaceInvalidXmlChars(m.Name), m.Value)))); }
/// <summary> /// Adds the given metric values to the report. /// </summary> /// <param name="metric">The metric.</param> public void MetricsRow(MethodMetric metric) { if (metric == null) { throw new ArgumentNullException("metric"); } this.reportTextWriter.WriteStartElement(XmlRenderer.ReplaceInvalidXmlChars(metric.ShortName)); foreach (var m in metric.Metrics) { this.reportTextWriter.WriteStartElement(XmlRenderer.ReplaceInvalidXmlChars(m.Name)); this.reportTextWriter.WriteValue(m.Value.ToString(CultureInfo.InvariantCulture)); this.reportTextWriter.WriteEndElement(); } this.reportTextWriter.WriteEndElement(); }
/// <summary> /// Adds the given metric values to the report. /// </summary> /// <param name="metric">The metric.</param> public void MetricsRow(MethodMetric metric) { if (metric == null) { throw new ArgumentNullException(nameof(metric)); } this.reportTextWriter.Write("<tr>"); this.reportTextWriter.Write("<td title=\"{0}\">{1}</td>", WebUtility.HtmlEncode(metric.Name), WebUtility.HtmlEncode(metric.ShortName)); foreach (var metricValue in metric.Metrics.Select(m => m.Value)) { this.reportTextWriter.Write("<td>{0}</td>", metricValue.ToString(CultureInfo.InvariantCulture)); } this.reportTextWriter.WriteLine("</tr>"); }
/// <summary> /// Adds the given method metric. /// </summary> /// <param name="methodMetric">The method metric.</param> internal void AddMethodMetric(MethodMetric methodMetric) { this.methodMetrics.Add(methodMetric); }
/// <summary> /// Adds the given metric values to the report. /// </summary> /// <param name="metric">The metric.</param> public void MetricsRow(MethodMetric metric) { foreach (var renderer in this.renderers) { renderer.MetricsRow(metric); } }
/// <summary> /// Adds the given method metric. /// </summary> /// <param name="methodMetric">The method metric.</param> public void AddMethodMetric(MethodMetric methodMetric) { this.methodMetrics.Add(methodMetric); }
/// <summary> /// Adds the given metric values to the report. /// </summary> /// <param name="metric">The metric.</param> public void MetricsRow(MethodMetric metric) { if (metric == null) { throw new ArgumentNullException("metric"); } this.reportBuilder.Append("<tr>"); this.reportBuilder.AppendFormat("<td>{0}</td>", WebUtility.HtmlEncode(metric.Name)); foreach (var metricValue in metric.Metrics.Select(m => m.Value)) { this.reportBuilder.AppendFormat("<td>{0}</td>", metricValue); } this.reportBuilder.Append("</tr>"); }