Skip to content

Commit bfe6718

Browse files
Allow the integration tests to run on .NET Framework (#1286)
* Allow the integration tests to run on .NET Framework * Update appveyor.yml * Update appveyor.yml --------- Co-authored-by: Wojciech Nagórski <[email protected]>
1 parent 47eabe7 commit bfe6718

File tree

10 files changed

+26
-49
lines changed

10 files changed

+26
-49
lines changed

appveyor.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ for:
1919

2020
build_script:
2121
- echo build
22-
- dotnet build Renci.SshNet.sln -c Debug -f net8.0
22+
- dotnet build -f net8.0 -c Debug test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
23+
- dotnet build -f net8.0 -c Debug test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
2324

2425
test_script:
2526
- sh: echo "Run unit tests"
2627
- 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
2728
- sh: echo "Run integration tests"
28-
- 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
29+
- 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
2930

3031
# on_failure:
3132
# - sh: appveyor PushArtifact artifacts/tcpdump.pcap

test/Renci.SshNet.IntegrationTests/App.config

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/Renci.SshNet.IntegrationTests/Common/DateTimeExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ public static class DateTimeExtensions
44
{
55
public static DateTime TruncateToWholeSeconds(this DateTime dateTime)
66
{
7-
return dateTime.AddMilliseconds(-dateTime.Millisecond)
8-
.AddMicroseconds(-dateTime.Microsecond)
9-
.AddTicks(-(dateTime.Nanosecond / 100));
7+
return new DateTime(dateTime.Ticks - (dateTime.Ticks % TimeSpan.TicksPerSecond), dateTime.Kind);
108
}
119
}
1210
}

test/Renci.SshNet.IntegrationTests/HostConfig.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public static HostConfig Read(ScpClient scpClient, string path)
2929
while ((line = sr.ReadLine()) != null)
3030
{
3131
// skip comments
32+
#if NET
3233
if (line.StartsWith('#'))
34+
#else
35+
if (line.StartsWith("#"))
36+
#endif
3337
{
3438
continue;
3539
}

test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System.Diagnostics;
2+
#if !NET6_0_OR_GREATER
3+
using System.Net;
4+
#endif
25

36
using Renci.SshNet.Common;
47

@@ -46,8 +49,8 @@ public void Test_PortForwarding_Local_Stop_Hangs_On_Wait()
4649
.GetAwaiter()
4750
.GetResult();
4851
#else
49-
var request = (HttpWebRequest) WebRequest.Create(url);
50-
var response = (HttpWebResponse) request.GetResponse();
52+
var request = (HttpWebRequest) WebRequest.Create(url);
53+
var response = (HttpWebResponse) request.GetResponse();
5154
#endif // NET6_0_OR_GREATER
5255

5356
Assert.IsNotNull(response);
@@ -122,10 +125,10 @@ public void Test_PortForwarding_Local_Without_Connecting()
122125
{
123126
var data = ReadStream(response.Content.ReadAsStream());
124127
#else
125-
var request = (HttpWebRequest) WebRequest.Create("http://localhost:8084");
126-
using (var response = (HttpWebResponse) request.GetResponse())
127-
{
128-
var data = ReadStream(response.GetResponseStream());
128+
var request = (HttpWebRequest) WebRequest.Create("http://localhost:8084");
129+
using (var response = (HttpWebResponse) request.GetResponse())
130+
{
131+
var data = ReadStream(response.GetResponseStream());
129132
#endif // NET6_0_OR_GREATER
130133
var end = DateTime.Now;
131134

test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ protected static string CalculateMD5(string fileName)
1414
{
1515
using (FileStream file = new FileStream(fileName, FileMode.Open))
1616
{
17-
var hash = MD5.HashData(file);
17+
byte[] hash;
18+
using (var md5 = MD5.Create())
19+
{
20+
hash = md5.ComputeHash(file);
21+
}
1822

1923
file.Close();
2024

test/Renci.SshNet.IntegrationTests/Program.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFrameworks>net48;net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<IsPackable>false</IsPackable>
77
<IsTestProject>true</IsTestProject>
88
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010</NoWarn>
9+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
910
</PropertyGroup>
1011

1112
<ItemGroup>

test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>netstandard2.0</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045</NoWarn>

test/Renci.SshNet.TestTools.OpenSSH/SshdConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private static void ProcessGlobalOption(SshdConfig sshdConfig, string line)
329329
sshdConfig.KeyboardInteractiveAuthentication = ToBool(value);
330330
break;
331331
case "LogLevel":
332-
sshdConfig.LogLevel = Enum.Parse<LogLevel>(value, ignoreCase: true);
332+
sshdConfig.LogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), value, ignoreCase: true);
333333
break;
334334
case "Subsystem":
335335
sshdConfig.Subsystems.Add(Subsystem.FromConfig(value));

0 commit comments

Comments
 (0)