Skip to content

Commit

Permalink
Implemented changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RikuVirtanen committed Dec 19, 2023
1 parent c335e46 commit a0f6746
Show file tree
Hide file tree
Showing 23 changed files with 1,047 additions and 624 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ListFiles_build_and_test_on_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ jobs:
uses: FrendsPlatform/FrendsTasks/.github/workflows/build_main.yml@main
with:
workdir: Frends.FTP.ListFiles
env_var_name_1: HiQ_FTP_Host
env_var_name_2: HiQ_FTP_User
env_var_name_3: HiQ_FTP_Password
prebuild_command: docker-compose -f Frends.FTP.DownloadFiles.Tests/docker-compose.yml up -d
secrets:
badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }}
env_var_value_1: ${{ secrets.HIQ_FTP_HOST }}
env_var_value_2: ${{ secrets.HIQ_FTP_USER }}
env_var_value_3: ${{ secrets.HIQ_FTP_PASSWORD }}
badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }}
9 changes: 2 additions & 7 deletions .github/workflows/ListFiles_build_and_test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ jobs:
uses: FrendsPlatform/FrendsTasks/.github/workflows/build_test.yml@main
with:
workdir: Frends.FTP.ListFiles
env_var_name_1: HiQ_FTP_Host
env_var_name_2: HiQ_FTP_User
env_var_name_3: HiQ_FTP_Password
prebuild_command: docker-compose -f Frends.FTP.DownloadFiles.Tests/docker-compose.yml up -d
secrets:
badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }}
test_feed_api_key: ${{ secrets.TASKS_TEST_FEED_API_KEY }}
env_var_value_1: ${{ secrets.HIQ_FTP_HOST }}
env_var_value_2: ${{ secrets.HIQ_FTP_USER }}
env_var_value_3: ${{ secrets.HIQ_FTP_PASSWORD }}
test_feed_api_key: ${{ secrets.TASKS_TEST_FEED_API_KEY }}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN X9.42 DH PARAMETERS-----
MIICLAKCAQEAw2Vi3DlhlltVCbM+vrY7qXBL62xIsyYGWHDVRiQR1CxfdPpy7AVG
lPc1FWsFBrUMVmhKBwsktlQmCzT7Hf6DdBFLU4V2erCER1IkEkwuC1IC61j8NTFq
59jVNjgy7RFTN3n0eFvaT7U/PQIyC7gGqlYHJpPnBb8nul3AF5aGdrlHvuvattwY
6P6PtpJCpGypZi352nGMkMFhA/tcBfi3jp9hFA7o6HJi89/UZzeO1ks1uEUf3EFv
rx7ckWBW9Rr85bTNsAcOn1q9h2BVoY8RjRHNTtzwpiygE31BRovShVL4UL+uYZ+E
1qKBdfV8KLyGT6IEdxEwHD+JC+3oMA1TfQKCAQB+2MtPTMZDRLJfy//8DbEajAK4
SyBzv7OHjZ/Oin4we1tE9FtLUDNwXNocGVPyHLK+cYhhDOcVWI3LdCyY38abSnhE
XWUA5q28OQsfsoDT/6EOx8NZ5A69UgNtzUyHfacnWCtVZ+WCUO6qb/XreqFZhuJD
tt4wwwitl2xU2C29CNqd3mTVukDypkHhBZZosMn6r4Jyw6V98xoZx9pvSqk8ts84
4bfTAgcfbWW7IH5C4ah6yVWfEkCbYIs5NPgAha0qumWPwpvMQSAXihYKKF3MgYWm
n+va+f6/GG3lIIbuvea/ESh9W7mSytAgwqd27JXtxcNd9D+Yu3f8khefBcvYAiEA
u4TEb+qo7uxkHl/8p1q6t7fLGqtomQCJTxufjVjkJUM=
-----END X9.42 DH PARAMETERS-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCU0FaMrsBVqfPd
ZncSFilS3JcOR6nZZE7mKDTo868Nz016yJXwBSEjg3z81tSTkNhocrQPvxWJAobV
TXy0h0yXhJMlKV4wQKyRXsdSrS5nn2NTA+fj3kx+Gtz+4yADiDB/egkOGKAm3RZM
grhjglR94BZR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DF2lAgMBAAGjUzBRMB0GA1UdDgQWBBTmLsDgEYUp5f7M6INaiTd3vxVvODAfBgNV
HSMEGDAWgBTmLsDgEYUp5f7M6INaiTd3vxVvODAPBgNVHRMBAf8EBTADAQH/MA0G
CSqGSIb3DQEBCwUAA4IBAQAtPbygrCcfrSwKsgi6anBwzGgvdshK5lEF75LbuTPD
S/yagTfLfEtkNkYmTal7Llsa6RP64bpNNIx6n9vuKtuyRUM3YJzksUAPokkBe7cw
FcexXcqBnh5u9ZBfMnSkM02iB+cRbiKYskeWVeuct01uDfGsyxc7gWOw2yeAZhXC
8opQlzVMs2tk43VIy7dmFuj/D7BwHK0Lc1eEf56Q0CaE7kMM8NzROs7Zonm2eMqz
RAgOFNPax+zsqjCr1493w4luLzUzimDISsXIrZF3+RA+rBWnMbUKtApUM5fJUAl/
qZh3mieSHCh/pEeNesnn+FZu8k3HpIknlm2b3J5WzZK8
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Frends.FTP.ListFiles\Frends.FTP.ListFiles.csproj" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Frends.FTP.ListFiles\Frends.FTP.ListFiles.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="DockerVolumes\data\ftp\test\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "<Pending>", Scope = "member", Target = "~F:Frends.FTP.ListFiles.Tests.Lib.ListFilesTestBase.FtpHelper")]
83 changes: 83 additions & 0 deletions Frends.FTP.ListFiles/Frends.FTP.ListFiles.Tests/Lib/FtpHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Text;
using FluentFTP;
using Frends.FTP.ListFiles.Definitions;

