From b4d7e4f986df76a4c8b936609f52eb01b4881045 Mon Sep 17 00:00:00 2001 From: Maytham Fahmi <9260645+maythamfahmi@users.noreply.github.com> Date: Mon, 21 Oct 2024 06:27:11 +0200 Subject: [PATCH] #107 fix cross platform file name --- .../Examples.UnitTests/AESExampleTests.cs | 21 ++++++++++++------- .../Examples.UnitTests/ExampleTestBase.cs | 4 ++-- .../Examples.UnitTests/RSAExampleTests.cs | 21 ++++++++++++------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Examples/Examples.UnitTests/AESExampleTests.cs b/Examples/Examples.UnitTests/AESExampleTests.cs index 0faa81b..c7b577e 100644 --- a/Examples/Examples.UnitTests/AESExampleTests.cs +++ b/Examples/Examples.UnitTests/AESExampleTests.cs @@ -8,14 +8,19 @@ namespace CryptoNet.Examples.UnitTests; [TestFixture] public class AESExampleTests : ExampleTestBase { - private const string AESExampleExeName = "AESExample.exe"; - - //[Ignore("temp")] [Test] public async Task AESExampleSmokeTest() { - // ToDo: Missing executables on Linux and MacOS. - if (Environment.OSVersion.Platform != PlatformID.Win32NT) return; + string aesExampleExeName; + + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + aesExampleExeName = "AESExample.exe"; // Windows executable + } + else + { + aesExampleExeName = "AESExample"; // Linux or MacOs executable + } // This provides a human readable temporary directory name prefix. // If you see a lot of these laying around your temp directory, it's @@ -28,11 +33,11 @@ public async Task AESExampleSmokeTest() using (var tmpDir = new TempDirectory(tmpDirPrefix)) { ClassicAssert.IsTrue(Directory.Exists(tmpDir.DirectoryInfo.FullName)); - ClassicAssert.IsTrue(File.Exists(AESExampleExeName)); + ClassicAssert.IsTrue(File.Exists(aesExampleExeName)); - ShowAvailableExecutables(); + ShowAvailableExecutables(aesExampleExeName); - var result = await Cli.Wrap(AESExampleExeName) + var result = await Cli.Wrap(aesExampleExeName) .WithWorkingDirectory(tmpDir.DirectoryInfo.FullName) .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer)) .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer)) diff --git a/Examples/Examples.UnitTests/ExampleTestBase.cs b/Examples/Examples.UnitTests/ExampleTestBase.cs index d28fe34..a8be13f 100644 --- a/Examples/Examples.UnitTests/ExampleTestBase.cs +++ b/Examples/Examples.UnitTests/ExampleTestBase.cs @@ -4,10 +4,10 @@ namespace CryptoNet.Examples.UnitTests; public class ExampleTestBase { - public void ShowAvailableExecutables() + public void ShowAvailableExecutables(string filename) { Console.WriteLine("Available .exe files in CWD:"); - foreach (var fileName in Directory.GetFiles(".", "*.exe")) + foreach (var fileName in Directory.GetFiles(".", filename)) { Console.WriteLine(fileName); } diff --git a/Examples/Examples.UnitTests/RSAExampleTests.cs b/Examples/Examples.UnitTests/RSAExampleTests.cs index d8147f2..1a8c586 100644 --- a/Examples/Examples.UnitTests/RSAExampleTests.cs +++ b/Examples/Examples.UnitTests/RSAExampleTests.cs @@ -8,14 +8,19 @@ namespace CryptoNet.Examples.UnitTests; [TestFixture] public class RSAExampleTests : ExampleTestBase { - private const string RSAExampleExeName = "RSAExample.exe"; - - //[Ignore("temp")] [Test] public async Task RSAExampleSmokeTest() { - // ToDo: Missing executables on Linux and MacOS. - if (Environment.OSVersion.Platform != PlatformID.Win32NT) return; + string rsaExampleExeName; + + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + { + rsaExampleExeName = "RSAExample.exe"; // Windows executable + } + else + { + rsaExampleExeName = "RSAExample"; // Linux or MacOs executable + } var tmpDirPrefix = $"{nameof(AESExampleTests)}.{nameof(RSAExampleSmokeTest)}-{Guid.NewGuid().ToString("D")}"; @@ -25,11 +30,11 @@ public async Task RSAExampleSmokeTest() using (var tmpDir = new TempDirectory()) { ClassicAssert.IsTrue(Directory.Exists(tmpDir.DirectoryInfo.FullName)); - ClassicAssert.IsTrue(File.Exists(RSAExampleExeName)); + ClassicAssert.IsTrue(File.Exists(rsaExampleExeName)); - ShowAvailableExecutables(); + ShowAvailableExecutables(rsaExampleExeName); - var result = await Cli.Wrap(RSAExampleExeName) + var result = await Cli.Wrap(rsaExampleExeName) .WithWorkingDirectory(tmpDir.DirectoryInfo.FullName) .WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutBuffer)) .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer))