Skip to content

Commit

Permalink
Use CollectionAssert in ListDirectory tests (#1166)
Browse files Browse the repository at this point in the history
* Use CollectionAssert in ListDirectory tests

* Indent the braces

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
  • Loading branch information
Rob-Hague and WojciechNagorski authored Nov 13, 2023
1 parent 5ffcb94 commit 823bc1b
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions test/Renci.SshNet.IntegrationTests/SftpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public void Create_directory_with_contents_and_list_it()
Assert.IsTrue(_sftpClient.Exists(testFilePath));

// Check if ListDirectory works
var files = _sftpClient.ListDirectory(testDirectory);
var expectedFiles = new List<(string FullName, bool IsRegularFile, bool IsDirectory)>()
{
("/home/sshnet/sshnet-test/.", IsRegularFile: false, IsDirectory: true),
("/home/sshnet/sshnet-test/..", IsRegularFile: false, IsDirectory: true),
("/home/sshnet/sshnet-test/test-file.txt", IsRegularFile: true, IsDirectory: false),
};

var actualFiles = _sftpClient.ListDirectory(testDirectory)
.Select(f => (f.FullName, f.IsRegularFile, f.IsDirectory))
.ToList();

_sftpClient.DeleteFile(testFilePath);
_sftpClient.DeleteDirectory(testDirectory);

var builder = new StringBuilder();
foreach (var file in files)
{
builder.AppendLine($"{file.FullName} {file.IsRegularFile} {file.IsDirectory}");
}

Assert.AreEqual(@"/home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
", builder.ToString());
CollectionAssert.AreEquivalent(expectedFiles, actualFiles);
}

[TestMethod]
Expand All @@ -69,21 +69,24 @@ public async Task Create_directory_with_contents_and_list_it_async()
Assert.IsTrue(_sftpClient.Exists(testFilePath));

// Check if ListDirectory works
var files = _sftpClient.ListDirectoryAsync(testDirectory, CancellationToken.None);
var expectedFiles = new List<(string FullName, bool IsRegularFile, bool IsDirectory)>()
{
("/home/sshnet/sshnet-test/.", IsRegularFile: false, IsDirectory: true),
("/home/sshnet/sshnet-test/..", IsRegularFile: false, IsDirectory: true),
("/home/sshnet/sshnet-test/test-file.txt", IsRegularFile: true, IsDirectory: false),
};

var actualFiles = new List<(string FullName, bool IsRegularFile, bool IsDirectory)>();

var builder = new StringBuilder();
await foreach (var file in files)
await foreach (var file in _sftpClient.ListDirectoryAsync(testDirectory, CancellationToken.None))
{
builder.AppendLine($"{file.FullName} {file.IsRegularFile} {file.IsDirectory}");
actualFiles.Add((file.FullName, file.IsRegularFile, file.IsDirectory));
}

_sftpClient.DeleteFile(testFilePath);
_sftpClient.DeleteDirectory(testDirectory);

Assert.AreEqual(@"/home/sshnet/sshnet-test/. False True
/home/sshnet/sshnet-test/.. False True
/home/sshnet/sshnet-test/test-file.txt True False
", builder.ToString());
CollectionAssert.AreEquivalent(expectedFiles, actualFiles);
}

[TestMethod]
Expand Down

0 comments on commit 823bc1b

Please sign in to comment.