Skip to content
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.9" />
<PackageVersion Include="MSTest" Version="3.9.3" />
<PackageVersion Include="MSTest" Version="4.0.2" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
Expand Down
6 changes: 6 additions & 0 deletions test/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ dotnet_diagnostic.SA1623.severity = none
# For unit test projects, we do not care about documentation.
dotnet_diagnostic.SA1629.severity = none

# Workaround https://github.com/SonarSource/sonar-dotnet/issues/9767
dotnet_diagnostic.S1450.severity = none
dotnet_diagnostic.S1764.severity = none
dotnet_diagnostic.S3260.severity = none
dotnet_diagnostic.S5445.severity = none

#### .NET Compiler Platform analysers rules ####

# CA1001: Types that own disposable fields should be disposable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: DoNotParallelize]
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public void KeyboardInteractive_NoResponseSet_ThrowsSshAuthenticationException()
catch (SshAuthenticationException ex)
{
Assert.IsNull(ex.InnerException);
Assert.IsTrue(ex.Message.StartsWith("AuthenticationPrompt.Response is null for prompt \"Password: \""), $"Message was \"{ex.Message}\"");
Assert.StartsWith("AuthenticationPrompt.Response is null for prompt \"Password: \"", ex.Message);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Renci.SshNet.IntegrationTests/ConnectivityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public void Common_HostKeyAlgorithms_NoMatch()
var ex = Assert.Throws<SshConnectionException>(client.Connect);

Assert.AreEqual(DisconnectReason.KeyExchangeFailed, ex.DisconnectReason);
Assert.IsTrue(ex.Message.StartsWith("No matching host key algorithm"), ex.Message);
Assert.StartsWith("No matching host key algorithm", ex.Message);
}
}

Expand Down
40 changes: 40 additions & 0 deletions test/Renci.SshNet.IntegrationTests/Logging/TestConsoleLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#nullable enable
using Microsoft.Extensions.Logging;

namespace Renci.SshNet.IntegrationTests.Logging
{
internal class TestConsoleLogger(string categoryName) : ILogger
{
public IDisposable? BeginScope<TState>(TState state)
where TState : notnull
{
return null;
}

public bool IsEnabled(LogLevel logLevel)
{
return true;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
StringBuilder sb = new StringBuilder();
sb.Append(logLevel);
sb.Append(": ");
sb.Append(categoryName);
sb.Append(": ");

string message = formatter(state, exception);
sb.Append(message);

if (exception != null)
{
sb.Append(": ");
sb.Append(exception);
}

string line = sb.ToString();
Console.WriteLine(line);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#nullable enable

using Microsoft.Extensions.Logging;

namespace Renci.SshNet.IntegrationTests.Logging
{
internal class TestConsoleLoggerProvider : ILoggerProvider
{
public ILogger CreateLogger(string categoryName)
{
return new TestConsoleLogger(categoryName);
}

public void Dispose()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#nullable enable

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

namespace Renci.SshNet.IntegrationTests.Logging
{
internal static class TestConsoleLoggerProviderExtensions
{
internal static void AddTestConsoleLogger(this ILoggingBuilder builder)
{
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, TestConsoleLoggerProvider>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Test_Sftp_ListDirectory_Current()

var files = sftp.ListDirectory(".");

Assert.IsTrue(files.Count() > 0);
Assert.IsGreaterThan(0, files.Count());

foreach (var file in files)
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public async Task Test_Sftp_ListDirectoryAsync_Current()
Debug.WriteLine(file.FullName);
}

Assert.IsTrue(count > 0);
Assert.IsGreaterThan(0, count);

sftp.Disconnect();
}
Expand All @@ -87,7 +87,7 @@ public void Test_Sftp_ListDirectory_Empty()

var files = sftp.ListDirectory(string.Empty);

Assert.IsTrue(files.Count() > 0);
Assert.IsGreaterThan(0, files.Count());

foreach (var file in files)
{
Expand Down Expand Up @@ -128,7 +128,7 @@ public void Test_Sftp_ListDirectory_HugeDirectory()
var files = sftp.ListDirectory(".");

// Ensure that directory has at least 10000 items
Assert.IsTrue(files.Count() > 10000);
Assert.IsGreaterThan(10000, files.Count());

sftp.Disconnect();
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public void Test_Sftp_Change_Directory()

var files = sftp.ListDirectory(".");

Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}", sftp.WorkingDirectory)));
Assert.StartsWith(string.Format("{0}", sftp.WorkingDirectory), files.First().FullName);

sftp.ChangeDirectory("test1_1");

Expand All @@ -178,7 +178,7 @@ public void Test_Sftp_Change_Directory()

files = sftp.ListDirectory("test1/test1_1");

Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory)));
Assert.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory), files.First().FullName);

sftp.ChangeDirectory("test1/test1_1");

Expand Down Expand Up @@ -227,7 +227,7 @@ public async Task Test_Sftp_Change_DirectoryAsync()

var files = sftp.ListDirectory(".");

Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}", sftp.WorkingDirectory)));
Assert.StartsWith(string.Format("{0}", sftp.WorkingDirectory), files.First().FullName);

