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

feat: add Api approval tests #482

Merged
merged 13 commits into from
Mar 14, 2024
4 changes: 4 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="PublicApiGenerator" Version="11.1.0" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.0.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Testably.Abstractions.Testing.FileSystem;
/// <summary>
/// Mocked instance of a <see cref="IFileSystemWatcher" />
/// </summary>
public sealed class FileSystemWatcherMock : Component, IFileSystemWatcher
internal sealed class FileSystemWatcherMock : Component, IFileSystemWatcher
{
/// <summary>
/// Simulated bytes pre message to calculate the size of the blocking collection relative to the
Expand Down
16 changes: 16 additions & 0 deletions Testably.Abstractions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testably.Abstractions.TestH
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testably.Abstractions.Tests.SourceGenerator", "Tests\Helpers\Testably.Abstractions.Tests.SourceGenerator\Testably.Abstractions.Tests.SourceGenerator.csproj", "{97A2540A-7FB4-4D8B-B003-3F8CAA9CED87}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{8A44FA00-968E-4CEC-90E6-94A878B9DEB2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testably.Abstractions.Api.Tests", "Tests\Api\Testably.Abstractions.Api.Tests\Testably.Abstractions.Api.Tests.csproj", "{2A729DA1-0C27-4C68-AB39-7D7BCB00D49F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Api", "Api", "{0AEBB1A6-07D6-46DC-BC78-9771D380EBC0}"
ProjectSection(SolutionItems) = preProject
Tests\Api\Directory.Build.props = Tests\Api\Directory.Build.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -144,6 +153,10 @@ Global
{97A2540A-7FB4-4D8B-B003-3F8CAA9CED87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97A2540A-7FB4-4D8B-B003-3F8CAA9CED87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97A2540A-7FB4-4D8B-B003-3F8CAA9CED87}.Release|Any CPU.Build.0 = Release|Any CPU
{2A729DA1-0C27-4C68-AB39-7D7BCB00D49F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A729DA1-0C27-4C68-AB39-7D7BCB00D49F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A729DA1-0C27-4C68-AB39-7D7BCB00D49F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A729DA1-0C27-4C68-AB39-7D7BCB00D49F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -163,6 +176,9 @@ Global
{B6C45D8A-A545-402E-A6B0-47BC7D9BBCF5} = {61F335A6-9CE0-4040-A34F-E70B1A55077D}
{425BA8BA-7795-4749-BFC1-6FA853EBC6B7} = {B6C45D8A-A545-402E-A6B0-47BC7D9BBCF5}
{97A2540A-7FB4-4D8B-B003-3F8CAA9CED87} = {B6C45D8A-A545-402E-A6B0-47BC7D9BBCF5}
{8A44FA00-968E-4CEC-90E6-94A878B9DEB2} = {61F335A6-9CE0-4040-A34F-E70B1A55077D}
{2A729DA1-0C27-4C68-AB39-7D7BCB00D49F} = {8A44FA00-968E-4CEC-90E6-94A878B9DEB2}
{0AEBB1A6-07D6-46DC-BC78-9771D380EBC0} = {2FDB2AAE-E5CE-483E-A1A6-EC0B0A4AD67B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EC4D8481-B9FD-41B5-832A-369210993DF4}
Expand Down
39 changes: 39 additions & 0 deletions Tests/Api/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<Project>

<Import Project="$(MSBuildThisFileDirectory)/../../Directory.Build.props"
Condition="Exists('$(MSBuildThisFileDirectory)/../../Directory.Build.props')" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Feature.Flags.props', '$(MSBuildThisFileDirectory)/../../'))" />

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<LangVersion>latest</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<NoWarn>701;1702;CA1845</NoWarn>
<OutputPath>..\..\..\Build\Tests\$(MSBuildProjectName)</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<Nullable>annotations</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit.Analyzers" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Nullable">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Tests/Api/Testably.Abstractions.Api.Tests/ApiAcceptance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NUnit.Framework;

namespace Testably.Abstractions.Api.Tests;

public sealed class ApiAcceptance
{
/// <summary>
/// Execute this test to update the expected public API to the current API surface.
/// </summary>
[TestCase]
[Explicit]
public void AcceptApiChanges()
{
string[] assemblyNames =
{
"Testably.Abstractions",
"Testably.Abstractions.AccessControl",
"Testably.Abstractions.Compression",
"Testably.Abstractions.Interface",
"Testably.Abstractions.Testing"
};
foreach (string assemblyName in assemblyNames)
{
foreach (string framework in Helper.GetTargetFrameworks())
{
string publicApi = Helper.CreatePublicApi(framework, assemblyName);
Helper.SetExpectedApi(framework, assemblyName, publicApi);
}
}
}
}
85 changes: 85 additions & 0 deletions Tests/Api/Testably.Abstractions.Api.Tests/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using NUnit.Framework;
using System.Collections;

namespace Testably.Abstractions.Api.Tests;

/// <summary>
/// Whenever a test fails, this means that the public API surface changed.
/// If the change was intentional, execute the <see cref="ApiAcceptance.AcceptApiChanges()" /> test to take over the
/// current public API surface. The changes will become part of the pull request and will be reviewed accordingly.
/// </summary>
public sealed class ApiApprovalTests
{
[TestCaseSource(typeof(TargetFrameworksTheoryData))]
public void VerifyPublicApiForTestablyAbstractions(string framework)
{
const string assemblyName = "Testably.Abstractions";

string publicApi = Helper.CreatePublicApi(framework, assemblyName);
string expectedApi = Helper.GetExpectedApi(framework, assemblyName);

Assert.That(publicApi, Is.EqualTo(expectedApi));
}

[TestCaseSource(typeof(TargetFrameworksTheoryData))]
public void VerifyPublicApiForTestablyAbstractionsAccessControl(string framework)
{
const string assemblyName = "Testably.Abstractions.AccessControl";

string publicApi = Helper.CreatePublicApi(framework, assemblyName);
string expectedApi = Helper.GetExpectedApi(framework, assemblyName);

Assert.That(publicApi, Is.EqualTo(expectedApi));
}

[TestCaseSource(typeof(TargetFrameworksTheoryData))]
public void VerifyPublicApiForTestablyAbstractionsCompression(string framework)
{
const string assemblyName = "Testably.Abstractions.Compression";

string publicApi = Helper.CreatePublicApi(framework, assemblyName);
string expectedApi = Helper.GetExpectedApi(framework, assemblyName);

Assert.That(publicApi, Is.EqualTo(expectedApi));
}

[TestCaseSource(typeof(TargetFrameworksTheoryData))]
public void VerifyPublicApiForTestablyAbstractionsInterface(string framework)
{
const string assemblyName = "Testably.Abstractions.Interface";

string publicApi = Helper.CreatePublicApi(framework, assemblyName);
string expectedApi = Helper.GetExpectedApi(framework, assemblyName);

Assert.That(publicApi, Is.EqualTo(expectedApi));
}

[TestCaseSource(typeof(TargetFrameworksTheoryData))]
public void VerifyPublicApiForTestablyAbstractionsTesting(string framework)
{
const string assemblyName = "Testably.Abstractions.Testing";

string publicApi = Helper.CreatePublicApi(framework, assemblyName);
string expectedApi = Helper.GetExpectedApi(framework, assemblyName);

Assert.That(publicApi, Is.EqualTo(expectedApi));
}

private class TargetFrameworksTheoryData : IEnumerable
{
#region IEnumerable Members

public IEnumerator GetEnumerator()
{
foreach (string targetFramework in Helper.GetTargetFrameworks())
{
yield return new object[]
{
targetFramework
};
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[assembly: System.CLSCompliant(true)]
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/Testably/Testably.Abstractions.git")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Testably.Abstractions.AccessControl.Tests")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName=".NET 6.0")]
namespace Testably.Abstractions
{
public static class DirectoryAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void CreateDirectory(this System.IO.Abstractions.IDirectory directory, string path, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectory directory, string path) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectory directory, string path, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IDirectory directory, string path, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
}
public static class DirectoryInfoAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void Create(this System.IO.Abstractions.IDirectoryInfo directoryInfo, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectoryInfo directoryInfo) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectoryInfo directoryInfo, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IDirectoryInfo directoryInfo, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
}
public static class FileAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFile file, string path) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFile file, string path, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IFile file, string path, System.Security.AccessControl.FileSecurity fileSecurity) { }
}
public static class FileInfoAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFileInfo fileInfo) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFileInfo fileInfo, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IFileInfo fileInfo, System.Security.AccessControl.FileSecurity fileSecurity) { }
}
public static class FileStreamAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.FileSystemStream fileStream) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.FileSystemStream fileStream, System.Security.AccessControl.FileSecurity fileSecurity) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[assembly: System.CLSCompliant(true)]
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/Testably/Testably.Abstractions.git")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Testably.Abstractions.AccessControl.Tests")]
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v7.0", FrameworkDisplayName=".NET 7.0")]
namespace Testably.Abstractions
{
public static class DirectoryAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void CreateDirectory(this System.IO.Abstractions.IDirectory directory, string path, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectory directory, string path) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectory directory, string path, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IDirectory directory, string path, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
}
public static class DirectoryInfoAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void Create(this System.IO.Abstractions.IDirectoryInfo directoryInfo, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectoryInfo directoryInfo) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.DirectorySecurity GetAccessControl(this System.IO.Abstractions.IDirectoryInfo directoryInfo, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IDirectoryInfo directoryInfo, System.Security.AccessControl.DirectorySecurity directorySecurity) { }
}
public static class FileAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFile file, string path) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFile file, string path, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IFile file, string path, System.Security.AccessControl.FileSecurity fileSecurity) { }
}
public static class FileInfoAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFileInfo fileInfo) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.IFileInfo fileInfo, System.Security.AccessControl.AccessControlSections includeSections) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.IFileInfo fileInfo, System.Security.AccessControl.FileSecurity fileSecurity) { }
}
public static class FileStreamAclExtensions
{
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.AccessControl.FileSecurity GetAccessControl(this System.IO.Abstractions.FileSystemStream fileStream) { }
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SetAccessControl(this System.IO.Abstractions.FileSystemStream fileStream, System.Security.AccessControl.FileSecurity fileSecurity) { }
}
}
Loading
Loading