Skip to content

Commit

Permalink
chore: Clean up tests and some simplifications (#499)
Browse files Browse the repository at this point in the history
* chore: Test cleanup

* fix: Fixed `new-project.ps1`

---------

Signed-off-by: Martin Stühmer <[email protected]>
  • Loading branch information
samtrion authored Oct 30, 2024
1 parent 5bf2891 commit 73176ba
Show file tree
Hide file tree
Showing 116 changed files with 1,459 additions and 20 deletions.
9 changes: 8 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@
</PropertyGroup>

<ItemGroup Condition=" '$(IsTestableProject)' == 'true' " >
<None Include="..\_snapshot\**\*.*" Link="_snapshot\%(RecursiveDir)%(Filename)%(Extension)" />
<None Include="..\_snapshots\**\*.*" Link="_sharedSnapshots\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<PropertyGroup>
<NetEvolve_ProjectTargetFrameworks>netstandard2.0;net8.0</NetEvolve_ProjectTargetFrameworks>
<NetEvolve_TestTargetFrameworks>net6.0;net8.0;</NetEvolve_TestTargetFrameworks>

<NoWarn Condition=" '$(TargetFramework)' == 'netstandard2.0' ">$(NoWarn);CA1062;</NoWarn>
</PropertyGroup>

<PropertyGroup>
<!-- Workaround, until https://github.com/GitTools/GitVersion/pull/4206 is released -->
<GitVersionTargetFramework>net8.0</GitVersionTargetFramework>
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.3.0" />
<PackageVersion Include="PublicApiGenerator" Version="11.1.0" />
<PackageVersion Include="Verify.MSTest" Version="28.0.0" />
<PackageVersion Include="Verify.NUnit" Version="28.0.0" />
<PackageVersion Include="Verify.Xunit" Version="28.0.0" />
Expand Down
32 changes: 24 additions & 8 deletions Extensions.Test.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{19B4116B-14B4-436F-8A52-E71DB9CFCA7C}"
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D67E420A-2329-4879-B82C-069039603B81}"
ProjectSection(SolutionItems) = preProject
tests\Directory.Build.props = tests\Directory.Build.props
tests\Directory.Build.targets = tests\Directory.Build.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetEvolve.Extensions.XUnit", "src\NetEvolve.Extensions.XUnit\NetEvolve.Extensions.XUnit.csproj", "{83075493-17CC-48AC-BACF-A22ACE5223E8}"
EndProject
Expand All @@ -46,6 +38,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetEvolve.Extensions.MSTest
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetEvolve.Extensions.MSTest.Tests.Unit", "tests\NetEvolve.Extensions.MSTest.Tests.Unit\NetEvolve.Extensions.MSTest.Tests.Unit.csproj", "{75703C6B-80B0-406B-A9FF-84C5F4956186}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetEvolve.Extensions.XUnit.Tests.PublicApi", "tests\NetEvolve.Extensions.XUnit.Tests.PublicApi\NetEvolve.Extensions.XUnit.Tests.PublicApi.csproj", "{4D92E42D-68F1-4092-BDB7-29F6265C8CEC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetEvolve.Extensions.NUnit.Tests.PublicApi", "tests\NetEvolve.Extensions.NUnit.Tests.PublicApi\NetEvolve.Extensions.NUnit.Tests.PublicApi.csproj", "{4F4B90A9-9371-4D13-875B-331468D1E888}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetEvolve.Extensions.MSTest.Tests.PublicApi", "tests\NetEvolve.Extensions.MSTest.Tests.PublicApi\NetEvolve.Extensions.MSTest.Tests.PublicApi.csproj", "{37815304-2B2A-4EE1-A1A2-A947794ED7A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -76,6 +74,18 @@ Global
{75703C6B-80B0-406B-A9FF-84C5F4956186}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75703C6B-80B0-406B-A9FF-84C5F4956186}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75703C6B-80B0-406B-A9FF-84C5F4956186}.Release|Any CPU.Build.0 = Release|Any CPU
{4D92E42D-68F1-4092-BDB7-29F6265C8CEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D92E42D-68F1-4092-BDB7-29F6265C8CEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D92E42D-68F1-4092-BDB7-29F6265C8CEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D92E42D-68F1-4092-BDB7-29F6265C8CEC}.Release|Any CPU.Build.0 = Release|Any CPU
{4F4B90A9-9371-4D13-875B-331468D1E888}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F4B90A9-9371-4D13-875B-331468D1E888}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F4B90A9-9371-4D13-875B-331468D1E888}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F4B90A9-9371-4D13-875B-331468D1E888}.Release|Any CPU.Build.0 = Release|Any CPU
{37815304-2B2A-4EE1-A1A2-A947794ED7A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37815304-2B2A-4EE1-A1A2-A947794ED7A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37815304-2B2A-4EE1-A1A2-A947794ED7A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37815304-2B2A-4EE1-A1A2-A947794ED7A5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -87,5 +97,11 @@ Global
{4A9EFEA3-5849-4542-A7E4-9EEDF2DD8EBF} = {D67E420A-2329-4879-B82C-069039603B81}
{0797A20A-41EA-419B-A6B6-CB2A973A33FF} = {19B4116B-14B4-436F-8A52-E71DB9CFCA7C}
{75703C6B-80B0-406B-A9FF-84C5F4956186} = {D67E420A-2329-4879-B82C-069039603B81}
{4D92E42D-68F1-4092-BDB7-29F6265C8CEC} = {D67E420A-2329-4879-B82C-069039603B81}
{4F4B90A9-9371-4D13-875B-331468D1E888} = {D67E420A-2329-4879-B82C-069039603B81}
{37815304-2B2A-4EE1-A1A2-A947794ED7A5} = {D67E420A-2329-4879-B82C-069039603B81}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EBB4607C-57F7-4F91-93B2-A444A3D33755}
EndGlobalSection
EndGlobal
16 changes: 13 additions & 3 deletions new-project.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ param (
# Parameter help description
[Parameter(Mandatory = $false)]
[Switch]
$DisableIntegrationTests
$DisableIntegrationTests,

[Parameter(Mandatory = $false)]
[Switch]
$EnableProjectGrouping,

[Parameter(Mandatory = $false)]
[Switch]
$DisableArchitectureTests
)

