-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from FrendsPlatform/issue-19
FTP.DownloadFiles - Modified operations log
- Loading branch information
Showing
12 changed files
with
615 additions
and
605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 84 additions & 84 deletions
168
Frends.FTP.DownloadFiles/Frends.FTP.DownloadFiles.Tests/MacrosTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,109 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using Frends.FTP.DownloadFiles.Enums; | ||
using Frends.FTP.DownloadFiles.TaskConfiguration; | ||
using Frends.FTP.DownloadFiles.TaskResult; | ||
using Frends.FTP.DownloadFiles.Tests.Lib; | ||
using NUnit.Framework; | ||
|
||
namespace Frends.FTP.DownloadFiles.Tests; | ||
|
||
/// <summary> | ||
/// We have several places that support macros: | ||
/// - source dir | ||
/// - destination dir | ||
/// - destination file name | ||
/// | ||
/// NOTE: | ||
/// - source file name does not support macros for some reason in Cobalt, currently not implementing because | ||
/// need to understand reasoning better | ||
/// </summary> | ||
[TestFixture] | ||
public class MacrosTests : DownloadFilesTestBase | ||
{ | ||
[Test] | ||
public void MacrosWorkInSourceDirectory() | ||
{ | ||
// Setup | ||
var year = DateTime.Now.Year; | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using Frends.FTP.DownloadFiles.Enums; | ||
using Frends.FTP.DownloadFiles.TaskConfiguration; | ||
using Frends.FTP.DownloadFiles.TaskResult; | ||
using Frends.FTP.DownloadFiles.Tests.Lib; | ||
using NUnit.Framework; | ||
|
||
namespace Frends.FTP.DownloadFiles.Tests; | ||
|
||
/// <summary> | ||
/// We have several places that support macros: | ||
/// - source dir | ||
/// - destination dir | ||
/// - destination file name | ||
/// | ||
/// NOTE: | ||
/// - source file name does not support macros for some reason in Cobalt, currently not implementing because | ||
/// need to understand reasoning better | ||
/// </summary> | ||
[TestFixture] | ||
public class MacrosTests : DownloadFilesTestBase | ||
{ | ||
[Test] | ||
public void MacrosWorkInSourceDirectory() | ||
{ | ||
// Setup | ||
var year = DateTime.Now.Year; | ||
FtpHelper.CreateFileOnFTP($"dir{year}", "file1.txt"); | ||
|
||
var result = CallDownloadFiles( | ||
"dir%Year%", | ||
"file*.txt", | ||
var result = CallDownloadFiles( | ||
"dir%Year%", | ||
"file*.txt", | ||
LocalDirFullPath); | ||
|
||
Assert.IsTrue(result.Success, result.UserResultMessage); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
Assert.IsTrue(LocalFileExists("file1.txt")); | ||
Assert.IsTrue(result.Success, result.UserResultMessage); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
Assert.IsTrue(LocalFileExists("file1.txt")); | ||
} | ||
|
||
[Test] | ||
public void MacrosWorkInDestinationDirectory() | ||
{ | ||
var year = DateTime.Now.Year; | ||
var guid = Guid.NewGuid().ToString(); | ||
FtpHelper.CreateFileOnFTP(FtpDir, "file1.txt"); | ||
var destinationDirWithMacros = Path.Combine(Path.GetTempPath(), $"transfer-%Year%-{guid}"); | ||
[Test] | ||
public void MacrosWorkInDestinationDirectory() | ||
{ | ||
var year = DateTime.Now.Year; | ||
var guid = Guid.NewGuid().ToString(); | ||
FtpHelper.CreateFileOnFTP(FtpDir, "file1.txt"); | ||
var destinationDirWithMacros = Path.Combine(Path.GetTempPath(), $"transfer-%Year%-{guid}"); | ||
var destinationDirWithMacrosExpanded = Path.Combine(Path.GetTempPath(), $"transfer-{year}-{guid}"); | ||
|
||
var result = CallDownloadFiles( | ||
FtpDir, | ||
"file1.txt", | ||
var result = CallDownloadFiles( | ||
FtpDir, | ||
"file1.txt", | ||
destinationDirWithMacros); | ||
|
||
Assert.IsTrue(result.Success, result.UserResultMessage); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
Assert.IsTrue(File.Exists(Path.Combine(destinationDirWithMacrosExpanded, "file1.txt")), result.UserResultMessage); | ||
Assert.IsTrue(result.Success, result.UserResultMessage); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
Assert.IsTrue(File.Exists(Path.Combine(destinationDirWithMacrosExpanded, "file1.txt")), result.UserResultMessage); | ||
} | ||
|
||
[Test] | ||
public void MacrosWorkInDestinationFilename() | ||
{ | ||
var year = DateTime.Now.Year; | ||
var guid = Guid.NewGuid().ToString(); | ||
FtpHelper.CreateFileOnFTP(FtpDir, "file1.txt"); | ||
var destinationFileNameWithMacros = $"f-%Year%-%SourceFileName%-{guid}"; | ||
[Test] | ||
public void MacrosWorkInDestinationFilename() | ||
{ | ||
var year = DateTime.Now.Year; | ||
var guid = Guid.NewGuid().ToString(); | ||
FtpHelper.CreateFileOnFTP(FtpDir, "file1.txt"); | ||
var destinationFileNameWithMacros = $"f-%Year%-%SourceFileName%-{guid}"; | ||
var destinationFileNameWithMacrosExpanded = $"f-{year}-file1-{guid}"; | ||
|
||
var result = CallDownloadFiles( | ||
FtpDir, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
var result = CallDownloadFiles( | ||
FtpDir, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
destinationFileNameWithMacros); | ||
|
||
Assert.IsTrue(result.Success, result.UserResultMessage); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
Assert.IsTrue(File.Exists(Path.Combine(LocalDirFullPath, destinationFileNameWithMacrosExpanded)), result.UserResultMessage); | ||
Assert.IsTrue(result.Success, result.UserResultMessage); | ||
Assert.AreEqual(1, result.SuccessfulTransferCount); | ||
Assert.IsTrue(File.Exists(Path.Combine(LocalDirFullPath, destinationFileNameWithMacrosExpanded)), result.UserResultMessage); | ||
} | ||
|
||
private Result CallDownloadFiles( | ||
string sourceDirectory, | ||
string sourceFileName, | ||
string targetDirectory, | ||
string targetFileName = null, | ||
string moveToDir = null, | ||
string renameTo = null) | ||
{ | ||
var source = new Source | ||
{ | ||
private static Result CallDownloadFiles( | ||
string sourceDirectory, | ||
string sourceFileName, | ||
string targetDirectory, | ||
string targetFileName = null, | ||
string moveToDir = null, | ||
string renameTo = null) | ||
{ | ||
var source = new Source | ||
{ | ||
Directory = sourceDirectory, | ||
FileName = sourceFileName, | ||
Operation = SourceOperation.Delete, | ||
DirectoryToMoveAfterTransfer = moveToDir, | ||
FileNameAfterTransfer = renameTo | ||
}; | ||
FileName = sourceFileName, | ||
Operation = SourceOperation.Delete, | ||
DirectoryToMoveAfterTransfer = moveToDir, | ||
FileNameAfterTransfer = renameTo | ||
}; | ||
var destination = new Destination | ||
{ | ||
Directory = targetDirectory, | ||
Action = DestinationAction.Overwrite, | ||
FileName = targetFileName | ||
}; | ||
var options = new Options { CreateDestinationDirectories = true, RenameSourceFileBeforeTransfer = true }; | ||
var connection = FtpHelper.GetFtpsConnection(); | ||
|
||
var result = FTP.DownloadFiles(source, destination, connection, options, new Info(), new CancellationToken()); | ||
return result; | ||
} | ||
}; | ||
var options = new Options { CreateDestinationDirectories = true, RenameSourceFileBeforeTransfer = true }; | ||
var connection = FtpHelper.GetFtpsConnection(); | ||
|
||
var result = FTP.DownloadFiles(source, destination, connection, options, new Info(), new CancellationToken()); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.