From bfe6718fceae958cc04bc979a6029afcdf6ba86b Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Tue, 6 Feb 2024 12:30:01 +0000 Subject: [PATCH] Allow the integration tests to run on .NET Framework (#1286) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Allow the integration tests to run on .NET Framework * Update appveyor.yml * Update appveyor.yml --------- Co-authored-by: Wojciech Nagórski --- appveyor.yml | 5 ++-- test/Renci.SshNet.IntegrationTests/App.config | 23 ------------------- .../Common/DateTimeExtensions.cs | 4 +--- .../HostConfig.cs | 4 ++++ .../ForwardedPortLocalTest.cs | 15 +++++++----- .../OldIntegrationTests/SftpClientTest.cs | 6 ++++- test/Renci.SshNet.IntegrationTests/Program.cs | 11 --------- .../Renci.SshNet.IntegrationTests.csproj | 3 ++- .../Renci.SshNet.TestTools.OpenSSH.csproj | 2 +- .../SshdConfig.cs | 2 +- 10 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 test/Renci.SshNet.IntegrationTests/App.config delete mode 100644 test/Renci.SshNet.IntegrationTests/Program.cs diff --git a/appveyor.yml b/appveyor.yml index 98487674..b0a5bf2e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,13 +19,14 @@ for: build_script: - echo build - - dotnet build Renci.SshNet.sln -c Debug -f net8.0 + - dotnet build -f net8.0 -c Debug test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj + - dotnet build -f net8.0 -c Debug test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj test_script: - sh: echo "Run unit tests" - sh: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_unit_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_unit_test_net_8_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj - sh: echo "Run integration tests" - - sh: dotnet test -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_8_coverage.xml test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj + - sh: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_8_coverage.xml test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj # on_failure: # - sh: appveyor PushArtifact artifacts/tcpdump.pcap diff --git a/test/Renci.SshNet.IntegrationTests/App.config b/test/Renci.SshNet.IntegrationTests/App.config deleted file mode 100644 index c9794e84..00000000 --- a/test/Renci.SshNet.IntegrationTests/App.config +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/Renci.SshNet.IntegrationTests/Common/DateTimeExtensions.cs b/test/Renci.SshNet.IntegrationTests/Common/DateTimeExtensions.cs index d9f0d22e..7617d1d6 100644 --- a/test/Renci.SshNet.IntegrationTests/Common/DateTimeExtensions.cs +++ b/test/Renci.SshNet.IntegrationTests/Common/DateTimeExtensions.cs @@ -4,9 +4,7 @@ { public static DateTime TruncateToWholeSeconds(this DateTime dateTime) { - return dateTime.AddMilliseconds(-dateTime.Millisecond) - .AddMicroseconds(-dateTime.Microsecond) - .AddTicks(-(dateTime.Nanosecond / 100)); + return new DateTime(dateTime.Ticks - (dateTime.Ticks % TimeSpan.TicksPerSecond), dateTime.Kind); } } } diff --git a/test/Renci.SshNet.IntegrationTests/HostConfig.cs b/test/Renci.SshNet.IntegrationTests/HostConfig.cs index c328a729..fd3c3f13 100644 --- a/test/Renci.SshNet.IntegrationTests/HostConfig.cs +++ b/test/Renci.SshNet.IntegrationTests/HostConfig.cs @@ -29,7 +29,11 @@ namespace Renci.SshNet.IntegrationTests while ((line = sr.ReadLine()) != null) { // skip comments +#if NET if (line.StartsWith('#')) +#else + if (line.StartsWith("#")) +#endif { continue; } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs index ec28a738..09ce7cd7 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs @@ -1,4 +1,7 @@ using System.Diagnostics; +#if !NET6_0_OR_GREATER +using System.Net; +#endif using Renci.SshNet.Common; @@ -46,8 +49,8 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests .GetAwaiter() .GetResult(); #else - var request = (HttpWebRequest) WebRequest.Create(url); - var response = (HttpWebResponse) request.GetResponse(); + var request = (HttpWebRequest) WebRequest.Create(url); + var response = (HttpWebResponse) request.GetResponse(); #endif // NET6_0_OR_GREATER Assert.IsNotNull(response); @@ -122,10 +125,10 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests { var data = ReadStream(response.Content.ReadAsStream()); #else - var request = (HttpWebRequest) WebRequest.Create("http://localhost:8084"); - using (var response = (HttpWebResponse) request.GetResponse()) - { - var data = ReadStream(response.GetResponseStream()); + var request = (HttpWebRequest) WebRequest.Create("http://localhost:8084"); + using (var response = (HttpWebResponse) request.GetResponse()) + { + var data = ReadStream(response.GetResponseStream()); #endif // NET6_0_OR_GREATER var end = DateTime.Now; diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.cs index 1c7def55..3c49e60f 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.cs @@ -14,7 +14,11 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests { using (FileStream file = new FileStream(fileName, FileMode.Open)) { - var hash = MD5.HashData(file); + byte[] hash; + using (var md5 = MD5.Create()) + { + hash = md5.ComputeHash(file); + } file.Close(); diff --git a/test/Renci.SshNet.IntegrationTests/Program.cs b/test/Renci.SshNet.IntegrationTests/Program.cs deleted file mode 100644 index af2b60d5..00000000 --- a/test/Renci.SshNet.IntegrationTests/Program.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Renci.SshNet.IntegrationTests -{ - class Program - { -#if NETFRAMEWORK - private static void Main() - { - } -#endif - } -} diff --git a/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj b/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj index f55b6744..109da05d 100644 --- a/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj +++ b/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj @@ -1,11 +1,12 @@  - net8.0 + net48;net8.0 enable false true $(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010 + true diff --git a/test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj b/test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj index b6066153..a6dbd202 100644 --- a/test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj +++ b/test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj @@ -1,6 +1,6 @@  - net8.0 + netstandard2.0 enable enable $(NoWarn);SYSLIB0021;SYSLIB1045 diff --git a/test/Renci.SshNet.TestTools.OpenSSH/SshdConfig.cs b/test/Renci.SshNet.TestTools.OpenSSH/SshdConfig.cs index 5e302571..048e1ca7 100644 --- a/test/Renci.SshNet.TestTools.OpenSSH/SshdConfig.cs +++ b/test/Renci.SshNet.TestTools.OpenSSH/SshdConfig.cs @@ -329,7 +329,7 @@ namespace Renci.SshNet.TestTools.OpenSSH sshdConfig.KeyboardInteractiveAuthentication = ToBool(value); break; case "LogLevel": - sshdConfig.LogLevel = Enum.Parse(value, ignoreCase: true); + sshdConfig.LogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), value, ignoreCase: true); break; case "Subsystem": sshdConfig.Subsystems.Add(Subsystem.FromConfig(value));