namespace Frends.FTP.ListFiles.Tests;

public class FtpHelper : IDisposable
{
// Those values are taken directly from docker compose (see docker-compose.yml)
internal static readonly string FtpHost = "localhost";
internal static readonly int FtpPort = 21;
internal static readonly int FtpsPort = 21;
internal static readonly string FtpUsername = "frendsuser";
internal static readonly string FtpPassword = "frendspass";
internal static readonly string Sha1Hash = "D911262984DE9CC32A3518A1094CD24249EA5C49";
readonly FtpClient client = new();

public FtpHelper()
{
client = new FtpClient(FtpHost, FtpPort, FtpUsername, FtpPassword);
client.Connect();
}

internal static Connection GetFtpsConnection()
{
var connection = new Connection
{
UseFTPS = true,
Address = FtpHost,
UserName = FtpUsername,
Password = FtpPassword,
Port = FtpsPort,
SslMode = FtpsSslMode.Explicit,
CertificateHashStringSHA1 = Sha1Hash
};

return connection;
}

internal static Connection GetFtpConnection()
{
var connection = new Connection
{
Address = FtpHost,
UserName = FtpUsername,
Password = FtpPassword,
Port = FtpPort,
SslMode = FtpsSslMode.None
};

return connection;
}

internal void CreateFileOnFTP(string subDir, string fileName, string content = "hello")
{
client.CreateDirectory(subDir);
client.SetWorkingDirectory(subDir);
client.Upload(Encoding.UTF8.GetBytes(content), fileName);
client.SetWorkingDirectory("/");
}

internal void CreateDirectoryOnFTP(string subDir)
{
client.CreateDirectory(subDir);
}

internal bool FileExistsOnFTP(string subDir, string fileName)
{
return client.FileExists(subDir + "/" + fileName);
}

public void Dispose()
{
GC.SuppressFinalize(this);
client.Disconnect();
if (!client.IsDisposed) client.Dispose();
}

public void DeleteDirectoryOnFTP(string ftpDir)
{
client.DeleteDirectory(ftpDir, FtpListOption.Recursive);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using NUnit.Framework;
using Frends.FTP.ListFiles.Definitions;

namespace Frends.FTP.ListFiles.Tests.Lib;

public class ListFilesTestBase
{
protected string LocalDirFullPath = string.Empty;
protected static FtpHelper FtpHelper = new();
protected string FtpDir = string.Empty;

protected Input input = new();

[OneTimeSetUp]
public void OneTimeSetUp()
{
FtpHelper = new FtpHelper();
}

[OneTimeTearDown]
public void OneTimeTearDown()
{
if (FtpHelper != null)
FtpHelper.Dispose();
}

[SetUp]
public void SetUp()
{
FtpDir = Guid.NewGuid().ToString();
var files = new string[]
{
$"Test1.txt",
$"Test1.xlsx",
$"Test1.xml",
$"testfile.txt",
$"DemoTest.txt"
};

foreach (var file in files)
{
FtpHelper.CreateFileOnFTP(FtpDir, file);
}

input = new Input
{
FileMask = "*",
Directory = FtpDir,
IncludeSubdirectories = false,
IncludeType = IncludeType.File
};
}

[TearDown]
public void TearDown()
{
FtpHelper.DeleteDirectoryOnFTP(FtpDir);
}
}
Loading

0 comments on commit a0f6746

Please sign in to comment.