forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentationTests.cs
92 lines (72 loc) · 3 KB
/
DocumentationTests.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using GitVersion;
using NUnit.Framework;
using Shouldly;
using YamlDotNet.Serialization;
[TestFixture]
public class DocumentationTests
{
[Test]
public void ConfigurationDocumentationIsUpToDate()
{
var configurationDocumentationFile = ReadDocumentationFile("configuration.md");
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance;
var configProperties = typeof(Config)
.GetProperties(bindingFlags)
.Union(typeof(BranchConfig).GetProperties(bindingFlags))
.Select(p => p.GetCustomAttribute<YamlMemberAttribute>())
.Where(a => a != null)
.Select(a => a.Alias)
.ToList();
configProperties.ShouldNotBeEmpty();
foreach (var configProperty in configProperties)
{
var formattedConfigProperty = string.Format("**`{0}:`**", configProperty);
configurationDocumentationFile.ShouldContain(formattedConfigProperty,
Environment.NewLine + configurationDocumentationFile);
}
}
[Test]
public void VariableDocumentationIsUpToDate()
{
var variableDocumentationFile = ReadDocumentationFile("more-info/variables.md");
var variables = VersionVariables.AvailableVariables.ToList();
variables.ShouldNotBeEmpty();
foreach (var variable in variables)
{
variableDocumentationFile.ShouldContain(variable,
Environment.NewLine + variableDocumentationFile);
}
}
static string ReadDocumentationFile(string relativeDocumentationFilePath)
{
var currentDirectory = new FileInfo(typeof(DocumentationTests).Assembly.Location).Directory;
while (currentDirectory != null)
{
var docsDirectory = currentDirectory
.EnumerateDirectories("docs", SearchOption.TopDirectoryOnly)
.FirstOrDefault();
if (docsDirectory != null)
{
currentDirectory = docsDirectory;
break;
}
currentDirectory = currentDirectory.Parent;
}
if (currentDirectory == null || !currentDirectory.Name.Equals("docs", StringComparison.Ordinal))
{
throw new DirectoryNotFoundException("Couldn't find the 'docs' directory.");
}
var documentationFilePath = Path.Combine(currentDirectory.FullName, relativeDocumentationFilePath);
// Normalize path separators and such.
documentationFilePath = new FileInfo(documentationFilePath).FullName;
if (!File.Exists(documentationFilePath))
{
throw new FileNotFoundException(string.Format("The documentation file '{0}' couldn't be found.", documentationFilePath), documentationFilePath);
}
return File.ReadAllText(documentationFilePath);
}
}