-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathPublicApiTests.cs
More file actions
executable file
·56 lines (45 loc) · 2.2 KB
/
Copy pathPublicApiTests.cs
File metadata and controls
executable file
·56 lines (45 loc) · 2.2 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.IO;
using PublicApiGenerator;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.OpenApi.Tests.PublicApi
{
[Collection("DefaultSettings")]
public class PublicApiTests
{
private readonly ITestOutputHelper _output;
public PublicApiTests(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public void ReviewPublicApiChanges()
{
// This test is a safety check when you modify the public api surface.
// If it fails, it means you changed something public. This is not always a problem!
// It takes a human to read the change, determine if it is breaking and update the PublicApi.approved.txt with the new approved API surface
// Arrange
var publicApi = typeof(OpenApiSpecVersion).Assembly.GeneratePublicApi(new() { AllowNamespacePrefixes = new[] { "Microsoft.OpenApi" } } );
// Act
var approvedFilePath = Path.Combine("PublicApi", "PublicApi.approved.txt");
if (!File.Exists(approvedFilePath))
using (var _ = File.CreateText(approvedFilePath)) { }
var approvedApi = File.ReadAllText(approvedFilePath);
if (!approvedApi.Equals(publicApi))
{
_output.WriteLine("This test is a safety check when you modify the public api surface.");
_output.WriteLine("It has failed. This means you changed something public. This is not always a problem!");
_output.WriteLine("It takes a human to read the change, determine if it is breaking and update the PublicApi.approved.txt with the new approved API surface.");
_output.WriteLine("The new API surface can be found in PublicApi.current.txt");
_output.WriteLine(string.Empty);
_output.WriteLine("The new public api is:");
_output.WriteLine(publicApi);
File.WriteAllText(Path.Combine("PublicApi", "PublicApi.current.txt"), publicApi);
}
// Assert
Assert.Equal(approvedApi, publicApi);
}
}
}