public void TestCanUploadUsingTemporaryIndicatorDecorator()
        {
            // arrange

            var sftpClient = SftpTestsHelperRoutines.GenerateBasicSftpClient();
            BasicSftpFileUploaderDecorator uploaderDecoratorWithTemporaryFilesUploadDecoration =
                new BasicSftpFileUploaderDecorator(
                    new UploadPrefixIndicatorDecorator("foobar", new NullObjectSftpuploadDecorator()));

            StandardSftpFileUploader standardSftpFileUploader = new StandardSftpFileUploader(uploaderDecoratorWithTemporaryFilesUploadDecoration, testLogger);

            // act
            sftpClient.Connect();
            using (sftpClient)
            {
                string newTempFilePath = Path.GetTempFileName();
                standardSftpFileUploader.PerformFileUpload(newTempFilePath, $@"{Path.GetFileName(newTempFilePath)}", sftpClient, testLogger);

                // assert
                bool fileWasUploadedAndRenamed = sftpClient.Exists(Path.GetFileName(newTempFilePath));
                Assert.IsTrue(fileWasUploadedAndRenamed);

                // clean up
                sftpClient.DeleteFile(Path.GetFileName(newTempFilePath));
            }
        }
Exemple #2
0
        public void TestCanUploadUsingChecksumDecorator()
        {
            // arrange
            var sftpClient = SftpTestsHelperRoutines.GenerateBasicSftpClient();
            BasicSftpFileUploaderDecorator uploaderDecoratorWithChecksumDecoration =
                new BasicSftpFileUploaderDecorator(
                    new ChecksumFileDecorator(new NullObjectSftpuploadDecorator()));

            StandardSftpFileUploader standardSftpFileUploader = new StandardSftpFileUploader(uploaderDecoratorWithChecksumDecoration, testLogger);

            // act
            sftpClient.Connect();
            using (sftpClient)
            {
                string newTempFilePath = Path.GetTempFileName();
                standardSftpFileUploader.PerformFileUpload(newTempFilePath, $@"{Path.GetFileName(newTempFilePath)}", sftpClient, testLogger);

                // assert
                bool fileWasUploadedAndRenamed = sftpClient.Exists(Path.GetFileName(newTempFilePath));
                Assert.IsTrue(fileWasUploadedAndRenamed);

                // clean up
                string fileName          = Path.GetFileName(newTempFilePath);
                string filenameExtension = Path.GetExtension(fileName);
                sftpClient.DeleteFile(fileName);
                sftpClient.DeleteFile(fileName + ".sha256");
            }
        }
Exemple #3
0
        public void TestCanExecuteProgramAndUploadDictionary()
        {
            // arrange
            var sftpClient = SftpTestsHelperRoutines.GenerateBasicSftpClient();

            sftpClient.Connect();
            using (sftpClient)
            {
                string destinationPath = $@"/temp/{Guid.NewGuid().ToString()}";

                string testDirPath = Path.GetTempPath() + @"\foobar" + DateTime.Now.Ticks.ToString();
                if (!Directory.Exists(testDirPath))
                {
                    Directory.CreateDirectory(testDirPath);
                }
                string pathOfTestFile = Path.GetTempFileName();
                string fileName       = Path.GetFileName(pathOfTestFile);
                string foo            = Path.GetFullPath(testDirPath) + @"\" + fileName;
                File.Copy(pathOfTestFile, foo);


                string   commandlineArgs        = $@"--tt=upload --host={connectivitySettings.Host} -username={connectivitySettings.UserName} -password={connectivitySettings.Password} -sp={testDirPath} -dp={destinationPath}";
                string[] commandlineArgsAsArray = commandlineArgs.Split(' ');

                // act
                Program.Main(commandlineArgsAsArray);

                // assert
                IEnumerable <SftpFile> fileSystemEntries = sftpClient.ListDirectory(destinationPath);
                Assert.AreEqual(fileSystemEntries.Count(), 3);
            }
        }
        public void UploadFileTest_privateKeyConnection_canUploadFile()
        {
            // arrange
            ConnectivitySettings connectivitySettings = SftpTestsHelperRoutines.CreateConnectivitySettingsFromConfig();
            string physicalPathToPrivateKeyFile       = SftpTestsHelperRoutines.GetTestFilesPath() + connectivitySettings.PrivateKeyPath;

            connectivitySettings.PrivateKeyPath = physicalPathToPrivateKeyFile;

            DotNetSftpClient dotNetSftpClient = new DotNetSftpClient(connectivitySettings, testLogger);

            dotNetSftpClient.CreateConnection();

            // act/assert - 'assert' as in no exceptions are thrown
            string           newTempFilePath  = Path.GetTempFileName();
            TransferSettings transferSettings = new TransferSettings()
            {
                TransferType    = 'u',
                DestinationPath = string.Empty,
                SourcePath      = newTempFilePath
            };

            // act/assert - 'assert' as in no exceptions are thrown
            using (dotNetSftpClient)
            {
                dotNetSftpClient.Upload(transferSettings);
            }
        }
