Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
<value>Path to the Private key in PKCS #1 PEM format</value>
</data>
<data name="NoValidAuthenticationMethod" xml:space="preserve">
<value>No valid authentication method found: You need to supply either Private Key file (and optionally passphare) or Password</value>
<value>No valid authentication method found: You need to supply either Private Key file (and optionally passphrase) or Password</value>
</data>
<data name="NewPath" xml:space="preserve">
<value>New remote path</value>
Expand Down
3 changes: 2 additions & 1 deletion Activities/FTP/UiPath.FTP.Activities/WithFtpSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ protected override async Task<Action<NativeActivityContext>> ExecuteAsync(Native
throw new ArgumentNullException(Resources.EmptyUsernameException);
}

if (string.IsNullOrWhiteSpace(ftpConfiguration.Password) && string.IsNullOrWhiteSpace(ftpConfiguration.ClientCertificatePath))
if (string.IsNullOrWhiteSpace(ftpConfiguration.Password) && string.IsNullOrWhiteSpace(ftpConfiguration.ClientCertificatePath)
&& !UseSftp)
Comment thread
viogroza marked this conversation as resolved.
{
throw new ArgumentNullException(Resources.NoValidAuthenticationMethod);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using Moq;
using System;
using System.Activities;
using System.Activities.Statements;
using System.Threading;
using System.Threading.Tasks;
using UiPath.FTP.Activities;
using Xunit;

namespace UiPath.FTP.Tests.ActivitiesTests
{
public class DirectoryExistsTests
{
[Fact]
public void DirectoryExists_SetsExistsTrue_WhenSessionReturnsTrue()
{
var session = CreateSessionMock(exists: true);
bool result = RunActivity(session, "/remote/dir");
Assert.True(result);
}

[Fact]
public void DirectoryExists_SetsExistsFalse_WhenSessionReturnsFalse()
{
var session = CreateSessionMock(exists: false);
bool result = RunActivity(session, "/remote/dir");
Assert.False(result);
}

[Fact]
public void DirectoryExists_CallsDirectoryExistsAsync_WithCorrectPath()
{
var session = CreateSessionMock(exists: false);
RunActivity(session, "/expected/path");
session.Verify(
s => s.DirectoryExistsAsync("/expected/path", It.IsAny<CancellationToken>()),
Times.Once);
}

[Fact]
public void DirectoryExists_PropagatesException_WhenSessionThrows()
{
var session = new Mock<IFtpSession>();
session
.Setup(s => s.DirectoryExistsAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new InvalidOperationException("session error"));

var ex = Assert.ThrowsAny<Exception>(() => RunActivity(session, "/remote/dir"));
Assert.Contains(TestsHelper.Flatten(ex), e => e is InvalidOperationException);
}

// --- Helpers ---

private static Mock<IFtpSession> CreateSessionMock(bool exists)
{
var session = new Mock<IFtpSession>();
session
.Setup(s => s.DirectoryExistsAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(exists));
return session;
}

private static bool RunActivity(Mock<IFtpSession> session, string remotePath)
{
var result = new bool[1];
var resultVariable = new Variable<bool>("exists");
var activity = new WithFtpSession(session.Object)
{
Host = new InArgument<string>("NonUsed"),
Username = new InArgument<string>("NonUsed"),
Password = new InArgument<string>("NonUsed"),
};

if (activity.Body.Handler is Sequence seq)
{
seq.Variables.Add(resultVariable);
seq.Activities.Add(new DirectoryExists
{
RemotePath = new InArgument<string>(remotePath),
Exists = new OutArgument<bool>(resultVariable)
});
seq.Activities.Add(new InvokeMethod
{
TargetType = typeof(TestsHelper),
MethodName = nameof(TestsHelper.CopyBool),
Parameters =
{
new InArgument<bool>(ctx => resultVariable.Get(ctx)),
new InArgument<bool[]>(ctx => result)
}
});
}

WorkflowInvoker.Invoke(activity, TimeSpan.FromSeconds(5));
return result[0];
}
}
}
98 changes: 98 additions & 0 deletions Activities/FTP/UiPath.FTP.Tests/ActivitiesTests/FileExistsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using Moq;
using System;
using System.Activities;
using System.Activities.Statements;
using System.Threading;
using System.Threading.Tasks;
using UiPath.FTP.Activities;
using Xunit;

namespace UiPath.FTP.Tests.ActivitiesTests
{
public class FileExistsTests
{
[Fact]
public void FileExists_SetsExistsTrue_WhenSessionReturnsTrue()
{
var session = CreateSessionMock(exists: true);
bool result = RunActivity(session, "/remote/file.txt");
Assert.True(result);
}

[Fact]
public void FileExists_SetsExistsFalse_WhenSessionReturnsFalse()
{
var session = CreateSessionMock(exists: false);
bool result = RunActivity(session, "/remote/file.txt");
Assert.False(result);
}

[Fact]
public void FileExists_CallsFileExistsAsync_WithCorrectPath()
{
var session = CreateSessionMock(exists: false);
RunActivity(session, "/expected/file.txt");
session.Verify(
s => s.FileExistsAsync("/expected/file.txt", It.IsAny<CancellationToken>()),
Times.Once);
}

[Fact]
public void FileExists_PropagatesException_WhenSessionThrows()
{
var session = new Mock<IFtpSession>();
session
.Setup(s => s.FileExistsAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new InvalidOperationException("session error"));

var ex = Assert.ThrowsAny<Exception>(() => RunActivity(session, "/remote/file.txt"));
Assert.Contains(TestsHelper.Flatten(ex), e => e is InvalidOperationException);
}

// --- Helpers ---

private static Mock<IFtpSession> CreateSessionMock(bool exists)
{
var session = new Mock<IFtpSession>();
session
.Setup(s => s.FileExistsAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(exists));
return session;
}

private static bool RunActivity(Mock<IFtpSession> session, string remotePath)
{
var result = new bool[1];
var resultVariable = new Variable<bool>("exists");
var activity = new WithFtpSession(session.Object)
{
Host = new InArgument<string>("NonUsed"),
Username = new InArgument<string>("NonUsed"),
Password = new InArgument<string>("NonUsed"),
};

if (activity.Body.Handler is Sequence seq)
{
seq.Variables.Add(resultVariable);
seq.Activities.Add(new FileExists
{
RemotePath = new InArgument<string>(remotePath),
Exists = new OutArgument<bool>(resultVariable)
});
seq.Activities.Add(new InvokeMethod
{
TargetType = typeof(TestsHelper),
MethodName = nameof(TestsHelper.CopyBool),
Parameters =
{
new InArgument<bool>(ctx => resultVariable.Get(ctx)),
new InArgument<bool[]>(ctx => result)
}
});
}
Comment thread
viogroza marked this conversation as resolved.

WorkflowInvoker.Invoke(activity, TimeSpan.FromSeconds(5));
return result[0];
}
Comment thread
viogroza marked this conversation as resolved.
}
}
Loading