|
|
@@ -11,39 +11,25 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
{
|
|
|
[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<SftpPermissionDeniedException>(() => 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<SftpPathNotFoundException>(() => sftp.ListDirectory("/asdfgh"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -115,23 +101,13 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
[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<ArgumentNullException>(() => sftp.ListDirectory(null));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -168,13 +144,13 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
{
|
|
|
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 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
|
|
|
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 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
|
|
|
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 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
{
|
|
|
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 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
|
|
|
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 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
|
|
|
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 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
[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<ArgumentNullException>(() => 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<ArgumentNullException>(() => 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 @@ namespace Renci.SshNet.IntegrationTests.OldIntegrationTests
|
|
|
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<ArgumentException>(() => sftp.EndListDirectory(ar));
|
|
|
}
|
|
|
}
|
|
|
}
|