Exemple #5
0
        public void TestWontOverwriteFileOfDifferentSize()
        {
            // arrange
            var sftpClient = SftpTestsHelperRoutines.GenerateBasicSftpClient();

            sftpClient.Connect();
            using (sftpClient)
            {
                string destinationPath = $@"/temp/{Guid.NewGuid().ToString()}";

                string testDirPath = Path.GetTempPath() + @"\foobar" + DateTime.Now.Ticks.ToString();
                if (!Directory.Exists(testDirPath))
                {
                    Directory.CreateDirectory(testDirPath);
                }
                string pathOfTestFile = Path.GetTempFileName();
                File.WriteAllText(pathOfTestFile, "Hello World");
                string fileName = Path.GetFileName(pathOfTestFile);

                string   commandlineArgs        = $@"--tt=upload --host={connectivitySettings.Host} -username={connectivitySettings.UserName} -password={connectivitySettings.Password} -sp={pathOfTestFile} -dp={destinationPath} -ow";
                string[] commandlineArgsAsArray = commandlineArgs.Split(' ');

                // act
                DateTime firstFileWriteTimeStamp = DateTime.Now.ToUniversalTime();
                Program.Main(commandlineArgsAsArray); // first upload
                File.WriteAllText(pathOfTestFile, "Hello World - more text");
                Program.Main(commandlineArgsAsArray); // second upload - should overwrite the first
                DateTime secondFileWriteTimeStamp = DateTime.Now.ToUniversalTime();

                // assert
                var uploadedFileTimeStamp = sftpClient.GetLastWriteTimeUtc(destinationPath + @"\" + fileName);
                Assert.IsTrue(uploadedFileTimeStamp > firstFileWriteTimeStamp);
                Assert.IsTrue(uploadedFileTimeStamp < secondFileWriteTimeStamp);
            }
        }
        public static void AssemblyInit(TestContext context)
        {
            bool isTelnetServerRunning = SftpTestsHelperRoutines.IsLocalSftpServerRunning();

            if (!isTelnetServerRunning)
            {
                throw new Exception("Local SFTP-server is not running, and we need that for these integration-tests.");
            }
        }
        public void OnlineConnectivityTest_canConnect_usernameAndPassword()
        {
            // arrange
            ConnectivitySettings connectivitySettings = SftpTestsHelperRoutines.CreateConnectivitySettingsFromConfig();

            connectivitySettings.PrivateKeyPath = string.Empty;
            DotNetSftpClient dotNetSftpClient = new DotNetSftpClient(connectivitySettings, testLogger);

            // act/assert - 'assert' as in no exceptions are thrown
            using (dotNetSftpClient)
            {
                dotNetSftpClient.CreateConnection();
            }
        }
        public void OnlineConnectivityTest_ThrowsConnectionError()
        {
            // arrange
            ConnectivitySettings connectivitySettings = SftpTestsHelperRoutines.CreateConnectivitySettingsFromConfig();

            connectivitySettings.Host           = "ImPrettySureThisHostDoesntExistInAnyShapeOrForm";
            connectivitySettings.PrivateKeyPath = string.Empty;
            DotNetSftpClient dotNetSftpClient = new DotNetSftpClient(connectivitySettings, testLogger);

            // act/assert - 'assert' as in no exceptions are thrown
            using (dotNetSftpClient)
            {
                dotNetSftpClient.CreateConnection();
            }
        }
        public void OnlineConnectivityTest_privateKeyConnection_canConnect()
        {
            // arrange
            ConnectivitySettings connectivitySettings = SftpTestsHelperRoutines.CreateConnectivitySettingsFromConfig();
            string physicalPathToPrivateKeyFile       = SftpTestsHelperRoutines.GetTestFilesPath() + connectivitySettings.PrivateKeyPath;

            connectivitySettings.PrivateKeyPath = physicalPathToPrivateKeyFile;

            // act/assert - 'assert' as in no exceptions are thrown
            DotNetSftpClient dotNetSftpClient = new DotNetSftpClient(connectivitySettings, testLogger);

            using (dotNetSftpClient)
            {
                dotNetSftpClient.CreateConnection();
            }
        }
        public void UploadFileTest_usernamePasswordConnection_canUploadFile()
        {
            // arrange
            ConnectivitySettings connectivitySettings = SftpTestsHelperRoutines.CreateConnectivitySettingsFromConfig();

            connectivitySettings.PrivateKeyPath = String.Empty; // clear private key path, so we only connect via username/password
            DotNetSftpClient dotNetSftpClient = new DotNetSftpClient(connectivitySettings, testLogger);

            dotNetSftpClient.CreateConnection();

            string           newTempFilePath  = Path.GetTempFileName();
            TransferSettings transferSettings = new TransferSettings()
            {
                TransferType    = 'u',
                DestinationPath = " ",
                SourcePath      = newTempFilePath
            };

            // act/assert - 'assert' as in no exceptions are thrown
            using (dotNetSftpClient)
            {
                dotNetSftpClient.Upload(transferSettings);
            }
        }
Exemple #11
0
 public void InitializeTests()
 {
     connectivitySettings = SftpTestsHelperRoutines.CreateConnectivitySettingsFromConfig();
 }