-
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 #38 from FrendsPlatform/issue-37
DownloadFiles - Added timeout setups for FtpClient
- Loading branch information
Showing
7 changed files
with
251 additions
and
191 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
130 changes: 65 additions & 65 deletions
130
Frends.FTP.DownloadFiles/Frends.FTP.DownloadFiles.Tests/DestinationActionTests.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,76 +1,76 @@ | ||
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; | ||
|
||
[TestFixture] | ||
public class DestinationActionTests : DownloadFilesTestBase | ||
{ | ||
[Test] | ||
public void DestinationAction_Append_NoRenameInTransfer() | ||
{ | ||
FtpHelper.CreateFileOnFTP(FtpDir, "file1.txt", "mycontent"); | ||
|
||
var result1 = CallDownloadFiles( | ||
DestinationAction.Overwrite, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
false); | ||
var result2 = CallDownloadFiles( | ||
DestinationAction.Append, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
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; | ||
|
||
[TestFixture] | ||
public class DestinationActionTests : DownloadFilesTestBase | ||
{ | ||
[Test] | ||
public void DestinationAction_Append_NoRenameInTransfer() | ||
{ | ||
FtpHelper.CreateFileOnFTP(FtpDir, "file1.txt", "mycontent"); | ||
|
||
var result1 = CallDownloadFiles( | ||
DestinationAction.Overwrite, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
false); | ||
var result2 = CallDownloadFiles( | ||
DestinationAction.Append, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
false); | ||
|
||
Assert.IsTrue(result1.Success, result1.UserResultMessage); | ||
Assert.IsTrue(result2.Success, result2.UserResultMessage); | ||
Assert.AreEqual(1, result2.SuccessfulTransferCount); | ||
Assert.AreEqual("mycontentmycontent", File.ReadAllText($"{LocalDirFullPath}/file1.txt")); | ||
Assert.IsTrue(result1.Success, result1.UserResultMessage); | ||
Assert.IsTrue(result2.Success, result2.UserResultMessage); | ||
Assert.AreEqual(1, result2.SuccessfulTransferCount); | ||
Assert.AreEqual("mycontentmycontent", File.ReadAllText($"{LocalDirFullPath}/file1.txt")); | ||
} | ||
|
||
[Test] | ||
public void DestinationAction_Append_WithRenameInTransfer() | ||
{ | ||
[Test] | ||
public void DestinationAction_Append_WithRenameInTransfer() | ||
{ | ||
FtpHelper.CreateFileOnFTP(FtpDir, "file1.txt", "mycontent"); | ||
|
||
var result1 = CallDownloadFiles( | ||
DestinationAction.Overwrite, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
true); | ||
var result2 = CallDownloadFiles( | ||
DestinationAction.Append, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
var result1 = CallDownloadFiles( | ||
DestinationAction.Overwrite, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
true); | ||
var result2 = CallDownloadFiles( | ||
DestinationAction.Append, | ||
"file1.txt", | ||
LocalDirFullPath, | ||
true); | ||
|
||
Assert.IsTrue(result1.Success, result1.UserResultMessage); | ||
Assert.IsTrue(result2.Success, result2.UserResultMessage); | ||
Assert.AreEqual(1, result2.SuccessfulTransferCount); | ||
Assert.AreEqual("mycontentmycontent", File.ReadAllText($"{LocalDirFullPath}/file1.txt")); | ||
Assert.IsTrue(result1.Success, result1.UserResultMessage); | ||
Assert.IsTrue(result2.Success, result2.UserResultMessage); | ||
Assert.AreEqual(1, result2.SuccessfulTransferCount); | ||
Assert.AreEqual("mycontentmycontent", File.ReadAllText($"{LocalDirFullPath}/file1.txt")); | ||
} | ||
|
||
private Result CallDownloadFiles( | ||
DestinationAction destinationAction, string sourceFileName, string targetDir, | ||
bool renameDestinationFilesDuringTransfer) | ||
{ | ||
var source = new Source | ||
{ | ||
Directory = FtpDir, | ||
FileName = sourceFileName, | ||
Operation = SourceOperation.Nothing | ||
}; | ||
|
||
var destination = new Destination { Directory = targetDir, Action = destinationAction }; | ||
var options = new Options { CreateDestinationDirectories = true, RenameDestinationFileDuringTransfer = renameDestinationFilesDuringTransfer }; | ||
var connection = FtpHelper.GetFtpsConnection(); | ||
|
||
var result = FTP.DownloadFiles(source, destination, connection, options, new Info(), new CancellationToken()); | ||
return result; | ||
} | ||
private Result CallDownloadFiles( | ||
DestinationAction destinationAction, string sourceFileName, string targetDir, | ||
bool renameDestinationFilesDuringTransfer) | ||
{ | ||
var source = new Source | ||
{ | ||
Directory = FtpDir, | ||
FileName = sourceFileName, | ||
Operation = SourceOperation.Nothing | ||
}; | ||
|
||
var destination = new Destination { Directory = targetDir, Action = destinationAction }; | ||
var options = new Options { CreateDestinationDirectories = true, RenameDestinationFileDuringTransfer = renameDestinationFilesDuringTransfer }; | ||
var connection = FtpHelper.GetFtpsConnection(); | ||
|
||
var result = FTP.DownloadFiles(source, destination, connection, options, new Info(), new CancellationToken()); | ||
return result; | ||
} | ||
} |
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
94 changes: 47 additions & 47 deletions
94
Frends.FTP.DownloadFiles/Frends.FTP.DownloadFiles.Tests/Lib/DownloadFilesTestBase.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,52 +1,52 @@ | ||
using System; | ||
using System.IO; | ||
using NUnit.Framework; | ||
|
||
namespace Frends.FTP.DownloadFiles.Tests.Lib; | ||
|
||
public class DownloadFilesTestBase | ||
{ | ||
protected string LocalDirFullPath; | ||
protected static FtpHelper FtpHelper; | ||
protected string FtpDir; | ||
|
||
[OneTimeSetUp] | ||
public void OneTimeSetUp() | ||
{ | ||
FtpHelper = new FtpHelper(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void OneTimeTearDown() | ||
{ | ||
FtpHelper.Dispose(); | ||
using System; | ||
using System.IO; | ||
using NUnit.Framework; | ||
|
||
namespace Frends.FTP.DownloadFiles.Tests.Lib; | ||
|
||
public class DownloadFilesTestBase | ||
{ | ||
protected string LocalDirFullPath; | ||
protected static FtpHelper FtpHelper; | ||
protected string FtpDir; | ||
|
||
[OneTimeSetUp] | ||
public void OneTimeSetUp() | ||
{ | ||
FtpHelper = new FtpHelper(); | ||
} | ||
|
||
[OneTimeTearDown] | ||
public void OneTimeTearDown() | ||
{ | ||
FtpHelper.Dispose(); | ||
} | ||
|
||
protected bool LocalFileExists(string fileName, string subDir = null) | ||
{ | ||
var path = subDir == null ? LocalDirFullPath : Path.Combine(Path.GetTempPath(), subDir); | ||
return File.Exists(Path.Combine(path, fileName)); | ||
} | ||
|
||
protected static string CreateLocalDir(string name) | ||
{ | ||
var dir = Path.Combine(Path.GetTempPath(), name); | ||
Directory.CreateDirectory(dir); | ||
return dir; | ||
protected bool LocalFileExists(string fileName, string subDir = null) | ||
{ | ||
var path = subDir == null ? LocalDirFullPath : Path.Combine(Path.GetTempPath(), subDir); | ||
return File.Exists(Path.Combine(path, fileName)); | ||
} | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
LocalDirFullPath = CreateLocalDir(Guid.NewGuid().ToString()); | ||
FtpDir = Guid.NewGuid().ToString(); | ||
FtpHelper.CreateDirectoryOnFTP(FtpDir); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
Directory.Delete(LocalDirFullPath, true); | ||
FtpHelper.DeleteDirectoryOnFTP(FtpDir); | ||
} | ||
protected static string CreateLocalDir(string name) | ||
{ | ||
var dir = Path.Combine(Path.GetTempPath(), name); | ||
Directory.CreateDirectory(dir); | ||
return dir; | ||
} | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
LocalDirFullPath = CreateLocalDir(Guid.NewGuid().ToString()); | ||
FtpDir = Guid.NewGuid().ToString(); | ||
FtpHelper.CreateDirectoryOnFTP(FtpDir); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
Directory.Delete(LocalDirFullPath, true); | ||
FtpHelper.DeleteDirectoryOnFTP(FtpDir); | ||
} | ||
} |
Oops, something went wrong.