Skip to content

Allow the integration tests to run on .NET Framework #1286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions test/Renci.SshNet.IntegrationTests/App.config

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ public static class DateTimeExtensions
{
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);
}
}
}
4 changes: 4 additions & 0 deletions test/Renci.SshNet.IntegrationTests/HostConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public static HostConfig Read(ScpClient scpClient, string path)
while ((line = sr.ReadLine()) != null)
{
// skip comments
#if NET
if (line.StartsWith('#'))
#else
if (line.StartsWith("#"))
#endif
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Diagnostics;
#if !NET6_0_OR_GREATER
using System.Net;
#endif

using Renci.SshNet.Common;

Expand Down Expand Up @@ -46,8 +49,8 @@ public void Test_PortForwarding_Local_Stop_Hangs_On_Wait()
.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);
Expand Down Expand Up @@ -122,10 +125,10 @@ public void Test_PortForwarding_Local_Without_Connecting()
{
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ protected static string CalculateMD5(string fileName)
{
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();

Expand Down
11 changes: 0 additions & 11 deletions test/Renci.SshNet.IntegrationTests/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010</NoWarn>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion test/Renci.SshNet.TestTools.OpenSSH/SshdConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private static void ProcessGlobalOption(SshdConfig sshdConfig, string line)
sshdConfig.KeyboardInteractiveAuthentication = ToBool(value);
break;
case "LogLevel":
sshdConfig.LogLevel = Enum.Parse<LogLevel>(value, ignoreCase: true);
sshdConfig.LogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), value, ignoreCase: true);
break;
case "Subsystem":
sshdConfig.Subsystems.Add(Subsystem.FromConfig(value));
Expand Down