-
Notifications
You must be signed in to change notification settings - Fork 867
/
Copy pathPublicApiContractTest.cs
36 lines (29 loc) · 1.08 KB
/
PublicApiContractTest.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Reflection;
using PublicApiGenerator;
namespace Docfx.Tests;
public class PublicApiContractTest
{
[Fact]
public static Task TestPublicApiContract()
{
var assemblies = new HashSet<Assembly>();
GetAssemblies(typeof(Docset).Assembly);
var publicApi = string.Join("\n", assemblies
.OrderBy(a => a.FullName)
.Select(a => a.GeneratePublicApi(new() { IncludeAssemblyAttributes = false })));
return Verify(new Target("cs", publicApi)).UseFileName("Api").AutoVerify(includeBuildServer: false);
void GetAssemblies(Assembly assembly)
{
assemblies.Add(assembly);
foreach (var name in assembly.GetReferencedAssemblies())
{
if (name.Name.StartsWith("Docfx.", StringComparison.OrdinalIgnoreCase))
{
GetAssemblies(Assembly.Load(name.Name));
}
}
}
}
}