forked from sshnet/SSH.NET
-
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.
Add unit tests for task-based asynchronous API (sshnet#906)
* Fix runtime and culture dependant tests. * Set C# 7.3 in Tests.csproj to limit intellisense's suggestions under different targets * Add SftpClientTest.*Async * Add SftpFileStreamTest_OpenAsync_* * Add SftpFileStreamTest_WriteAsync_* * Add SftpFileStreamTest_ReadAsync_* * Align AppVeyor script with Test project target frameworks
- Loading branch information
1 parent
37fb864
commit 4dfc126
Showing
42 changed files
with
3,379 additions
and
68 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
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
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
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
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
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
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
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
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
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
69 changes: 69 additions & 0 deletions
69
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamAsyncTestBase.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#if FEATURE_TAP | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using Renci.SshNet.Sftp; | ||
|
||
namespace Renci.SshNet.Tests.Classes.Sftp | ||
{ | ||
public abstract class SftpFileStreamAsyncTestBase | ||
{ | ||
internal Mock<ISftpSession> SftpSessionMock; | ||
protected MockSequence MockSequence; | ||
|
||
protected virtual Task ArrangeAsync() | ||
{ | ||
SetupData(); | ||
CreateMocks(); | ||
SetupMocks(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
protected virtual void SetupData() | ||
{ | ||
MockSequence = new MockSequence(); | ||
} | ||
|
||
protected abstract void SetupMocks(); | ||
|
||
private void CreateMocks() | ||
{ | ||
SftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict); | ||
} | ||
|
||
[TestInitialize] | ||
public async Task SetUpAsync() | ||
{ | ||
await ArrangeAsync(); | ||
await ActAsync(); | ||
} | ||
|
||
protected abstract Task ActAsync(); | ||
|
||
protected byte[] GenerateRandom(int length) | ||
{ | ||
return GenerateRandom(length, new Random()); | ||
} | ||
|
||
protected byte[] GenerateRandom(int length, Random random) | ||
{ | ||
var buffer = new byte[length]; | ||
random.NextBytes(buffer); | ||
return buffer; | ||
} | ||
|
||
protected byte[] GenerateRandom(uint length) | ||
{ | ||
return GenerateRandom(length, new Random()); | ||
} | ||
|
||
protected byte[] GenerateRandom(uint length, Random random) | ||
{ | ||
var buffer = new byte[length]; | ||
random.NextBytes(buffer); | ||
return buffer; | ||
} | ||
} | ||
} | ||
#endif |
57 changes: 57 additions & 0 deletions
57
src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileAccessInvalid.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#if FEATURE_TAP | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Renci.SshNet.Sftp; | ||
|
||
namespace Renci.SshNet.Tests.Classes.Sftp | ||
{ | ||
[TestClass] | ||
public class SftpFileStreamTest_OpenAsync_FileAccessInvalid : SftpFileStreamAsyncTestBase | ||
{ | ||
private Random _random; | ||
private string _path; | ||
private FileMode _fileMode; | ||
private FileAccess _fileAccess; | ||
private int _bufferSize; | ||
private ArgumentOutOfRangeException _actualException; | ||
|
||
protected override void SetupData() | ||
{ | ||
base.SetupData(); | ||
|
||
_random = new Random(); | ||
_path = _random.Next().ToString(); | ||
_fileMode = FileMode.Open; | ||
_fileAccess = 0; | ||
_bufferSize = _random.Next(5, 1000); | ||
} | ||
|
||
protected override void SetupMocks() | ||
{ | ||
} | ||
|
||
protected override async Task ActAsync() | ||
{ | ||
try | ||
{ | ||
await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default); | ||
Assert.Fail(); | ||
} | ||
catch (ArgumentOutOfRangeException ex) | ||
{ | ||
_actualException = ex; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void CtorShouldHaveThrownArgumentException() | ||
{ | ||
Assert.IsNotNull(_actualException); | ||
Assert.IsNull(_actualException.InnerException); | ||
Assert.AreEqual("access", _actualException.ParamName); | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.