using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshNet.Common; using Renci.SshNet.Tests.Properties; using System; namespace Renci.SshNet.Tests.Classes { /// /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. /// public partial class SftpClientTest { [TestMethod] [TestCategory("Sftp")] [ExpectedException(typeof(SshConnectionException))] public void Test_Sftp_CreateDirectory_Without_Connecting() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.CreateDirectory("test"); } } [TestMethod] [TestCategory("Sftp")] [TestCategory("integration")] public void Test_Sftp_CreateDirectory_In_Current_Location() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("test"); sftp.Disconnect(); } } [TestMethod] [TestCategory("Sftp")] [TestCategory("integration")] [ExpectedException(typeof(SftpPermissionDeniedException))] public void Test_Sftp_CreateDirectory_In_Forbidden_Directory() { if (Resources.USERNAME == "root") { Assert.Fail("Must not run this test as root!"); } using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("/sbin/test"); sftp.Disconnect(); } } [TestMethod] [TestCategory("Sftp")] [TestCategory("integration")] [ExpectedException(typeof(SftpPathNotFoundException))] public void Test_Sftp_CreateDirectory_Invalid_Path() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("/abcdefg/abcefg"); sftp.Disconnect(); } } [TestMethod] [TestCategory("Sftp")] [TestCategory("integration")] [ExpectedException(typeof(SshException))] public void Test_Sftp_CreateDirectory_Already_Exists() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.Connect(); sftp.CreateDirectory("test"); sftp.CreateDirectory("test"); sftp.Disconnect(); } } [TestMethod] [TestCategory("Sftp")] [Description("Test passing null to CreateDirectory.")] [ExpectedException(typeof(ArgumentException))] public void Test_Sftp_CreateDirectory_Null() { using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) { sftp.CreateDirectory(null); } } } }