diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_DiscardsFurtherReadAheads.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_DiscardsFurtherReadAheads.cs index 8c709252..22384719 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_DiscardsFurtherReadAheads.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_DiscardsFurtherReadAheads.cs @@ -15,6 +15,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp { private const int ChunkLength = 32 * 1024; + private MockSequence _seq; private byte[] _handle; private int _fileSize; private byte[] _chunk1; @@ -40,9 +41,9 @@ namespace Renci.SshNet.Tests.Classes.Sftp protected override void SetupMocks() { - var seq = new MockSequence(); + _seq = new MockSequence(); - SftpSessionMock.InSequence(seq) + SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 0, ChunkLength, It.IsNotNull(), It.IsAny())) .Callback((handle, offset, length, callback, state) => { @@ -50,7 +51,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp asyncResult.SetAsCompleted(_chunk1, false); }) .Returns((SftpReadAsyncResult)null); - SftpSessionMock.InSequence(seq) + SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, ChunkLength, ChunkLength, It.IsNotNull(), It.IsAny())) .Callback((handle, offset, length, callback, state) => { @@ -65,7 +66,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp }); }) .Returns((SftpReadAsyncResult)null); - SftpSessionMock.InSequence(seq) + SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 2 * ChunkLength, ChunkLength, It.IsNotNull(), It.IsAny())) .Callback((handle, offset, length, callback, state) => { @@ -129,13 +130,17 @@ namespace Renci.SshNet.Tests.Classes.Sftp } [TestMethod] - public void DisposeShouldCompleteImmediately() + public void DisposeShouldCloseHandleAndCompleteImmediately() { + SftpSessionMock.InSequence(_seq).Setup(p => p.RequestClose(_handle)); + var stopwatch = Stopwatch.StartNew(); _reader.Dispose(); stopwatch.Stop(); Assert.IsTrue(stopwatch.ElapsedMilliseconds < 200, "Dispose took too long to complete: " + stopwatch.ElapsedMilliseconds); + + SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); } } } diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_PreventsFurtherReadAheads.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_PreventsFurtherReadAheads.cs index b1134a4b..cdee15ae 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_PreventsFurtherReadAheads.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_ReadAheadEndInvokeException_PreventsFurtherReadAheads.cs @@ -15,6 +15,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp { private const int ChunkLength = 32 * 1024; + private MockSequence _seq; private byte[] _handle; private int _fileSize; private byte[] _chunk1; @@ -42,9 +43,9 @@ namespace Renci.SshNet.Tests.Classes.Sftp protected override void SetupMocks() { - var seq = new MockSequence(); + _seq = new MockSequence(); - SftpSessionMock.InSequence(seq) + SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 0, ChunkLength, It.IsNotNull(), It.IsAny())) .Callback((handle, offset, length, callback, state) => { @@ -52,7 +53,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp asyncResult.SetAsCompleted(_chunk1, false); }) .Returns((SftpReadAsyncResult)null); - SftpSessionMock.InSequence(seq) + SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, ChunkLength, ChunkLength, It.IsNotNull(), It.IsAny())) .Callback((handle, offset, length, callback, state) => { @@ -70,7 +71,7 @@ namespace Renci.SshNet.Tests.Classes.Sftp }); }) .Returns((SftpReadAsyncResult)null); - SftpSessionMock.InSequence(seq) + SftpSessionMock.InSequence(_seq) .Setup(p => p.BeginRead(_handle, 2 * ChunkLength, ChunkLength, It.IsNotNull(), It.IsAny())) .Callback((handle, offset, length, callback, state) => { @@ -136,13 +137,17 @@ namespace Renci.SshNet.Tests.Classes.Sftp } [TestMethod] - public void DisposeShouldCompleteImmediately() + public void DisposeShouldCloseHandleAndCompleteImmediately() { + SftpSessionMock.InSequence(_seq).Setup(p => p.RequestClose(_handle)); + var stopwatch = Stopwatch.StartNew(); _reader.Dispose(); stopwatch.Stop(); Assert.IsTrue(stopwatch.ElapsedMilliseconds < 200, "Dispose took too long to complete: " + stopwatch.ElapsedMilliseconds); + + SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); } [TestMethod]