Skip to content

Commit

Permalink
Deduplicate target frameworks
Browse files Browse the repository at this point in the history
In the ApproveApi test, read the target frameworks directly from the FluentAssertions.csproj file instead of copying them all as InlineData.

This should future proof when new target frameworks are added/removed from the main project.
  • Loading branch information
0xced committed Aug 26, 2022
1 parent f064e41 commit 15d3477
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Tests/Approval.Tests/ApiApproval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml.XPath;
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;
using PublicApiGenerator;
Expand All @@ -18,12 +20,7 @@ namespace Approval.Tests;
public class ApiApproval
{
[Theory]
[InlineData("net47")]
[InlineData("net6.0")]
[InlineData("netstandard2.0")]
[InlineData("netstandard2.1")]
[InlineData("netcoreapp2.1")]
[InlineData("netcoreapp3.0")]
[ClassData(typeof(TargetFrameworksTheoryData))]
public Task ApproveApi(string frameworkVersion)
{
string codeBase = Assembly.GetExecutingAssembly().Location;
Expand Down Expand Up @@ -75,4 +72,18 @@ public static Task<CompareResult> OnlyIncludeChanges(string received, string ver
var compareResult = CompareResult.NotEqual(builder.ToString());
return Task.FromResult(compareResult);
}

private class TargetFrameworksTheoryData : TheoryData<string>
{
public TargetFrameworksTheoryData()
{
var csproj = Path.Combine(GetSourceDirectory(), Path.Combine("..", "..", "Src", "FluentAssertions", "FluentAssertions.csproj"));
var project = XDocument.Load(csproj);
var targetFrameworks = project.XPathSelectElement("/Project/PropertyGroup/TargetFrameworks");
foreach (string targetFramework in targetFrameworks!.Value.Split(';'))
{
Add(targetFramework);
}
}
}
}

0 comments on commit 15d3477

Please sign in to comment.