From acc54d415b29f28526c13855123ead650da32742 Mon Sep 17 00:00:00 2001 From: Louis Seubert Date: Tue, 27 Oct 2026 19:33:01 +0100 Subject: [PATCH] chore: tests --- src/sdk.tests/DirectoryExtensions.cs | 22 +++ src/sdk.tests/Geekeey.Arcade.NET.Tests.csproj | 4 +- src/sdk.tests/SdkNuGetTests.cs | 114 ++++++++++++ src/sdk.tests/SdkPackageIntegrationTests.cs | 168 ------------------ src/sdk.tests/_shared/Command.cs | 75 ++++++++ src/sdk.tests/_shared/CommandOutput.cs | 6 + src/sdk.tests/_shared/Project.cs | 65 +++++++ src/sdk.tests/fixtures/base/nuget.config | 7 + .../{BaseConsumer.csproj => project.csproj} | 4 +- src/sdk.tests/fixtures/razor/nuget.config | 7 + .../{RazorConsumer.csproj => project.csproj} | 3 +- .../fixtures/test/Directory.Build.props | 5 - src/sdk.tests/fixtures/test/nuget.config | 7 + .../{TestConsumer.csproj => project.csproj} | 5 +- src/sdk.tests/fixtures/web/nuget.config | 7 + .../{WebConsumer.csproj => project.csproj} | 4 +- .../Geekeey.Arcade.NET.Sdk.Test.csproj | 3 + .../Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.props | 2 + .../Geekeey.Arcade.NET.Sdk.Test/Sdk.targets | 2 + .../extensions/TestingPlatformExtensions.cs | 60 +++++++ .../TestingPlatformExtensions.props | 9 + .../TestingPlatformExtensions.targets | 31 ++++ 22 files changed, 422 insertions(+), 188 deletions(-) create mode 100644 src/sdk.tests/SdkNuGetTests.cs delete mode 100644 src/sdk.tests/SdkPackageIntegrationTests.cs create mode 100644 src/sdk.tests/_shared/Command.cs create mode 100644 src/sdk.tests/_shared/CommandOutput.cs create mode 100644 src/sdk.tests/_shared/Project.cs create mode 100644 src/sdk.tests/fixtures/base/nuget.config rename src/sdk.tests/fixtures/base/{BaseConsumer.csproj => project.csproj} (62%) create mode 100644 src/sdk.tests/fixtures/razor/nuget.config rename src/sdk.tests/fixtures/razor/{RazorConsumer.csproj => project.csproj} (63%) delete mode 100644 src/sdk.tests/fixtures/test/Directory.Build.props create mode 100644 src/sdk.tests/fixtures/test/nuget.config rename src/sdk.tests/fixtures/test/{TestConsumer.csproj => project.csproj} (67%) create mode 100644 src/sdk.tests/fixtures/web/nuget.config rename src/sdk.tests/fixtures/web/{WebConsumer.csproj => project.csproj} (67%) create mode 100644 src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.cs create mode 100644 src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.props create mode 100644 src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.targets diff --git a/src/sdk.tests/DirectoryExtensions.cs b/src/sdk.tests/DirectoryExtensions.cs index 1b73e4d..09d9682 100644 --- a/src/sdk.tests/DirectoryExtensions.cs +++ b/src/sdk.tests/DirectoryExtensions.cs @@ -19,5 +19,27 @@ public static class DirectoryExtensions File.Copy(file, Path.Combine(destinationDirectory, Path.GetRelativePath(sourceDirectory, file))); } } + + public static string? GetDirectoryNameOfFileAbove(string directory, string file) + { + for (var current = new DirectoryInfo(directory); current is not null; current = current.Parent) + { + if (File.Exists(Path.Combine(current.FullName, file))) + { + return current.FullName; + } + } + + return null; + } + } + + extension(File) + { + public static string? GetPathOfFileAbove(string directory, string file) + { + var directoryName = Directory.GetDirectoryNameOfFileAbove(directory, file); + return directoryName is null ? null : Path.Combine(directoryName, file); + } } } diff --git a/src/sdk.tests/Geekeey.Arcade.NET.Tests.csproj b/src/sdk.tests/Geekeey.Arcade.NET.Tests.csproj index ae672d9..9f899a0 100644 --- a/src/sdk.tests/Geekeey.Arcade.NET.Tests.csproj +++ b/src/sdk.tests/Geekeey.Arcade.NET.Tests.csproj @@ -4,12 +4,10 @@ false true Exe + $(DefaultItemExcludes);$(MSBuildProjectDirectory)/fixtures/**/* - - - diff --git a/src/sdk.tests/SdkNuGetTests.cs b/src/sdk.tests/SdkNuGetTests.cs new file mode 100644 index 0000000..efe5596 --- /dev/null +++ b/src/sdk.tests/SdkNuGetTests.cs @@ -0,0 +1,114 @@ +// Copyright (c) The Geekeey Authors +// SPDX-License-Identifier: EUPL-1.2 + +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Geekeey.Arcade.NET.Tests; + +internal sealed class SdkNuGetTests +{ + private static Dictionary Feed { get; set; } = []; + + [Before(Class)] + public static async Task BuildSdkBeforeTest() + { + var path = Directory.GetDirectoryNameOfFileAbove(AppContext.BaseDirectory, "global.json") + ?? throw new InvalidOperationException("Could not locate the repository root containing global.json."); + var package = Path.Combine(path, "artifacts", "package", "release"); + File.Delete(Path.Combine(package, "Geekeey.Arcade.NET.Sdk.Test.1.0.0.nupkg")); + var command = Command.WithWorkingDirectory(path) + .WithThrowOnExit() + .WithEnvironment("DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER", "1"); + await command.RunAsync("dotnet", "pack", Path.Combine("src", "sdk", "Sdk.slnf")); + + var search = await command.RunAsync("dotnet", "package", "search", "--format=json", "--source", package, + "Geekeey.Arcade.NET.Sdk"); + + var result = JsonSerializer.Deserialize(search.StdOut) + ?? throw new InvalidOperationException("The package search response was empty."); + Feed = result.SearchResults + .SelectMany(static result => result.Packages) + .ToDictionary(static result => result.Id, static result => result.LatestVersion); + } + + [Test] + [Arguments("Geekeey.Arcade.NET.Sdk", "base")] + [Arguments("Geekeey.Arcade.NET.Sdk.Razor", "razor")] + [Arguments("Geekeey.Arcade.NET.Sdk.Web", "web")] + [Arguments("Geekeey.Arcade.NET.Sdk.Test", "test")] + public async Task DotNetBuildCanRestoreSdkFromNuGet(string packageId, string name) + { + // Arrange + using var project = await CreateProjectFromTemplate(packageId, name); + + // Act + var output = await project.RunAsync("dotnet", "build"); + + // Assert + await Assert.That(output.ExitCode).IsZero(); + await Assert.That(project.File("bin", "Debug", "net10.0", "project.dll")).Exists(); + } + + [Test] + public async Task TestSdkWritesResultsToArtifactsDirectory() + { + // Arrange + using var project = await CreateProjectFromTemplate("Geekeey.Arcade.NET.Sdk.Test", "test"); + var artifacts = project.Directory("artifacts"); + var build = await project.RunAsync("dotnet", "build", $"-p:ArtifactsPath={artifacts.FullName}"); + await Assert.That(build.ExitCode).IsZero(); + + // Act + var test = await project.RunAsync("dotnet", project.File("artifacts", "bin", "project", "debug", "project.dll").FullName); + + // Assert + await Assert.That(test.ExitCode).IsZero(); + await Assert.That(artifacts.GetFiles("*-report.html", SearchOption.AllDirectories)).IsNotEmpty(); + await Assert.That(artifacts.GetFiles("*-tunit-report.json", SearchOption.AllDirectories)).IsNotEmpty(); + await Assert.That(project.Directory("TestResults").Exists).IsFalse(); + } + + [Test] + [Arguments("Geekeey.Arcade.NET.Sdk", "base")] + [Arguments("Geekeey.Arcade.NET.Sdk.Razor", "razor")] + public async Task DotNetPackCanRestoreSdkFromNuGet(string sdkPackageId, string name) + { + // Arrange + using var project = await CreateProjectFromTemplate(sdkPackageId, name); + + // Act + var output = await project.RunAsync("dotnet", "pack"); + + // Assert + await Assert.That(output.ExitCode).IsZero(); + await Assert.That(project.File("bin", "Release", "My.Package.1.0.0.nupkg")).Exists(); + } + + private static async Task CreateProjectFromTemplate(string packageId, string name) + { + var repository = Directory.GetDirectoryNameOfFileAbove(AppContext.BaseDirectory, "global.json") + ?? throw new InvalidOperationException("Could not locate the repository root containing global.json."); + var package = Path.Combine(repository, "artifacts", "package", "release"); + + var project = new Project(Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), $"arcade-sdk-test-{Guid.NewGuid():N}"))); + project.CopyFrom(Path.Combine(repository, "src", "sdk.tests", "fixtures", name)); + await project.Template("nuget.config", "{0}", package); + await project.Template("project.csproj", "{0}", Feed[packageId]); + + return project; + } + + private sealed record PackageSearchResponse( + [property: JsonPropertyName("searchResult")] + IReadOnlyList SearchResults); + + private sealed record PackageSearchSource( + [property: JsonPropertyName("packages")] + IReadOnlyList Packages); + + private sealed record PackageSearchPackage( + [property: JsonPropertyName("id")] string Id, + [property: JsonPropertyName("latestVersion")] + string LatestVersion); +} diff --git a/src/sdk.tests/SdkPackageIntegrationTests.cs b/src/sdk.tests/SdkPackageIntegrationTests.cs deleted file mode 100644 index d254336..0000000 --- a/src/sdk.tests/SdkPackageIntegrationTests.cs +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) The Geekeey Authors -// SPDX-License-Identifier: EUPL-1.2 - -using System.Diagnostics; -using System.Text.RegularExpressions; - -namespace Geekeey.Arcade.NET.Tests; - -public sealed class SdkPackageIntegrationTests -{ - - private static string RepositoryPath - { - get - { - for (var directory = new DirectoryInfo(AppContext.BaseDirectory); directory is not null; directory = directory.Parent) - { - if (File.Exists(Path.Combine(directory.FullName, "global.json"))) - { - return directory.FullName; - } - } - - throw new InvalidOperationException("Could not locate the repository root containing global.json."); - } - } - - private static string NuGetFeedPath { get; } = Path.Combine(RepositoryPath, "artifacts", "package", "release"); - - [Test] - [Arguments("Geekeey.Arcade.NET.Sdk", "base")] - [Arguments("Geekeey.Arcade.NET.Sdk.Razor", "razor")] - [Arguments("Geekeey.Arcade.NET.Sdk.Web", "web")] - public async Task SdkPackageCanBeConsumedFromAFeed(string packageId, string name) - { - // Arrange - var version = FindPackageVersion(packageId); - using var sut = await SdkTestProject.CreateAsync(name, version); - - // Act - await sut.RunDotnetAsync($"restore --configfile \"{sut.NuGetConfigPath}\" --packages \"{sut.PackagesPath}\" --nologo"); - await sut.RunDotnetAsync("build --no-restore --nologo"); - await sut.RunDotnetAsync($"pack --no-restore --configuration Debug --output \"{sut.PackedPath}\" --nologo"); - - // Assert - await Assert.That(File.Exists(Path.Combine(sut.ProjectPath, "bin", "Debug", "net10.0", $"{sut.ProjectName}.dll"))).IsTrue(); - await Assert.That(Directory.Exists(sut.PackedPath)).IsTrue(); - await Assert.That(Directory.EnumerateFiles(sut.PackedPath, $"{sut.ProjectName}.*.nupkg").Any()).IsTrue(); - } - - [Test] - public async Task TestSdkPackageStoresTestOutputInArtifacts() - { - // Arrange - var version = FindPackageVersion("Geekeey.Arcade.NET.Sdk.Test"); - using var sut = await SdkTestProject.CreateAsync("test", version); - await sut.RunDotnetAsync($"restore --configfile \"{sut.NuGetConfigPath}\" --packages \"{sut.PackagesPath}\" --nologo"); - await sut.RunDotnetAsync("build --no-restore --nologo"); - - var outputDirectory = Path.Combine(sut.ProjectPath, "artifacts", "bin", sut.ProjectName, "debug"); - await Assert.That(File.Exists(Path.Combine(outputDirectory, $"{sut.ProjectName}.dll"))).IsTrue(); - - // Act - var stdout = await sut.RunDotnetAsync("run --no-build --no-restore"); - - // Assert - await Assert.That(stdout.Contains("succeeded: 1", StringComparison.Ordinal)).IsTrue(); - } - - private static string FindPackageVersion(string packageId) - { - var pattern = $"""^{Regex.Escape(packageId)}\.(?\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)\.nupkg$"""; - foreach (var package in Directory.EnumerateFiles(NuGetFeedPath, "*.nupkg")) - { - var match = Regex.Match(Path.GetFileName(package), pattern, RegexOptions.CultureInvariant); - if (match.Success) - { - return match.Groups["version"].Value; - } - } - - throw new InvalidOperationException($"No current package found for {packageId}. Run dotnet pack first."); - } - - private sealed class SdkTestProject : IDisposable - { - private SdkTestProject(string root) - { - RootPath = root; - ProjectPath = Path.Combine(RootPath, "Project"); - PackagesPath = Path.Combine(RootPath, "packages"); - PackedPath = Path.Combine(RootPath, "packed"); - NuGetConfigPath = Path.Combine(RootPath, "NuGet.config"); - } - - public static async Task CreateAsync(string name, string version) - { - var sut = new SdkTestProject(Path.Combine(Path.GetTempPath(), $"arcade-sdk-test-{Guid.NewGuid():N}")); - try - { - Directory.CreateDirectory(sut.ProjectPath); - Directory.Copy(Path.Combine(AppContext.BaseDirectory, "fixtures", name), sut.ProjectPath); - sut.ProjectFilePath = Directory.EnumerateFiles(sut.ProjectPath, "*.csproj").Single(); - sut.ProjectName = Path.GetFileNameWithoutExtension(sut.ProjectFilePath); - var project = await File.ReadAllTextAsync(sut.ProjectFilePath); - await File.WriteAllTextAsync(sut.ProjectFilePath, project.Replace("{0}", version, StringComparison.Ordinal)); - var contents = $""" - - - - - - - - """; - await File.WriteAllTextAsync(sut.NuGetConfigPath, contents); - return sut; - } - catch - { - sut.Dispose(); - throw; - } - } - - public string RootPath { get; } - - public string ProjectPath { get; } - - public string ProjectFilePath { get; private set; } = ""; - - public string ProjectName { get; private set; } = ""; - - public string PackagesPath { get; } - - public string PackedPath { get; } - - public string NuGetConfigPath { get; } - - public async Task RunDotnetAsync(string arguments) - { - var startInfo = new ProcessStartInfo("dotnet", arguments) - { - WorkingDirectory = ProjectPath, - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true, - Environment = - { - ["NUGET_PACKAGES"] = PackagesPath, - ["DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER"] = "1", - ["TUNIT_DISABLE_GITHUB_REPORTER"] = "true" - } - }; - var process = Process.Start(startInfo) ?? throw new InvalidOperationException("Could not start dotnet."); - var output = await process.StandardOutput.ReadToEndAsync(); - var error = await process.StandardError.ReadToEndAsync(); - await process.WaitForExitAsync(); - return process.ExitCode is 0 ? output : throw new InvalidOperationException($"dotnet {arguments} failed with exit code {process.ExitCode}.\n{output}\n{error}"); - } - - public void Dispose() - { - Directory.Delete(RootPath, recursive: true); - } - } -} diff --git a/src/sdk.tests/_shared/Command.cs b/src/sdk.tests/_shared/Command.cs new file mode 100644 index 0000000..a5c8667 --- /dev/null +++ b/src/sdk.tests/_shared/Command.cs @@ -0,0 +1,75 @@ +// Copyright (c) The Geekeey Authors +// SPDX-License-Identifier: EUPL-1.2 + +using System.Diagnostics; + +namespace Geekeey.Arcade.NET.Tests; + +internal sealed record Command(string WorkingDirectory, IEnumerable> Environment) +{ + public bool ThrowOnExit { get; init; } + + public static Command WithWorkingDirectory(string path) + { + return new Command(path, []); + } + + public Command WithEnvironment(string name, string value) + { + return WithEnvironment([new KeyValuePair(name, value)]); + } + + public Command WithEnvironment(IEnumerable> environment) + { + var env = new Dictionary(Environment); + + foreach (var pair in environment) + { + env[pair.Key] = pair.Value; + } + + return this with { Environment = env }; + } + + public Command WithThrowOnExit() + { + return this with { ThrowOnExit = true }; + } + + public async Task RunAsync(string exe, params IReadOnlyList args) + { + ArgumentNullException.ThrowIfNull(args); + + var startInfo = new ProcessStartInfo(exe) + { + WorkingDirectory = WorkingDirectory, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + foreach (var argument in args) + { + startInfo.ArgumentList.Add(argument); + } + + foreach (var pair in Environment) + { + startInfo.Environment[pair.Key] = pair.Value; + } + + var process = Process.Start(startInfo) ?? throw new InvalidOperationException("Could not start dotnet."); + var output = await process.StandardOutput.ReadToEndAsync(); + var error = await process.StandardError.ReadToEndAsync(); + + await process.WaitForExitAsync(); + + if (ThrowOnExit && process.ExitCode is not 0) + { + throw new InvalidOperationException($"'{exe}' exited with code {process.ExitCode}.{System.Environment.NewLine}{error}{output}"); + } + + return new CommandOutput(output, error, process.ExitCode); + } +} diff --git a/src/sdk.tests/_shared/CommandOutput.cs b/src/sdk.tests/_shared/CommandOutput.cs new file mode 100644 index 0000000..3ba2910 --- /dev/null +++ b/src/sdk.tests/_shared/CommandOutput.cs @@ -0,0 +1,6 @@ +// Copyright (c) The Geekeey Authors +// SPDX-License-Identifier: EUPL-1.2 + +namespace Geekeey.Arcade.NET.Tests; + +internal sealed record CommandOutput(string StdOut, string StdErr, int ExitCode); diff --git a/src/sdk.tests/_shared/Project.cs b/src/sdk.tests/_shared/Project.cs new file mode 100644 index 0000000..7fb3edb --- /dev/null +++ b/src/sdk.tests/_shared/Project.cs @@ -0,0 +1,65 @@ +// Copyright (c) The Geekeey Authors +// SPDX-License-Identifier: EUPL-1.2 + +namespace Geekeey.Arcade.NET.Tests; + +internal sealed class Project : IDisposable +{ + private readonly DirectoryInfo _root; + private readonly Command _shell; + + public Project(DirectoryInfo root) + { + _root = root; + _shell = Command.WithWorkingDirectory(_root.FullName) + .WithEnvironment("DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER", "1") + .WithEnvironment("TUNIT_DISABLE_GITHUB_REPORTER", "true") + .WithEnvironment("NUGET_PACKAGES", System.IO.Path.Combine(_root.FullName, "packages")); + } + + public string Path + { + get => _root.FullName; + } + + public Task RunAsync(string exe, params IReadOnlyList args) + { + return _shell.RunAsync(exe, args); + } + + public void CopyFrom(string path) + { + System.IO.Directory.Copy(path, _root.FullName); + } + + public FileInfo File(params IReadOnlyList path) + { + return new FileInfo(System.IO.Path.Combine([_root.FullName, .. path])); + } + + public DirectoryInfo Directory(params IReadOnlyList path) + { + return new DirectoryInfo(System.IO.Path.Combine([_root.FullName, .. path])); + } + + public async Task Template(string path, string from, string insert) + { + string content; + var file = File(path); + + using (var text = file.OpenText()) + { + content = await text.ReadToEndAsync(); + } + + content = content.Replace(from, insert, StringComparison.Ordinal); + + await using var writer = new StreamWriter(file.OpenWrite()); + await writer.WriteAsync(content); + } + + public void Dispose() + { + _root.Delete(recursive: true); + } +} diff --git a/src/sdk.tests/fixtures/base/nuget.config b/src/sdk.tests/fixtures/base/nuget.config new file mode 100644 index 0000000..c2bf5ad --- /dev/null +++ b/src/sdk.tests/fixtures/base/nuget.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/sdk.tests/fixtures/base/BaseConsumer.csproj b/src/sdk.tests/fixtures/base/project.csproj similarity index 62% rename from src/sdk.tests/fixtures/base/BaseConsumer.csproj rename to src/sdk.tests/fixtures/base/project.csproj index 65f8f3f..e715221 100644 --- a/src/sdk.tests/fixtures/base/BaseConsumer.csproj +++ b/src/sdk.tests/fixtures/base/project.csproj @@ -1,9 +1,7 @@ net10.0 - true - false - BaseConsumer + My.Package IDE0055 diff --git a/src/sdk.tests/fixtures/razor/nuget.config b/src/sdk.tests/fixtures/razor/nuget.config new file mode 100644 index 0000000..c2bf5ad --- /dev/null +++ b/src/sdk.tests/fixtures/razor/nuget.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/sdk.tests/fixtures/razor/RazorConsumer.csproj b/src/sdk.tests/fixtures/razor/project.csproj similarity index 63% rename from src/sdk.tests/fixtures/razor/RazorConsumer.csproj rename to src/sdk.tests/fixtures/razor/project.csproj index b3de58d..6f55742 100644 --- a/src/sdk.tests/fixtures/razor/RazorConsumer.csproj +++ b/src/sdk.tests/fixtures/razor/project.csproj @@ -1,8 +1,7 @@ net10.0 - RazorConsumer - false + My.Package IDE0055 diff --git a/src/sdk.tests/fixtures/test/Directory.Build.props b/src/sdk.tests/fixtures/test/Directory.Build.props deleted file mode 100644 index 1b15241..0000000 --- a/src/sdk.tests/fixtures/test/Directory.Build.props +++ /dev/null @@ -1,5 +0,0 @@ - - - $(MSBuildProjectDirectory)/artifacts/ - - diff --git a/src/sdk.tests/fixtures/test/nuget.config b/src/sdk.tests/fixtures/test/nuget.config new file mode 100644 index 0000000..c2bf5ad --- /dev/null +++ b/src/sdk.tests/fixtures/test/nuget.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/sdk.tests/fixtures/test/TestConsumer.csproj b/src/sdk.tests/fixtures/test/project.csproj similarity index 67% rename from src/sdk.tests/fixtures/test/TestConsumer.csproj rename to src/sdk.tests/fixtures/test/project.csproj index 6f86a2d..7c47748 100644 --- a/src/sdk.tests/fixtures/test/TestConsumer.csproj +++ b/src/sdk.tests/fixtures/test/project.csproj @@ -1,10 +1,7 @@ net10.0 - true - false - TestConsumer - true + My.Package Exe IDE0055 diff --git a/src/sdk.tests/fixtures/web/nuget.config b/src/sdk.tests/fixtures/web/nuget.config new file mode 100644 index 0000000..c2bf5ad --- /dev/null +++ b/src/sdk.tests/fixtures/web/nuget.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/sdk.tests/fixtures/web/WebConsumer.csproj b/src/sdk.tests/fixtures/web/project.csproj similarity index 67% rename from src/sdk.tests/fixtures/web/WebConsumer.csproj rename to src/sdk.tests/fixtures/web/project.csproj index 3d9e2d9..2af4418 100644 --- a/src/sdk.tests/fixtures/web/WebConsumer.csproj +++ b/src/sdk.tests/fixtures/web/project.csproj @@ -1,9 +1,7 @@ net10.0 - true - false - WebConsumer + My.Package Exe IDE0055 diff --git a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Geekeey.Arcade.NET.Sdk.Test.csproj b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Geekeey.Arcade.NET.Sdk.Test.csproj index be50037..331bdd6 100644 --- a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Geekeey.Arcade.NET.Sdk.Test.csproj +++ b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Geekeey.Arcade.NET.Sdk.Test.csproj @@ -23,5 +23,8 @@ + + + diff --git a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.props b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.props index 7c6b9dd..424b3f8 100644 --- a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.props +++ b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.props @@ -14,4 +14,6 @@ + + diff --git a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.targets b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.targets index c34d867..2dc83c8 100644 --- a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.targets +++ b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/Sdk.targets @@ -1,3 +1,5 @@ + + diff --git a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.cs b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.cs new file mode 100644 index 0000000..e44ef9a --- /dev/null +++ b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.cs @@ -0,0 +1,60 @@ +// Copyright (c) The Geekeey Authors +// SPDX-License-Identifier: EUPL-1.2 +// +// This file is generated into the test project by Geekeey.Arcade.NET.Sdk.Test. +// + +#nullable enable +#pragma warning disable TPEXP + +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.CommandLine; +using Microsoft.Testing.Platform.Configurations; + +namespace Geekeey.Arcade.NET.Sdk.Test; + +public static class TestingPlatformExtensions +{ + public static void AddExtensions(ITestApplicationBuilder builder, string[] arguments) + { + builder.Configuration.AddConfigurationSource(() => new ResultDirectoryConfigurationSource()); + } + + public static class TestingPlatformBuilderHook + { + public static void AddExtensions(ITestApplicationBuilder builder, string[] arguments) + => TestingPlatformExtensions.AddExtensions(builder, arguments); + } + + private sealed class ResultDirectoryConfigurationSource : IConfigurationSource + { + public string Uid => "Geekeey.Arcade.NET.Sdk.Test.TestingPlatformExtensions"; + public string Version => "1.0.0"; + public string DisplayName => "Geekeey Arcade Testing Platform extensions"; + public string Description => "Uses the artifacts directory for test results by default."; + + public Task IsEnabledAsync() => Task.FromResult(true); + + public int Order => 4; + + public Task BuildAsync(CommandLineParseResult commandLineParseResult) + => Task.FromResult(new ResultDirectoryConfigurationProvider()); + } + + private sealed class ResultDirectoryConfigurationProvider : IConfigurationProvider + { + public Task LoadAsync() => Task.CompletedTask; + + public bool TryGet(string key, out string? value) + { + if (string.Equals(key, "platformOptions:resultDirectory", StringComparison.OrdinalIgnoreCase)) + { + value = @"__ARTIFACTS_PATH__"; + return true; + } + + value = null; + return false; + } + } +} diff --git a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.props b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.props new file mode 100644 index 0000000..506ddc2 --- /dev/null +++ b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.props @@ -0,0 +1,9 @@ + + + + + Geekeey Arcade Testing Platform extensions + Geekeey.Arcade.NET.Sdk.Test.TestingPlatformExtensions.TestingPlatformBuilderHook + + + diff --git a/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.targets b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.targets new file mode 100644 index 0000000..b864b93 --- /dev/null +++ b/src/sdk/Sdk/Geekeey.Arcade.NET.Sdk.Test/extensions/TestingPlatformExtensions.targets @@ -0,0 +1,31 @@ + + + <_ArcadeTestingPlatformExtensionsSourcePath>$(MSBuildThisFileDirectory)../common/source/TestingPlatformExtensions.cs + <_ArcadeTestingPlatformExtensionsGeneratedPath>$(IntermediateOutputPath)TestingPlatformExtensions.g.cs + + + + + + + + <_ArcadeTestingPlatformExtensionsSourceLineWithPath Include="@(_ArcadeTestingPlatformExtensionsSourceLine->Replace('__ARTIFACTS_PATH__', '$(ArtifactsPath)'))" /> + + + + + + + + + + +