diff --git a/.editorconfig b/.editorconfig index aebbfc80f..61d024e11 100644 --- a/.editorconfig +++ b/.editorconfig @@ -610,6 +610,17 @@ MA0053.class_with_virtual_member_shoud_be_sealed = true # This rule is disabled by default, hence we need to explicitly enable it. dotnet_diagnostic.MA0112.severity = error +# MA0165: Make interpolated string +dotnet_diagnostic.MA0165.severity = none + +#### MSTest rules #### + +# MSTEST0015: Test method should not be ignored +dotnet_diagnostic.MSTEST0015.severity = suggestion + +# MSTEST0032: Assertion condition is always true +dotnet_diagnostic.MSTEST0032.severity = suggestion + #### .NET Compiler Platform code quality rules #### # CA1002: Do not expose generic lists diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c41221ec7..5c54e4dd2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,22 +8,26 @@ updates: - package-ecosystem: "docker" directory: "/test/Renci.SshNet.IntegrationTests/" schedule: - interval: "weekly" + interval: "monthly" - package-ecosystem: "nuget" directory: "/" schedule: - interval: "weekly" - ignore: - # AsyncInterface must stay at 1.0.0 because of https://github.com/sshnet/SSH.NET/pull/1288 + interval: "monthly" + ignore: # See justifications in Directory.Packages.props - dependency-name: "Microsoft.Bcl.AsyncInterfaces" - # These should stay on LTS .NET Releases + - dependency-name: "System.Formats.Asn1" update-types: ["version-update:semver-major"] - - dependency-name: "Microsoft.Extensions.Logging.*" + + - dependency-name: "Microsoft.Extensions.Logging.Abstractions" update-types: ["version-update:semver-major"] + groups: + dependencies: + patterns: + - "*" - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "weekly" + interval: "monthly" diff --git a/Directory.Packages.props b/Directory.Packages.props index e0fde5f39..f299ce239 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,27 +6,31 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + + - + + - + - - + + - - - + + + + + - + diff --git a/Renci.SshNet.sln b/Renci.SshNet.sln index 5bfc241d8..4a0a20538 100644 --- a/Renci.SshNet.sln +++ b/Renci.SshNet.sln @@ -83,6 +83,9 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Renci.SshNet.AotCompatibilityTestApp", "test\Renci.SshNet.AotCompatibilityTestApp\Renci.SshNet.AotCompatibilityTestApp.csproj", "{F2E3FC50-4EF4-488C-B3D2-C45E99898D8B}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{05229079-6738-42CE-8F73-F4E182929B03}" + ProjectSection(SolutionItems) = preProject + .github\dependabot.yml = .github\dependabot.yml + EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{95F25B1A-2B14-4745-9087-43C00CD90EE0}" ProjectSection(SolutionItems) = preProject diff --git a/src/Renci.SshNet/SshMessageFactory.cs b/src/Renci.SshNet/SshMessageFactory.cs index e262a0149..038d7c3ae 100644 --- a/src/Renci.SshNet/SshMessageFactory.cs +++ b/src/Renci.SshNet/SshMessageFactory.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; +using System.Linq; + #if NET9_0_OR_GREATER using System.Threading; #endif @@ -19,7 +22,7 @@ internal sealed class SshMessageFactory private readonly bool[] _activatedMessagesById; private readonly Lock _lock = new Lock(); - internal static readonly MessageMetadata[] AllMessages = new MessageMetadata[] + private static readonly MessageMetadata[] AllMessages = new MessageMetadata[] { new MessageMetadata(0, "SSH_MSG_KEXINIT", 20), new MessageMetadata(1, "SSH_MSG_NEWKEYS", 21), @@ -55,6 +58,7 @@ internal sealed class SshMessageFactory new MessageMetadata(31, "SSH_MSG_KEX_ECDH_REPLY", 31), new MessageMetadata(32, "SSH_MSG_KEX_HYBRID_REPLY", 31) }; + private static readonly Dictionary MessagesByName = CreateMessagesByNameMapping(); /// @@ -62,17 +66,14 @@ internal sealed class SshMessageFactory /// internal const byte HighestMessageNumber = 100; - /// - /// Defines the total number of supported messages. - /// - internal const int TotalMessageCount = 33; - /// /// Initializes a new instance of the class. /// public SshMessageFactory() { - _activatedMessagesById = new bool[TotalMessageCount]; + Debug.Assert(AllMessages.Max(m => m.Number) == HighestMessageNumber); + + _activatedMessagesById = new bool[AllMessages.Length]; _enabledMessagesByNumber = new MessageMetadata[HighestMessageNumber + 1]; } @@ -289,7 +290,9 @@ public MessageMetadata(byte id, string name, byte number) public override Message Create() { - return new T(); + var message = new T(); + Debug.Assert(message.MessageNumber == Number); + return message; } } } diff --git a/test/Renci.SshNet.IntegrationTests/AuthenticationTests.cs b/test/Renci.SshNet.IntegrationTests/AuthenticationTests.cs index 6e6c3e8c9..9f143eee0 100644 --- a/test/Renci.SshNet.IntegrationTests/AuthenticationTests.cs +++ b/test/Renci.SshNet.IntegrationTests/AuthenticationTests.cs @@ -352,6 +352,8 @@ public void KeyboardInteractive_PasswordExpired() // Password expired, retype new password authenticationPrompt.Response = Users.Regular.Password; break; + default: + break; } authenticationPromptCount++; diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs index f97345175..d13c92ddf 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ForwardedPortLocalTest.cs @@ -100,61 +100,12 @@ public void Test_PortForwarding_Local_Stop_Hangs_On_Wait() } [TestMethod] - [ExpectedException(typeof(SshConnectionException))] public void Test_PortForwarding_Local_Without_Connecting() { using (var client = new SshClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { using var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80); - client.AddForwardedPort(port1); - port1.Exception += delegate (object sender, ExceptionEventArgs e) - { - Assert.Fail(e.Exception.ToString()); - }; - port1.Start(); - - var test = Parallel.For(0, - 100, - counter => - { - var start = DateTime.Now; - -#if NET6_0_OR_GREATER - var httpClient = new HttpClient(); - using (var response = httpClient.GetAsync("http://localhost:8084").GetAwaiter().GetResult()) - { - 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()); -#endif // NET6_0_OR_GREATER - var end = DateTime.Now; - - Debug.WriteLine(string.Format("Request# {2}: Lenght: {0} Time: {1}", data.Length, end - start, counter)); - } - }); - } - } - - private static byte[] ReadStream(Stream stream) - { - var buffer = new byte[1024]; - using (var ms = new MemoryStream()) - { - while (true) - { - var read = stream.Read(buffer, 0, buffer.Length); - if (read > 0) - { - ms.Write(buffer, 0, read); - } - else - { - return ms.ToArray(); - } - } + Assert.ThrowsException(() => client.AddForwardedPort(port1)); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ScpClientTest.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ScpClientTest.cs index e9015a3c6..0716280d3 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ScpClientTest.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/ScpClientTest.cs @@ -240,7 +240,7 @@ where CalculateMD5(file) == CalculateMD5(string.Format("{0}.down", file)) scp.Disconnect(); - Assert.IsTrue(result.Count() == uploadFilenames.Length); + Assert.AreEqual(uploadFilenames.Length, result.Count()); } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ChangeDirectory.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ChangeDirectory.cs index 4076c6b01..2f19fd26b 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ChangeDirectory.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ChangeDirectory.cs @@ -9,97 +9,97 @@ public partial class SftpClientTest : IntegrationTestBase { [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_ChangeDirectory_Root_Dont_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.ChangeDirectory("/asdasd"); + Assert.ThrowsException(() => sftp.ChangeDirectory("/asdasd")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public async Task Test_Sftp_ChangeDirectory_Root_Dont_ExistsAsync() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false); - await sftp.ChangeDirectoryAsync("/asdasd", CancellationToken.None).ConfigureAwait(false); + + await Assert.ThrowsExceptionAsync( + () => sftp.ChangeDirectoryAsync("/asdasd", CancellationToken.None)); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_ChangeDirectory_Root_With_Slash_Dont_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.ChangeDirectory("/asdasd/"); + Assert.ThrowsException(() => sftp.ChangeDirectory("/asdasd/")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public async Task Test_Sftp_ChangeDirectory_Root_With_Slash_Dont_ExistsAsync() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false); - await sftp.ChangeDirectoryAsync("/asdasd/", CancellationToken.None).ConfigureAwait(false); + + await Assert.ThrowsExceptionAsync( + () => sftp.ChangeDirectoryAsync("/asdasd/", CancellationToken.None)); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_ChangeDirectory_Subfolder_Dont_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.ChangeDirectory("/asdasd/sssddds"); + Assert.ThrowsException(() => sftp.ChangeDirectory("/asdasd/sssddds")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public async Task Test_Sftp_ChangeDirectory_Subfolder_Dont_ExistsAsync() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false); - await sftp.ChangeDirectoryAsync("/asdasd/sssddds", CancellationToken.None).ConfigureAwait(false); + + await Assert.ThrowsExceptionAsync( + () => sftp.ChangeDirectoryAsync("/asdasd/sssddds", CancellationToken.None)); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.ChangeDirectory("/asdasd/sssddds/"); + Assert.ThrowsException(() => sftp.ChangeDirectory("/asdasd/sssddds/")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public async Task Test_Sftp_ChangeDirectory_Subfolder_With_Slash_Dont_ExistsAsync() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false); - await sftp.ChangeDirectoryAsync("/asdasd/sssddds/", CancellationToken.None).ConfigureAwait(false); + + await Assert.ThrowsExceptionAsync( + () => sftp.ChangeDirectoryAsync("/asdasd/sssddds/", CancellationToken.None)); } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.CreateDirectory.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.CreateDirectory.cs index 43b176697..7274a6e91 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.CreateDirectory.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.CreateDirectory.cs @@ -24,37 +24,30 @@ public void Test_Sftp_CreateDirectory_In_Current_Location() [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPermissionDeniedException))] public void Test_Sftp_CreateDirectory_In_Forbidden_Directory() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, AdminUser.UserName, AdminUser.Password)) { sftp.Connect(); - sftp.CreateDirectory("/sbin/test"); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.CreateDirectory("/sbin/test")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_CreateDirectory_Invalid_Path() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.CreateDirectory("/abcdefg/abcefg"); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.CreateDirectory("/abcdefg/abcefg")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SshException))] public void Test_Sftp_CreateDirectory_Already_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) @@ -63,9 +56,7 @@ public void Test_Sftp_CreateDirectory_Already_Exists() sftp.CreateDirectory("test"); - sftp.CreateDirectory("test"); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.CreateDirectory("test")); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.DeleteDirectory.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.DeleteDirectory.cs index d5112895b..0609a4572 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.DeleteDirectory.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.DeleteDirectory.cs @@ -9,31 +9,25 @@ public partial class SftpClientTest : IntegrationTestBase { [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_DeleteDirectory_Which_Doesnt_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.DeleteDirectory("abcdef"); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.DeleteDirectory("abcdef")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPermissionDeniedException))] public void Test_Sftp_DeleteDirectory_Which_No_Permissions() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, AdminUser.UserName, AdminUser.Password)) { sftp.Connect(); - sftp.DeleteDirectory("/usr"); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.DeleteDirectory("/usr")); } } @@ -55,16 +49,13 @@ public void Test_Sftp_DeleteDirectory() [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to DeleteDirectory.")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_DeleteDirectory_Null() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.DeleteDirectory(null); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.DeleteDirectory(null)); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Download.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Download.cs index 4becef18f..d1475c5f3 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Download.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Download.cs @@ -9,88 +9,69 @@ public partial class SftpClientTest : IntegrationTestBase { [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPermissionDeniedException))] public void Test_Sftp_Download_Forbidden() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, AdminUser.UserName, AdminUser.Password)) { sftp.Connect(); - string remoteFileName = "/root/.profile"; - - using (var ms = new MemoryStream()) - { - sftp.DownloadFile(remoteFileName, ms); - } - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.DownloadFile("/root/.profile", Stream.Null)); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_Download_File_Not_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - string remoteFileName = "/xxx/eee/yyy"; - using (var ms = new MemoryStream()) - { - sftp.DownloadFile(remoteFileName, ms); - } - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.DownloadFile("/xxx/eee/yyy", Stream.Null)); } } [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to BeginDownloadFile")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_BeginDownloadFile_StreamIsNull() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.BeginDownloadFile("aaaa", null, null, null); - sftp.Disconnect(); + + Assert.ThrowsException(() => sftp.BeginDownloadFile("aaaa", null, null, null)); } } [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to BeginDownloadFile")] - [ExpectedException(typeof(ArgumentException))] public void Test_Sftp_BeginDownloadFile_FileNameIsWhiteSpace() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.BeginDownloadFile(" ", new MemoryStream(), null, null); - sftp.Disconnect(); + + Assert.ThrowsException(() => sftp.BeginDownloadFile(" ", Stream.Null, null, null)); } } [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to BeginDownloadFile")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_BeginDownloadFile_FileNameIsNull() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.BeginDownloadFile(null, new MemoryStream(), null, null); - sftp.Disconnect(); + + Assert.ThrowsException(() => sftp.BeginDownloadFile(null, Stream.Null, null, null)); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(ArgumentException))] public void Test_Sftp_EndDownloadFile_Invalid_Async_Handle() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) @@ -101,7 +82,8 @@ public void Test_Sftp_EndDownloadFile_Invalid_Async_Handle() sftp.UploadFile(File.OpenRead(filename), "test123"); var async1 = sftp.BeginListDirectory("/", null, null); var async2 = sftp.BeginDownloadFile("test123", new MemoryStream(), null, null); - sftp.EndDownloadFile(async1); + + Assert.ThrowsException(() => sftp.EndDownloadFile(async1)); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ListDirectory.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ListDirectory.cs index a5660fa3c..846d02fc4 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ListDirectory.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ListDirectory.cs @@ -11,39 +11,25 @@ public partial class SftpClientTest : IntegrationTestBase { [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPermissionDeniedException))] public void Test_Sftp_ListDirectory_Permission_Denied() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - var files = sftp.ListDirectory("/root"); - foreach (var file in files) - { - Debug.WriteLine(file.FullName); - } - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.ListDirectory("/root")); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_ListDirectory_Not_Exists() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - var files = sftp.ListDirectory("/asdfgh"); - foreach (var file in files) - { - Debug.WriteLine(file.FullName); - } - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.ListDirectory("/asdfgh")); } } @@ -115,23 +101,13 @@ public void Test_Sftp_ListDirectory_Empty() [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to ListDirectory.")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_ListDirectory_Null() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - var files = sftp.ListDirectory(null); - - Assert.IsTrue(files.Count() > 0); - - foreach (var file in files) - { - Debug.WriteLine(file.FullName); - } - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.ListDirectory(null)); } } @@ -168,13 +144,13 @@ public void Test_Sftp_Change_Directory() { sftp.Connect(); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet"); + Assert.AreEqual("/home/sshnet", sftp.WorkingDirectory); sftp.CreateDirectory("test1"); sftp.ChangeDirectory("test1"); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1"); + Assert.AreEqual("/home/sshnet/test1", sftp.WorkingDirectory); sftp.CreateDirectory("test1_1"); sftp.CreateDirectory("test1_2"); @@ -186,19 +162,19 @@ public void Test_Sftp_Change_Directory() sftp.ChangeDirectory("test1_1"); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_1"); + Assert.AreEqual("/home/sshnet/test1/test1_1", sftp.WorkingDirectory); sftp.ChangeDirectory("../test1_2"); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_2"); + Assert.AreEqual("/home/sshnet/test1/test1_2", sftp.WorkingDirectory); sftp.ChangeDirectory(".."); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1"); + Assert.AreEqual("/home/sshnet/test1", sftp.WorkingDirectory); sftp.ChangeDirectory(".."); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet"); + Assert.AreEqual("/home/sshnet", sftp.WorkingDirectory); files = sftp.ListDirectory("test1/test1_1"); @@ -206,15 +182,15 @@ public void Test_Sftp_Change_Directory() sftp.ChangeDirectory("test1/test1_1"); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_1"); + Assert.AreEqual("/home/sshnet/test1/test1_1", sftp.WorkingDirectory); sftp.ChangeDirectory("/home/sshnet/test1/test1_1"); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_1"); + Assert.AreEqual("/home/sshnet/test1/test1_1", sftp.WorkingDirectory); sftp.ChangeDirectory("/home/sshnet/test1/test1_1/../test1_2"); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_2"); + Assert.AreEqual("/home/sshnet/test1/test1_2", sftp.WorkingDirectory); sftp.ChangeDirectory("../../"); @@ -237,13 +213,13 @@ public async Task Test_Sftp_Change_DirectoryAsync() { await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet"); + Assert.AreEqual("/home/sshnet", sftp.WorkingDirectory); await sftp.CreateDirectoryAsync("test1", CancellationToken.None).ConfigureAwait(false); await sftp.ChangeDirectoryAsync("test1", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1"); + Assert.AreEqual("/home/sshnet/test1", sftp.WorkingDirectory); await sftp.CreateDirectoryAsync("test1_1", CancellationToken.None).ConfigureAwait(false); await sftp.CreateDirectoryAsync("test1_2", CancellationToken.None).ConfigureAwait(false); @@ -255,19 +231,19 @@ public async Task Test_Sftp_Change_DirectoryAsync() await sftp.ChangeDirectoryAsync("test1_1", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_1"); + Assert.AreEqual("/home/sshnet/test1/test1_1", sftp.WorkingDirectory); await sftp.ChangeDirectoryAsync("../test1_2", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_2"); + Assert.AreEqual("/home/sshnet/test1/test1_2", sftp.WorkingDirectory); await sftp.ChangeDirectoryAsync("..", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1"); + Assert.AreEqual("/home/sshnet/test1", sftp.WorkingDirectory); await sftp.ChangeDirectoryAsync("..", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet"); + Assert.AreEqual("/home/sshnet", sftp.WorkingDirectory); files = sftp.ListDirectory("test1/test1_1"); @@ -275,15 +251,15 @@ public async Task Test_Sftp_Change_DirectoryAsync() await sftp.ChangeDirectoryAsync("test1/test1_1", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_1"); + Assert.AreEqual("/home/sshnet/test1/test1_1", sftp.WorkingDirectory); await sftp.ChangeDirectoryAsync("/home/sshnet/test1/test1_1", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_1"); + Assert.AreEqual("/home/sshnet/test1/test1_1", sftp.WorkingDirectory); await sftp.ChangeDirectoryAsync("/home/sshnet/test1/test1_1/../test1_2", CancellationToken.None).ConfigureAwait(false); - Assert.AreEqual(sftp.WorkingDirectory, "/home/sshnet/test1/test1_2"); + Assert.AreEqual("/home/sshnet/test1/test1_2", sftp.WorkingDirectory); await sftp.ChangeDirectoryAsync("../../", CancellationToken.None).ConfigureAwait(false); @@ -301,39 +277,32 @@ public async Task Test_Sftp_Change_DirectoryAsync() [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to ChangeDirectory.")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_ChangeDirectory_Null() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.ChangeDirectory(null); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.ChangeDirectory(null)); } } [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to ChangeDirectory.")] - [ExpectedException(typeof(ArgumentNullException))] public async Task Test_Sftp_ChangeDirectory_NullAsync() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { await sftp.ConnectAsync(CancellationToken.None).ConfigureAwait(false); - await sftp.ChangeDirectoryAsync(null, CancellationToken.None).ConfigureAwait(false); - - sftp.Disconnect(); + await Assert.ThrowsExceptionAsync(() => sftp.ChangeDirectoryAsync(null)); } } [TestMethod] [TestCategory("Sftp")] - [Description("Test calling EndListDirectory method more then once.")] - [ExpectedException(typeof(ArgumentException))] + [Description("Test calling EndListDirectory method more than once.")] public void Test_Sftp_Call_EndListDirectory_Twice() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) @@ -341,7 +310,9 @@ public void Test_Sftp_Call_EndListDirectory_Twice() sftp.Connect(); var ar = sftp.BeginListDirectory("/", null, null); var result = sftp.EndListDirectory(ar); - var result1 = sftp.EndListDirectory(ar); + + // TODO there is no reason that this should throw + Assert.ThrowsException(() => sftp.EndListDirectory(ar)); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFile.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFile.cs index e74a8e7ed..200e2d717 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFile.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFile.cs @@ -37,16 +37,13 @@ public void Test_Sftp_Rename_File() [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to RenameFile.")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_RenameFile_Null() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.RenameFile(null, null); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.RenameFile(null, null)); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFileAsync.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFileAsync.cs index ade91099c..321d44e1c 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFileAsync.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.RenameFileAsync.cs @@ -40,16 +40,13 @@ public async Task Test_Sftp_RenameFileAsync() [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to RenameFile.")] - [ExpectedException(typeof(ArgumentNullException))] public async Task Test_Sftp_RenameFileAsync_Null() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { await sftp.ConnectAsync(default); - await sftp.RenameFileAsync(null, null, default); - - sftp.Disconnect(); + await Assert.ThrowsExceptionAsync(() => sftp.RenameFileAsync(null, null, default)); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Upload.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Upload.cs index 8346189be..e5cd91400 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Upload.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.Upload.cs @@ -53,7 +53,6 @@ public void Test_Sftp_Upload_And_Download_1MB_File() [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPermissionDeniedException))] public void Test_Sftp_Upload_Forbidden() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) @@ -67,7 +66,7 @@ public void Test_Sftp_Upload_Forbidden() using (var file = File.OpenRead(uploadedFileName)) { - sftp.UploadFile(file, remoteFileName); + Assert.ThrowsException(() => sftp.UploadFile(file, remoteFileName)); } sftp.Disconnect(); @@ -325,48 +324,44 @@ public void Test_Sftp_Ensure_Async_Delegates_Called_For_BeginFileUpload_BeginFil [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to BeginUploadFile")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_BeginUploadFile_StreamIsNull() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - _ = sftp.BeginUploadFile(null, "aaaaa", null, null); - sftp.Disconnect(); + + Assert.ThrowsException(() => sftp.BeginUploadFile(null, "aaaaa", null, null)); } } [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to BeginUploadFile")] - [ExpectedException(typeof(ArgumentException))] public void Test_Sftp_BeginUploadFile_FileNameIsWhiteSpace() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - _ = sftp.BeginUploadFile(new MemoryStream(), " ", null, null); - sftp.Disconnect(); + + Assert.ThrowsException(() => sftp.BeginUploadFile(new MemoryStream(), " ", null, null)); } } [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to BeginUploadFile")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_BeginUploadFile_FileNameIsNull() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - _ = sftp.BeginUploadFile(new MemoryStream(), null, null, null); - sftp.Disconnect(); + + Assert.ThrowsException(() => sftp.BeginUploadFile(new MemoryStream(), null, null, null)); } } [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(ArgumentException))] public void Test_Sftp_EndUploadFile_Invalid_Async_Handle() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) @@ -377,7 +372,8 @@ public void Test_Sftp_EndUploadFile_Invalid_Async_Handle() CreateTestFile(filename, 100); using var fileStream = File.OpenRead(filename); var async2 = sftp.BeginUploadFile(fileStream, "test", null, null); - sftp.EndUploadFile(async1); + + Assert.ThrowsException(() => sftp.EndUploadFile(async1)); } } } diff --git a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpFileTest.cs b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpFileTest.cs index ec9fb8c76..34819a6e6 100644 --- a/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpFileTest.cs +++ b/test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpFileTest.cs @@ -25,14 +25,13 @@ public void Test_Get_Root_Directory() [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Get_Invalid_Directory() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - sftp.Get("/xyz"); + Assert.ThrowsException(() => sftp.Get("/xyz")); } } @@ -56,17 +55,13 @@ public void Test_Get_File() [TestMethod] [TestCategory("Sftp")] - [Description("Test passing null to Get.")] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Get_File_Null() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - var file = sftp.Get(null); - - sftp.Disconnect(); + Assert.ThrowsException(() => sftp.Get(null)); } } @@ -104,14 +99,13 @@ public async Task Test_Get_Root_DirectoryAsync() [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SftpPathNotFoundException))] public async Task Test_Get_Invalid_DirectoryAsync() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - await sftp.GetAsync("/xyz", default).ConfigureAwait(false); + await Assert.ThrowsExceptionAsync(() => sftp.GetAsync("/xyz", default)); } } @@ -135,17 +129,13 @@ public async Task Test_Get_FileAsync() [TestMethod] [TestCategory("Sftp")] - [Description("Test passing null to Get.")] - [ExpectedException(typeof(ArgumentNullException))] public async Task Test_Get_File_NullAsync() { using (var sftp = new SftpClient(SshServerHostName, SshServerPort, User.UserName, User.Password)) { sftp.Connect(); - var file = await sftp.GetAsync(null, default).ConfigureAwait(false); - - sftp.Disconnect(); + await Assert.ThrowsExceptionAsync(() => sftp.GetAsync(null, default)); } } diff --git a/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj b/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj index d9f89ac45..e3334796a 100644 --- a/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj +++ b/test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj @@ -4,7 +4,6 @@ net48;net8.0;net9.0 enable true - $(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010 true @@ -18,7 +17,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - diff --git a/test/Renci.SshNet.IntegrationTests/SftpClientTests.cs b/test/Renci.SshNet.IntegrationTests/SftpClientTests.cs index 951fdf666..52c4223f4 100644 --- a/test/Renci.SshNet.IntegrationTests/SftpClientTests.cs +++ b/test/Renci.SshNet.IntegrationTests/SftpClientTests.cs @@ -90,10 +90,9 @@ public async Task Create_directory_with_contents_and_list_it_async() } [TestMethod] - [ExpectedException(typeof(SftpPermissionDeniedException), "Permission denied")] public void Test_Sftp_ListDirectory_Permission_Denied() { - _sftpClient.ListDirectory("/root"); + Assert.ThrowsException(() => _sftpClient.ListDirectory("/root")); } [TestMethod] diff --git a/test/Renci.SshNet.IntegrationTests/SftpTests.cs b/test/Renci.SshNet.IntegrationTests/SftpTests.cs index f03ee6a2c..8a3c229f1 100644 --- a/test/Renci.SshNet.IntegrationTests/SftpTests.cs +++ b/test/Renci.SshNet.IntegrationTests/SftpTests.cs @@ -1731,7 +1731,7 @@ public void Sftp_ReadAllText_NoEncoding_ExistingFile() } var actualText = client.ReadAllText(remoteFile); - Assert.AreEqual(actualText, expectedText); + Assert.AreEqual(expectedText, actualText); using (var fs = client.OpenRead(remoteFile)) { diff --git a/test/Renci.SshNet.IntegrationTests/SshTests.cs b/test/Renci.SshNet.IntegrationTests/SshTests.cs index 762a6ba58..ba84365bf 100644 --- a/test/Renci.SshNet.IntegrationTests/SshTests.cs +++ b/test/Renci.SshNet.IntegrationTests/SshTests.cs @@ -1,5 +1,8 @@ using System.ComponentModel; using System.Net; +#if NETFRAMEWORK +using System.Net.Http; +#endif using System.Net.Sockets; using Renci.SshNet.Common; @@ -537,29 +540,16 @@ public void Ssh_LocalPortForwardingCloseChannels() try { - var httpRequest = (HttpWebRequest)WebRequest.Create("http://" + localEndPoint); - httpRequest.Host = hostName; - httpRequest.Method = "GET"; - httpRequest.AllowAutoRedirect = false; - - try - { - using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse()) - { - Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode); - } - } - catch (WebException ex) + using HttpClientHandler handler = new() { - Assert.AreEqual(WebExceptionStatus.ProtocolError, ex.Status); - Assert.IsNotNull(ex.Response); + AllowAutoRedirect = false + }; - using (var httpResponse = ex.Response as HttpWebResponse) - { - Assert.IsNotNull(httpResponse); - Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode); - } - } + using HttpClient httpClient = new(handler); + + using HttpResponseMessage httpResponse = httpClient.GetAsync("http://" + localEndPoint).Result; + + Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode); } finally { @@ -606,30 +596,16 @@ public void Ssh_LocalPortForwarding() try { - var httpRequest = (HttpWebRequest)WebRequest.Create("http://" + localEndPoint); - httpRequest.Host = hostName; - httpRequest.Method = "GET"; - httpRequest.Accept = "text/html"; - httpRequest.AllowAutoRedirect = false; - - try - { - using (var httpResponse = (HttpWebResponse)httpRequest.GetResponse()) - { - Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode); - } - } - catch (WebException ex) + using HttpClientHandler handler = new() { - Assert.AreEqual(WebExceptionStatus.ProtocolError, ex.Status); - Assert.IsNotNull(ex.Response); + AllowAutoRedirect = false + }; - using (var httpResponse = ex.Response as HttpWebResponse) - { - Assert.IsNotNull(httpResponse); - Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode); - } - } + using HttpClient httpClient = new(handler); + + using HttpResponseMessage httpResponse = httpClient.GetAsync("http://" + localEndPoint).Result; + + Assert.AreEqual(HttpStatusCode.MovedPermanently, httpResponse.StatusCode); } finally { diff --git a/test/Renci.SshNet.IntegrationTests/TestBase.cs b/test/Renci.SshNet.IntegrationTests/TestBase.cs index 9c9445f65..7f42fc868 100644 --- a/test/Renci.SshNet.IntegrationTests/TestBase.cs +++ b/test/Renci.SshNet.IntegrationTests/TestBase.cs @@ -30,7 +30,7 @@ protected static void FillStream(Stream stream, int size) protected static string CreateHash(Stream stream) { - MD5 md5 = new MD5CryptoServiceProvider(); + using MD5 md5 = MD5.Create(); var hash = md5.ComputeHash(stream); return Encoding.ASCII.GetString(hash); } diff --git a/test/Renci.SshNet.IntegrationTests/TestInitializer.cs b/test/Renci.SshNet.IntegrationTests/TestInitializer.cs index 0c058781e..491dcdc79 100644 --- a/test/Renci.SshNet.IntegrationTests/TestInitializer.cs +++ b/test/Renci.SshNet.IntegrationTests/TestInitializer.cs @@ -1,7 +1,7 @@ namespace Renci.SshNet.IntegrationTests { [TestClass] - public class TestInitializer + public static class TestInitializer { [AssemblyInitialize] [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "MSTests requires context parameter")] 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 a7b18cf8b..51d1672b4 100644 --- a/test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj +++ b/test/Renci.SshNet.TestTools.OpenSSH/Renci.SshNet.TestTools.OpenSSH.csproj @@ -4,13 +4,6 @@ netstandard2.0 enable enable - $(NoWarn);SYSLIB0021;SYSLIB1045 - - - - - - diff --git a/test/Renci.SshNet.Tests/Classes/Common/ChannelDataEventArgsTest.cs b/test/Renci.SshNet.Tests/Classes/Common/ChannelDataEventArgsTest.cs deleted file mode 100644 index cc7e54889..000000000 --- a/test/Renci.SshNet.Tests/Classes/Common/ChannelDataEventArgsTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Provides data for event and events. - /// - [TestClass] - public class ChannelDataEventArgsTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Common/ChannelEventArgsTest.cs b/test/Renci.SshNet.Tests/Classes/Common/ChannelEventArgsTest.cs deleted file mode 100644 index b741c897e..000000000 --- a/test/Renci.SshNet.Tests/Classes/Common/ChannelEventArgsTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Base class forTest : TestBaseall channel related events. - /// - [TestClass] - public class ChannelEventArgsTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs b/test/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs deleted file mode 100644 index 2d42c5705..000000000 --- a/test/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Provides data for event. - /// - [TestClass] - public class ChannelOpenFailedEventArgsTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Common/ChannelRequestEventArgsTest.cs b/test/Renci.SshNet.Tests/Classes/Common/ChannelRequestEventArgsTest.cs deleted file mode 100644 index 6b5eeca91..000000000 --- a/test/Renci.SshNet.Tests/Classes/Common/ChannelRequestEventArgsTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Provides data for event. - /// - [TestClass] - public class ChannelRequestEventArgsTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Connection/SshIdentificationTest.cs b/test/Renci.SshNet.Tests/Classes/Connection/SshIdentificationTest.cs index c5a9fffec..80f5646ca 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/SshIdentificationTest.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/SshIdentificationTest.cs @@ -65,9 +65,9 @@ public void Ctor_ProtocolVersionAndSoftwareVersionAndComments() const string comments = "Beware, dangerous!"; var sshIdentification = new SshIdentification(protocolVersion, softwareVersion, comments); - Assert.AreSame(protocolVersion, sshIdentification.ProtocolVersion); - Assert.AreSame(softwareVersion, sshIdentification.SoftwareVersion); - Assert.AreSame(comments, sshIdentification.Comments); + Assert.AreEqual(protocolVersion, sshIdentification.ProtocolVersion); + Assert.AreEqual(softwareVersion, sshIdentification.SoftwareVersion); + Assert.AreEqual(comments, sshIdentification.Comments); } [TestMethod] @@ -78,9 +78,9 @@ public void Ctor_ProtocolVersionAndSoftwareVersionAndComments_CommentsIsNull() const string comments = null; var sshIdentification = new SshIdentification(protocolVersion, softwareVersion, comments); - Assert.AreSame(protocolVersion, sshIdentification.ProtocolVersion); - Assert.AreSame(softwareVersion, sshIdentification.SoftwareVersion); - Assert.IsNull(comments, sshIdentification.Comments); + Assert.AreEqual(protocolVersion, sshIdentification.ProtocolVersion); + Assert.AreEqual(softwareVersion, sshIdentification.SoftwareVersion); + Assert.IsNull(sshIdentification.Comments); } [TestMethod] diff --git a/test/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs b/test/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs index cddd087d1..751affe8a 100644 --- a/test/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs +++ b/test/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs @@ -13,17 +13,15 @@ namespace Renci.SshNet.Tests.Classes public partial class KeyboardInteractiveAuthenticationMethodTest : TestBase { [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Keyboard_Test_Pass_Null() { - new KeyboardInteractiveAuthenticationMethod(null); + Assert.ThrowsException(() => new KeyboardInteractiveAuthenticationMethod(null)); } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void Keyboard_Test_Pass_Whitespace() { - new KeyboardInteractiveAuthenticationMethod(string.Empty); + Assert.ThrowsException(() => new KeyboardInteractiveAuthenticationMethod(string.Empty)); } } } diff --git a/test/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs b/test/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs index a03feef3a..5b20fa3f0 100644 --- a/test/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs +++ b/test/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs @@ -175,11 +175,5 @@ public void FullCtor() Assert.AreEqual(_rows, ptyReq.Rows); Assert.AreSame(_terminalModeValues, ptyReq.TerminalModeValues); } - - [TestMethod] - public void NameShouldReturnPtyReq() - { - Assert.AreEqual("pty-req", PseudoTerminalRequestInfo.Name); - } } } diff --git a/test/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs b/test/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs index e60d56b09..786f78850 100644 --- a/test/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs +++ b/test/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs @@ -24,7 +24,7 @@ public void Test_KeyExchangeInitMessage_Load() m.Load(input); Assert.IsFalse(m.FirstKexPacketFollows); - Assert.IsTrue(m.Reserved == 0); + Assert.AreEqual(0u, m.Reserved); Assert.IsTrue(m.CompressionAlgorithmsClientToServer.SequenceEqual(new[] { "none", "zlib@openssh.com" })); Assert.IsTrue(m.CompressionAlgorithmsServerToClient.SequenceEqual(new[] { "none", "zlib@openssh.com" })); Assert.IsTrue(m.EncryptionAlgorithmsClientToServer.SequenceEqual(new[] { "aes128-ctr", "aes192-ctr", "aes256-ctr", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "blowfish-cbc", "cast128-cbc", "aes192-cbc", "aes256-cbc", "arcfour", "rijndael-cbc@lysator.liu.se" })); diff --git a/test/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs b/test/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs index 8f2cd7a2c..705c9442d 100644 --- a/test/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs +++ b/test/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs @@ -14,17 +14,15 @@ namespace Renci.SshNet.Tests.Classes public class NoneAuthenticationMethodTest : TestBase { [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void None_Test_Pass_Null() { - new NoneAuthenticationMethod(null); + Assert.ThrowsException(() => new NoneAuthenticationMethod(null)); } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void None_Test_Pass_Whitespace() { - new NoneAuthenticationMethod(string.Empty); + Assert.ThrowsException(() => new NoneAuthenticationMethod(string.Empty)); } [TestMethod] diff --git a/test/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs b/test/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs index e5a3b250c..76d6aeb5a 100644 --- a/test/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs +++ b/test/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs @@ -13,17 +13,15 @@ namespace Renci.SshNet.Tests.Classes public partial class PasswordAuthenticationMethodTest : TestBase { [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Password_Test_Pass_Null_Username() { - new PasswordAuthenticationMethod(null, "valid"); + Assert.ThrowsException(() => new PasswordAuthenticationMethod(null, "valid")); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Password_Test_Pass_Null_Password() { - new PasswordAuthenticationMethod("valid", (string)null); + Assert.ThrowsException(() => new PasswordAuthenticationMethod("valid", (string)null)); } [TestMethod] @@ -33,10 +31,9 @@ public void Password_Test_Pass_Valid_Username_And_Password() } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void Password_Test_Pass_Whitespace() { - new PasswordAuthenticationMethod(string.Empty, "valid"); + Assert.ThrowsException(() => new PasswordAuthenticationMethod(string.Empty, "valid")); } [TestMethod] diff --git a/test/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs b/test/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs index 3c818fd55..9cd5cf039 100644 --- a/test/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs +++ b/test/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs @@ -31,38 +31,36 @@ public void Test_ConnectionInfo_Host_Is_Null() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Test_ConnectionInfo_Username_Is_Null() { - _ = new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD); + Assert.ThrowsException(() => new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD)); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Test_ConnectionInfo_Password_Is_Null() { - _ = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null); + Assert.ThrowsException( + () => new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null)); } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void Test_ConnectionInfo_Username_Is_Whitespace() { - _ = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD); + Assert.ThrowsException(() => new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void Test_ConnectionInfo_SmallPortNumber() { - _ = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD); + Assert.ThrowsException( + () => new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD)); } [TestMethod] - [ExpectedException(typeof(ArgumentOutOfRangeException))] public void Test_ConnectionInfo_BigPortNumber() { - _ = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD); + Assert.ThrowsException( + () => new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD)); } } } diff --git a/test/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs b/test/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs index fb9599aed..aa981108f 100644 --- a/test/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs +++ b/test/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs @@ -13,24 +13,21 @@ namespace Renci.SshNet.Tests.Classes public class PrivateKeyAuthenticationMethodTest : TestBase { [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void PrivateKey_Test_Pass_Null() { - new PrivateKeyAuthenticationMethod(null, null); + Assert.ThrowsException(() => new PrivateKeyAuthenticationMethod(null, null)); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void PrivateKey_Test_Pass_PrivateKey_Null() { - new PrivateKeyAuthenticationMethod("username", null); + Assert.ThrowsException(() => new PrivateKeyAuthenticationMethod("username", null)); } [TestMethod] - [ExpectedException(typeof(ArgumentException))] public void PrivateKey_Test_Pass_Whitespace() { - new PrivateKeyAuthenticationMethod(string.Empty, null); + Assert.ThrowsException(() => new PrivateKeyAuthenticationMethod(string.Empty, null)); } } } diff --git a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs index 0b7fad0e5..6cb082b4b 100644 --- a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs +++ b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs @@ -21,7 +21,6 @@ namespace Renci.SshNet.Tests.Classes { - [TestClass] public abstract class SessionTest_ConnectedBase { internal Mock ServiceFactoryMock { get; private set; } diff --git a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs index f2c2f3476..4da2ef1ee 100644 --- a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs +++ b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs @@ -21,7 +21,6 @@ namespace Renci.SshNet.Tests.Classes { - [TestClass] public abstract class SessionTest_ConnectingBase { internal Mock ServiceFactoryMock { get; private set; } diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs deleted file mode 100644 index baaaebf30..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpInitRequestTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs deleted file mode 100644 index 3f5ca974c..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpNameResponseTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs deleted file mode 100644 index c9f2bcffb..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpStatusResponseTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs b/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs deleted file mode 100644 index 90be16468..000000000 --- a/test/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpVersionResponseTest : TestBase - { - } -} diff --git a/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteDirectory.cs b/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteDirectory.cs index c7d02323a..51a3818e2 100644 --- a/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteDirectory.cs +++ b/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteDirectory.cs @@ -12,12 +12,11 @@ public partial class SftpClientTest { [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SshConnectionException))] public void Test_Sftp_DeleteDirectory_Without_Connecting() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { - sftp.DeleteDirectory("test"); + Assert.ThrowsException(() => sftp.DeleteDirectory("test")); } } } diff --git a/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs b/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs index a5ba291bb..20d23267a 100644 --- a/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs +++ b/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs @@ -12,12 +12,11 @@ namespace Renci.SshNet.Tests.Classes public partial class SftpClientTest { [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public void Test_Sftp_DeleteFile_Null() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { - sftp.DeleteFile(null); + Assert.ThrowsException(() => sftp.DeleteFile(null)); } } } diff --git a/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs b/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs index 1b9b4ab27..56607e13c 100644 --- a/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs +++ b/test/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFileAsync.cs @@ -13,12 +13,11 @@ namespace Renci.SshNet.Tests.Classes public partial class SftpClientTest { [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] public async Task Test_Sftp_DeleteFileAsync_Null() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { - await sftp.DeleteFileAsync(null, default); + await Assert.ThrowsExceptionAsync(() => sftp.DeleteFileAsync(null, default)); } } } diff --git a/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectory.cs b/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectory.cs index c49fa0241..20516a5dd 100644 --- a/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectory.cs +++ b/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectory.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; - -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; using Renci.SshNet.Tests.Properties; @@ -14,16 +12,11 @@ public partial class SftpClientTest { [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SshConnectionException))] public void Test_Sftp_ListDirectory_Without_Connecting() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { - var files = sftp.ListDirectory("."); - foreach (var file in files) - { - Debug.WriteLine(file.FullName); - } + Assert.ThrowsException(() => sftp.ListDirectory(".")); } } } diff --git a/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectoryAsync.cs b/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectoryAsync.cs index 858eadc4b..c51fc352c 100644 --- a/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectoryAsync.cs +++ b/test/Renci.SshNet.Tests/Classes/SftpClientTest.ListDirectoryAsync.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -16,15 +15,16 @@ public partial class SftpClientTest { [TestMethod] [TestCategory("Sftp")] - [ExpectedException(typeof(SshConnectionException))] public async Task Test_Sftp_ListDirectoryAsync_Without_ConnectingAsync() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { - await foreach (var file in sftp.ListDirectoryAsync(".", CancellationToken.None)) + await Assert.ThrowsExceptionAsync(async () => { - Debug.WriteLine(file.FullName); - } + await foreach (var x in sftp.ListDirectoryAsync(".", CancellationToken.None)) + { + } + }); } } } diff --git a/test/Renci.SshNet.Tests/Classes/SshCommandTest.cs b/test/Renci.SshNet.Tests/Classes/SshCommandTest.cs index a2b6c356e..d008bb789 100644 --- a/test/Renci.SshNet.Tests/Classes/SshCommandTest.cs +++ b/test/Renci.SshNet.Tests/Classes/SshCommandTest.cs @@ -1,6 +1,4 @@ -using System; - -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; using Renci.SshNet.Tests.Common; @@ -15,25 +13,12 @@ namespace Renci.SshNet.Tests.Classes public partial class SshCommandTest : TestBase { [TestMethod] - [ExpectedException(typeof(SshConnectionException))] public void Test_Execute_SingleCommand_Without_Connecting() { using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { - var result = ExecuteTestCommand(client); - - Assert.IsTrue(result); + Assert.ThrowsException(() => client.CreateCommand("echo Hello")); } } - - private static bool ExecuteTestCommand(SshClient s) - { - var testValue = Guid.NewGuid().ToString(); - var command = string.Format("echo {0}", testValue); - var cmd = s.CreateCommand(command); - var result = cmd.Execute(); - result = result.Substring(0, result.Length - 1); // Remove \n character returned by command - return result.Equals(testValue); - } } } diff --git a/test/Renci.SshNet.Tests/Classes/SshMessageFactoryTest.cs b/test/Renci.SshNet.Tests/Classes/SshMessageFactoryTest.cs index ceca95818..74eb6f84c 100644 --- a/test/Renci.SshNet.Tests/Classes/SshMessageFactoryTest.cs +++ b/test/Renci.SshNet.Tests/Classes/SshMessageFactoryTest.cs @@ -1,6 +1,5 @@ using System; using System.Globalization; -using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -393,31 +392,11 @@ public void EnableActivatedMessagesShouldThrowSshExceptionWhenAnothersMessageWit [TestMethod] public void EnableActivatedMessagesShouldLeaveMessagesEnabledThatWereEnabledAfterInvokingDisableNonKeyExchangeMessages() { - const byte messageNumber = 60; - _sshMessageFactory.DisableNonKeyExchangeMessages(strict: false); _sshMessageFactory.EnableAndActivateMessage("SSH_MSG_USERAUTH_PASSWD_CHANGEREQ"); _sshMessageFactory.EnableActivatedMessages(); - var actual = _sshMessageFactory.Create(messageNumber); - Assert.IsNotNull(actual); - Assert.AreEqual(typeof(PasswordChangeRequiredMessage), actual.GetType()); - } - - [TestMethod] - public void HighestMessageNumberShouldCorrespondWithHighestSupportedMessageNumber() - { - var highestSupportMessageNumber = SshMessageFactory.AllMessages.Max(m => m.Number); - - Assert.AreEqual(highestSupportMessageNumber, SshMessageFactory.HighestMessageNumber); - } - - [TestMethod] - public void TotalMessageCountShouldBeTotalNumberOfSupportedMessages() - { - var totalNumberOfSupportedMessages = SshMessageFactory.AllMessages.Length; - - Assert.AreEqual(totalNumberOfSupportedMessages, SshMessageFactory.TotalMessageCount); + Assert.IsInstanceOfType(_sshMessageFactory.Create(60)); } } } diff --git a/test/Renci.SshNet.Tests/Common/TestBase.cs b/test/Renci.SshNet.Tests/Common/TestBase.cs index 66fe5c8e3..1acf2f16e 100644 --- a/test/Renci.SshNet.Tests/Common/TestBase.cs +++ b/test/Renci.SshNet.Tests/Common/TestBase.cs @@ -6,7 +6,6 @@ namespace Renci.SshNet.Tests.Common { - [TestClass] public abstract class TestBase { private static readonly Assembly ExecutingAssembly = Assembly.GetExecutingAssembly();