-
Notifications
You must be signed in to change notification settings - Fork 140
FTP: Sftp improvements [STUD-79812] [STUD-72320] #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
viogroza
wants to merge
1
commit into
develop
Choose a base branch
from
fix/ftp_issues
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
Activities/FTP/UiPath.FTP.Activities/Properties/UiPath.FTP.Activities.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
98 changes: 98 additions & 0 deletions
98
Activities/FTP/UiPath.FTP.Tests/ActivitiesTests/DirectoryExistsTests.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -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
98
Activities/FTP/UiPath.FTP.Tests/ActivitiesTests/FileExistsTests.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -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) | ||
| } | ||
| }); | ||
| } | ||
|
viogroza marked this conversation as resolved.
|
||
|
|
||
| WorkflowInvoker.Invoke(activity, TimeSpan.FromSeconds(5)); | ||
| return result[0]; | ||
| } | ||
|
viogroza marked this conversation as resolved.
|
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.