Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : Add API Tests #757

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ FodyWeavers.xsd
.DS_Store

# API Tests
src/*.Tests/**/ApiApprovalTests*.received.txt
src/*.Tests/API/ApiApprovalTests.*.received.txt

# JetBrains
.idea/
43 changes: 43 additions & 0 deletions src/DynamicData.Tests/API/ApiApprovalBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using PublicApiGenerator;
using VerifyXunit;

namespace DynamicData.APITests
{
/// <summary>
/// Api Approval Base.
/// </summary>
[ExcludeFromCodeCoverage]
[UsesVerify]
public abstract class ApiApprovalBase
{
/// <summary>
/// Check Approval.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <param name="filePath">The file path.</param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
protected static Task CheckApproval(Assembly assembly, [CallerFilePath] string? filePath = null)
{
if (filePath is null)
{
return Task.CompletedTask;
}

var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = ["DynamicData"] };
var apiText = assembly.GeneratePublicApi(generatorOptions);
return Verifier.Verify(apiText, null, filePath)
.UniqueForRuntimeAndVersion()
.ScrubEmptyLines()
.ScrubLines(l =>
l.StartsWith("[assembly: AssemblyVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: AssemblyFileVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: AssemblyInformationalVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: System.Reflection.AssemblyMetadata(", StringComparison.InvariantCulture));
}
}
}
Loading