await sftp.ChangeDirectoryAsync("test1_1", CancellationToken.None).ConfigureAwait(false);

Expand All @@ -247,7 +247,7 @@ public async Task Test_Sftp_Change_DirectoryAsync()

files = sftp.ListDirectory("test1/test1_1");

Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory)));
Assert.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory), files.First().FullName);

await sftp.ChangeDirectoryAsync("test1/test1_1", CancellationToken.None).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Test_Sftp_SynchronizeDirectories()
string searchPattern = Path.GetFileName(uploadedFileName);
var upLoadedFiles = sftp.SynchronizeDirectories(sourceDir, destDir, searchPattern);

Assert.IsTrue(upLoadedFiles.Count() > 0);
Assert.IsGreaterThan(0, upLoadedFiles.Count());

foreach (var file in upLoadedFiles)
{
Expand Down Expand Up @@ -63,7 +63,7 @@ public void Test_Sftp_BeginSynchronizeDirectories()

var upLoadedFiles = sftp.EndSynchronizeDirectories(asyncResult);

Assert.IsTrue(upLoadedFiles.Count() > 0);
Assert.IsGreaterThan(0, upLoadedFiles.Count());

foreach (var file in upLoadedFiles)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void Test_Execute_SingleCommand()
}

[TestMethod]
[Timeout(5000)]
public void Test_CancelAsync_Unfinished_Command()
{
using var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password);
Expand All @@ -76,7 +75,6 @@ public void Test_CancelAsync_Unfinished_Command()
}

[TestMethod]
[Timeout(5000)]
public async Task Test_CancelAsync_Kill_Unfinished_Command()
{
using var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password);
Expand Down Expand Up @@ -122,7 +120,6 @@ public void Test_CancelAsync_Finished_Command()
}

[TestMethod]
[Timeout(5000)]
public async Task Test_ExecuteAsync_CancellationToken()
{
using var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password);
Expand Down Expand Up @@ -195,7 +192,6 @@ public async Task Test_ExecuteAsync_Timeout()
}

[TestMethod]
[Timeout(15000)]
public async Task Test_ExecuteAsync_Disconnect()
{
using (var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password))
Expand Down Expand Up @@ -226,7 +222,7 @@ public void Test_Execute_InvalidCommand()
{
Assert.Fail("Operation should fail");
}
Assert.IsTrue(cmd.ExitStatus > 0);
Assert.IsGreaterThan(0, cmd.ExitStatus.Value);

client.Disconnect();
}
Expand All @@ -244,7 +240,7 @@ public void Test_Execute_InvalidCommand_Then_Execute_ValidCommand()
{
Assert.Fail("Operation should fail");
}
Assert.IsTrue(cmd.ExitStatus > 0);
Assert.IsGreaterThan(0, cmd.ExitStatus.Value);

var result = ExecuteTestCommand(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

[assembly: ExcludeFromCodeCoverage]
#endif // NET

[assembly: DoNotParallelize]
Loading