Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 994
Add unit tests for task-based asynchronous API#906
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7d5ccb82a47c9eba7ecbb81b3a16be97986f91c5f18c662675304296a7a9474de9faec5bc16c836b751b362910fc1a657abae6c5448e1af3f0a8f5f382649b07c15350030b352fbdb46354750435067079f45e7fa53f35bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -54,11 +54,11 @@ protected override void SetupMocks() | ||
| .Setup(p => p.SendExecRequest(string.Format("scp -prf {0}", _transformedPath))) | ||
| .Returns(false); | ||
| _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose()); | ||
| #if NET35 | ||
| _pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose()); | ||
| // On .NET Core, Dispose() in turn invokes Close() and since we're not mocking | ||
| // an interface, we need to expect this call as well | ||
| _pipeStreamMock.Setup(p => p.Close()); | ||
| #else | ||
| _pipeStreamMock.InSequence(sequence).Setup(p => p.Close()); | ||
| #endif | ||
| } | ||
| protected override void Arrange() | ||
| @@ -106,7 +106,11 @@ public void DisposeOnChannelShouldBeInvokedOnce() | ||
| [TestMethod] | ||
| public void DisposeOnPipeStreamShouldBeInvokedOnce() | ||
| { | ||
| #if NET35 | ||
| _pipeStreamMock.As<IDisposable>().Verify(p => p.Dispose(), Times.Once); | ||
| #else | ||
| _pipeStreamMock.Verify(p => p.Close(), Times.Once); | ||
| #endif | ||
Comment on lines
+109
to
+113
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IgorMilavec No need to move these changes (here and elsewhere) out of this PR. | ||
| } | ||
| [TestMethod] | ||
| 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 |
| 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 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd first like to discuss dropping .NET 3.5 support.
Perhaps we'll have a final release supporting the legacy frameworks.
As I said, let's discuss this first.