From 49e31c220fb11fd1ea1016a85ae47a4ef00ccac6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 6 Jan 2021 15:39:08 +0100 Subject: [PATCH] Minor code style tweaks --- .../NativeLibrariesResolverTests.cs | 63 ++++++++++++------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs b/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs index 6be4765f..86e61ea8 100644 --- a/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs +++ b/tests/ComputeSharp.Tests.NativeLibrariesResolver/NativeLibrariesResolverTests.cs @@ -4,13 +4,18 @@ using System.Diagnostics; using System.IO; [assembly: Parallelize(Workers = 0, Scope = ExecutionScope.ClassLevel)] + namespace ComputeSharp.Tests.NativeLibrariesResolver { [TestClass] public class NativeLibrariesResolverTests { + /// + /// Performs static initialization for the assembly before any unit tests are run. + /// + /// The for the test runner instance in use. [AssemblyInitialize] - public static void Initialize(TestContext context) + public static void Initialize(TestContext _) { string path = Path.GetDirectoryName(typeof(NativeLibrariesResolverTests).Assembly.Location); @@ -23,7 +28,7 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver string packagingProjectPath = Path.Combine(path, "src", "ComputeSharp.Package", "ComputeSharp.Package.msbuildproj"); - // Run dotnet pack and on the packaging project, to ensure the local NuGet package is available. + // Run dotnet pack and on the packaging project, to ensure the local NuGet package is available Process.Start("dotnet", $"pack {packagingProjectPath} -c Release").WaitForExit(); } @@ -114,23 +119,15 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver [DataRow(PublishMode.FrameworkDependent, DeploymentMode.SingleFile, NativeLibrariesDeploymentMode.ExtractToTemporaryDirectory)] public void DotnetPublishWorks(PublishMode publishMode, DeploymentMode deploymentMode, NativeLibrariesDeploymentMode nativeLibsDeploymentMode) { - // Publishing without specifying a RID is not supported - // We do not test Debug builds as it was determined that they are not an important scenario + // Publishing without specifying a RID is not supported. + // Furthermore, only publishing in Release mode is tested. CleanSampleProject(Configuration.Release, RID.Win_x64); Exec(SampleProjectDirectory, "dotnet", $"publish -c Release -r win-x64 {ToOption(publishMode)} {ToOption(deploymentMode)} {ToOption(nativeLibsDeploymentMode)} /bl"); - string pathToAppHost = Path.Combine("bin", $"Release", "net5.0", "win-x64", "publish", "ComputeSharp.Sample.NuGet.exe"); - Assert.AreEqual(0, Exec(SampleProjectDirectory, pathToAppHost, "")); - } - /// - /// Builds the sample project with a specific configuration and target runtime. - /// - /// The configuration to use to build the project. - /// The RID to use to build the project. - private static void BuildSampleProject(Configuration configuration, RID rid) - { - Exec(SampleProjectDirectory, "dotnet", $"build -c {configuration} {ToOption(rid)}"); + string pathToAppHost = Path.Combine("bin", $"Release", "net5.0", "win-x64", "publish", "ComputeSharp.Sample.NuGet.exe"); + + Assert.AreEqual(0, Exec(SampleProjectDirectory, pathToAppHost, "")); } /// @@ -145,6 +142,16 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver Exec(SampleProjectDirectory, "dotnet", $"clean -c {configuration} {ToOption(rid)}"); } + /// + /// Builds the sample project with a specific configuration and target runtime. + /// + /// The configuration to use to build the project. + /// The RID to use to build the project. + private static void BuildSampleProject(Configuration configuration, RID rid) + { + Exec(SampleProjectDirectory, "dotnet", $"build -c {configuration} {ToOption(rid)}"); + } + /// /// Executes a specified process from the command line and returns the exit code. /// @@ -172,7 +179,7 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver } /// - /// Gets a text representation of a cmd option for the dotnet tool, for the given . + /// Gets a text representation of the command line argument for the given . /// /// The input value. /// A text representation for . @@ -183,6 +190,11 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver _ => throw new InvalidEnumArgumentException(nameof(rid), (int)rid, typeof(RID)) }; + /// + /// Gets a text representation of the command line argument for the given . + /// + /// The input value. + /// A text representation for . private static string ToOption(PublishMode publishMode) => publishMode switch { PublishMode.FrameworkDependent => "--self-contained false", @@ -190,6 +202,11 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver _ => throw new InvalidEnumArgumentException(nameof(publishMode), (int)publishMode, typeof(PublishMode)) }; + /// + /// Gets a text representation of the command line argument for the given . + /// + /// The input value. + /// A text representation for . private static string ToOption(DeploymentMode deploymentMode) => deploymentMode switch { DeploymentMode.Multiassembly => "/p:PublishSingleFile=false", @@ -197,6 +214,11 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver _ => throw new InvalidEnumArgumentException(nameof(deploymentMode), (int)deploymentMode, typeof(DeploymentMode)) }; + /// + /// Gets a text representation of the command line argument for the given . + /// + /// The input value. + /// A text representation for . private static string ToOption(NativeLibrariesDeploymentMode deploymentMode) => deploymentMode switch { NativeLibrariesDeploymentMode.NotApplicable => "", @@ -236,7 +258,7 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver } /// - /// Publish mode: should the application carry the framework with itself. + /// Indicates how should the application carry the framework with itself. /// public enum PublishMode { @@ -245,9 +267,8 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver } /// - /// Deployment mode: how should the application be packaged. - /// Notably, these tests employ .NET 5 style SingleFile, aka SuperHost. - /// It does not affect native libraries packaging in .NET 5, but may in the future. + /// Indicates how should the application be packaged. Notably, these tests employ .NET 5 style SingleFile, + /// aka SuperHost. It does not affect native libraries packaging in .NET 5, but may in the future. /// public enum DeploymentMode { @@ -256,7 +277,7 @@ namespace ComputeSharp.Tests.NativeLibrariesResolver } /// - /// Deployment mode for application's native dependencies. + /// Indicates the deployment mode for application's native dependencies. /// Not applicable to multiassembly deployment mode. /// public enum NativeLibrariesDeploymentMode