Skip to content

Commit

Permalink
Merge branch 'main' into CP_AddNet8_0Target
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman authored Nov 16, 2023
2 parents b7b45fc + 53d5f6d commit cc8ffe0
Show file tree
Hide file tree
Showing 5 changed files with 2,797 additions and 1 deletion.
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

0 comments on commit cc8ffe0

Please sign in to comment.