Index: src/Common/DelftTools.Utils/Validation/ValidationReport.cs =================================================================== diff -u -r8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9 -r5fc71a385897af92ccb092f2f969b5709afab85a --- src/Common/DelftTools.Utils/Validation/ValidationReport.cs (.../ValidationReport.cs) (revision 8f6ae890fed8e8eae3a32f9c0498a10f82e0ddf9) +++ src/Common/DelftTools.Utils/Validation/ValidationReport.cs (.../ValidationReport.cs) (revision 5fc71a385897af92ccb092f2f969b5709afab85a) @@ -6,14 +6,6 @@ { public class ValidationReport { - /// - /// Gets the severity of the report, eg the maximum severity of any of its issues. - /// - public ValidationSeverity Severity { get; private set; } - public string Category { get; private set; } - public IEnumerable Issues { get; private set; } - public IEnumerable SubReports { get; private set; } - public ValidationReport(string category, IEnumerable issues, IEnumerable subReports = null) { Category = category; @@ -23,104 +15,113 @@ } public ValidationReport(string category, IEnumerable subReports) - : this(category, null, subReports) - { - } + : this(category, null, subReports) {} /// - /// Creates an empty validation report. Validation reports are read-only so they cannot be added to. + /// Gets the severity of the report, eg the maximum severity of any of its issues. /// - public static ValidationReport Empty(string name) - { - return new ValidationReport(name, null); - } + public ValidationSeverity Severity { get; private set; } + public string Category { get; private set; } + public IEnumerable Issues { get; private set; } + public IEnumerable SubReports { get; private set; } + /// /// IsEmpty is true when the report contains no issues and no subreports /// public bool IsEmpty { - get { return !Issues.Any() && !SubReports.Any(); } - } - - public IList GetAllIssuesRecursive() - { - var allIssues = new List(); - - allIssues.AddRange(Issues); - foreach(var report in SubReports) + get { - allIssues.AddRange(report.GetAllIssuesRecursive()); + return !Issues.Any() && !SubReports.Any(); } - - return allIssues; } public IEnumerable AllErrors { - get { return GetAllIssuesRecursive().Where(i => i.Severity == ValidationSeverity.Error); } + get + { + return GetAllIssuesRecursive().Where(i => i.Severity == ValidationSeverity.Error); + } } - private ValidationSeverity DetermineSeverity() - { - var issueMax = Issues.Any() ? Issues.Max(i => i.Severity) : ValidationSeverity.None; - var reportMax = SubReports.Any() ? SubReports.Max(i => i.Severity) : ValidationSeverity.None; - return (ValidationSeverity) Math.Max((int) issueMax, (int) reportMax); - } - /// /// The total number of issues (recursive) with severity level 'Error' /// public int ErrorCount { - get { return GetIssueCount(ValidationSeverity.Error); } + get + { + return GetIssueCount(ValidationSeverity.Error); + } } /// /// The total number of issues (recursive) with severity level 'Warning' /// public int WarningCount { - get { return GetIssueCount(ValidationSeverity.Warning); } + get + { + return GetIssueCount(ValidationSeverity.Warning); + } } /// /// The total number of issues (recursive) with severity level 'Info' /// public int InfoCount { - get { return GetIssueCount(ValidationSeverity.Info); } + get + { + return GetIssueCount(ValidationSeverity.Info); + } } - private int GetIssueCount(ValidationSeverity severity) + /// + /// Creates an empty validation report. Validation reports are read-only so they cannot be added to. + /// + public static ValidationReport Empty(string name) { - return SubReports.Sum(r => r.GetIssueCount(severity)) + Issues.Count(i => i.Severity == severity); + return new ValidationReport(name, null); } - public override bool Equals(object obj) + public IList GetAllIssuesRecursive() { - if (obj is ValidationReport) + var allIssues = new List(); + + allIssues.AddRange(Issues); + foreach (var report in SubReports) { - return Equals(obj as ValidationReport); + allIssues.AddRange(report.GetAllIssuesRecursive()); } - return false; + + return allIssues; } public bool Equals(ValidationReport other) { if (other == null) + { return false; + } if (ReferenceEquals(this, other)) + { return true; + } if (!Category.Equals(other.Category)) + { return false; + } var issues = Issues.ToList(); var otherIssues = other.Issues.ToList(); if (issues.Count != otherIssues.Count) + { return false; + } for (int i = 0; i < issues.Count; i++) { @@ -134,7 +135,9 @@ var otherSubreports = other.SubReports.ToList(); if (subreports.Count != otherSubreports.Count) + { return false; + } for (int i = 0; i < subreports.Count; i++) { @@ -146,13 +149,34 @@ return true; } + public override bool Equals(object obj) + { + if (obj is ValidationReport) + { + return Equals(obj as ValidationReport); + } + return false; + } + public override string ToString() { return string.Format("{0}, severity: {1} ({2} error(s), {3} warning(s), {4} info)", Category, Severity, ErrorCount, WarningCount, InfoCount); } - + + private ValidationSeverity DetermineSeverity() + { + var issueMax = Issues.Any() ? Issues.Max(i => i.Severity) : ValidationSeverity.None; + var reportMax = SubReports.Any() ? SubReports.Max(i => i.Severity) : ValidationSeverity.None; + return (ValidationSeverity) Math.Max((int) issueMax, (int) reportMax); + } + + private int GetIssueCount(ValidationSeverity severity) + { + return SubReports.Sum(r => r.GetIssueCount(severity)) + Issues.Count(i => i.Severity == severity); + } + private static IList AsList(IEnumerable enumerable) { return enumerable as IList ?? enumerable.ToList();