. .\eng\scripts\new-project.ps1
Expand All @@ -41,5 +49,7 @@ New-Project `
-DisableTests $DisableTests `
-DisableUnitTests $DisableUnitTests `
-DisableIntegrationTests $DisableIntegrationTests `
-SolutionFile ".\Extensions.Test.sln" `
-OutputDirectory (Get-Location)
-SolutionFile "./Extensions.Test.sln" `
-OutputDirectory (Get-Location) `
-EnableProjectGrouping $EnableProjectGrouping `
-DisableArchitectureTests $DisableArchitectureTests
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetEvolve_TestTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="PublicApiGenerator" />
<PackageReference Include="Verify.Xunit" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NetEvolve.Extensions.MSTest\NetEvolve.Extensions.MSTest.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions tests/NetEvolve.Extensions.MSTest.Tests.PublicApi/Predefined.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace NetEvolve.Extensions.MSTest.Tests.PublicApi;

using System.IO;
using System.Runtime.CompilerServices;
using VerifyTests;
using VerifyXunit;

internal static class Predefined
{
[ModuleInitializer]
public static void Init()
{
Verifier.DerivePathInfo(
(sourceFile, projectDirectory, type, method) =>
{
var directory = Path.Combine(
projectDirectory,
"_snapshots",
Namer.TargetFrameworkNameAndVersion
);
_ = Directory.CreateDirectory(directory);
return new(directory, type.Name, method.Name);
}
);

VerifierSettings.AutoVerify(includeBuildServer: false);
VerifierSettings.SortPropertiesAlphabetically();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace NetEvolve.Extensions.MSTest.Tests.PublicApi;

using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using PublicApiGenerator;
using Xunit;

public class PublicApiTests
{
[Fact]
public Task PublicApi_HasNotChanged_Expected()
{
var assembly = typeof(AcceptanceTestAttribute).Assembly;
var types = assembly.GetTypes().Where(IsVisibleToIntelliSense).ToArray();

var options = new ApiGeneratorOptions
{
ExcludeAttributes =
[
typeof(InternalsVisibleToAttribute).FullName!,
"System.Runtime.CompilerServices.IsByRefLikeAttribute",
typeof(TargetFrameworkAttribute).FullName!,
typeof(CLSCompliantAttribute).FullName!,
typeof(AssemblyMetadataAttribute).FullName!,
typeof(NeutralResourcesLanguageAttribute).FullName!,
],
IncludeTypes = types,
};

var publicApi = assembly.GeneratePublicApi(options);

return Verify(publicApi);
}

private static bool IsVisibleToIntelliSense(Type type)
{
var browsable = type.GetCustomAttribute<BrowsableAttribute>();
if (browsable is null || browsable.Browsable)
{
return true;
}

var editorBrowsable = type.GetCustomAttribute<EditorBrowsableAttribute>();
return editorBrowsable is null || editorBrowsable.State != EditorBrowsableState.Never;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
namespace NetEvolve.Extensions.MSTest
{
public sealed class AcceptanceTestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public AcceptanceTestAttribute() { }
}
public sealed class ArchitectureTestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public ArchitectureTestAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public sealed class BugAttribute : NetEvolve.Extensions.MSTest.Internal.TestCategoryWithIdBaseAttribute
{
public BugAttribute() { }
public BugAttribute(long id) { }
public BugAttribute(string? id) { }
}
public sealed class CodedUITestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public CodedUITestAttribute() { }
}
public sealed class EndToEndTestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public EndToEndTestAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public sealed class EpicAttribute : NetEvolve.Extensions.MSTest.Internal.TestCategoryWithIdBaseAttribute
{
public EpicAttribute() { }
public EpicAttribute(long id) { }
public EpicAttribute(string? id) { }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public sealed class FeatureAttribute : NetEvolve.Extensions.MSTest.Internal.TestCategoryWithIdBaseAttribute
{
public FeatureAttribute() { }
public FeatureAttribute(long id) { }
public FeatureAttribute(string? id) { }
}
public sealed class FunctionalTestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public FunctionalTestAttribute() { }
}
public sealed class IntegrationTestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public IntegrationTestAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public sealed class IssueAttribute : NetEvolve.Extensions.MSTest.Internal.TestCategoryWithIdBaseAttribute
{
public IssueAttribute() { }
public IssueAttribute(long id) { }
public IssueAttribute(string? id) { }
}
public sealed class PerformanceTestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public PerformanceTestAttribute() { }
}
public sealed class PostDeploymentAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public PostDeploymentAttribute() { }
}
public sealed class PreDeploymentAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public PreDeploymentAttribute() { }
}
public sealed class UnitTestAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
public UnitTestAttribute() { }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public sealed class UserStoryAttribute : NetEvolve.Extensions.MSTest.Internal.TestCategoryWithIdBaseAttribute
{
public UserStoryAttribute() { }
public UserStoryAttribute(long id) { }
public UserStoryAttribute(string? id) { }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
public sealed class WorkItemAttribute : NetEvolve.Extensions.MSTest.Internal.TestCategoryWithIdBaseAttribute
{
public WorkItemAttribute() { }
public WorkItemAttribute(long id) { }
public WorkItemAttribute(string? id) { }
}
}
namespace NetEvolve.Extensions.MSTest.Internal
{
public abstract class TestCategoryWithIdBaseAttribute : NetEvolve.Extensions.MSTest.Internal.TestTraitBaseAttribute
{
protected TestCategoryWithIdBaseAttribute(string categoryName, string? id = null) { }
public string? Id { get; }
}
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=true)]
public abstract class TestTraitBaseAttribute : Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryBaseAttribute
{
protected TestTraitBaseAttribute(string categoryName) { }
public override System.Collections.Generic.IList<string> TestCategories { get; }
}
}
Loading

0 comments on commit 73176ba

Please sign in to comment.