-
Notifications
You must be signed in to change notification settings - Fork 3
/
CodeComplianceDocumentationHelper.cs
61 lines (52 loc) · 2.11 KB
/
CodeComplianceDocumentationHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
namespace Atc.XUnit;
/// <summary>
/// CodeComplianceDocumentationHelper.
/// </summary>
public static class CodeComplianceDocumentationHelper
{
/// <summary>
/// Asserts the exported type with missing comments.
/// </summary>
/// <param name="type">The type.</param>
public static void AssertExportedTypeWithMissingComments(Type type)
{
var typeComments = DocumentationHelper.CollectExportedTypeWithCommentsFromType(type);
var testResults = new List<TestResult>();
if (typeComments is not null && !typeComments.HasComments)
{
testResults.Add(new TestResult(isError: true, 0, $"Type: {typeComments.Type.BeautifyTypeName(useFullName: true)}"));
}
TestResultHelper.AssertOnTestResults(testResults);
}
/// <summary>
/// Asserts the exported types with missing comments.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <param name="excludeTypes">The exclude types.</param>
public static void AssertExportedTypesWithMissingComments(
Assembly assembly,
List<Type>? excludeTypes = null)
{
if (assembly is null)
{
throw new ArgumentNullException(nameof(assembly));
}
// Due to some build issue with GenerateDocumentationFile=true and xml-file location, this hack is made for now.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return;
}
var typesWithMissingCommentsGroups = DocumentationHelper.CollectExportedTypesWithMissingCommentsFromAssembly(
assembly,
excludeTypes)
.OrderBy(x => x.Type.FullName, StringComparer.Ordinal)
.GroupBy(x => x.Type.BeautifyName(useFullName: true), StringComparer.Ordinal)
.ToArray();
var testResults = new List<TestResult>
{
new($"Assembly: {assembly.GetName()}"),
};
testResults.AddRange(typesWithMissingCommentsGroups.Select(item => new TestResult(isError: false, 1, $"Type: {item.Key}")));
TestResultHelper.AssertOnTestResults(testResults);
}
}