Skip to content

Commit 08b2d05

Browse files
committed
Added tests for issue #191, and update tests for issue #154.
1 parent 40e1068 commit 08b2d05

File tree

61 files changed

+3026
-128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3026
-128
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Moq;
4+
using Renci.SshNet.Sftp;
5+
6+
namespace Renci.SshNet.Tests.Classes.Sftp
7+
{
8+
public abstract class SftpFileStreamTestBase
9+
{
10+
internal Mock<ISftpSession> SftpSessionMock;
11+
protected MockSequence MockSequence;
12+
13+
private void Arrange()
14+
{
15+
SetupData();
16+
CreateMocks();
17+
SetupMocks();
18+
}
19+
20+
protected virtual void SetupData()
21+
{
22+
MockSequence = new MockSequence();
23+
}
24+
25+
protected abstract void SetupMocks();
26+
27+
private void CreateMocks()
28+
{
29+
SftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
30+
}
31+
32+
[TestInitialize]
33+
public void SetUp()
34+
{
35+
Arrange();
36+
Act();
37+
}
38+
39+
protected abstract void Act();
40+
41+
protected byte[] GenerateRandom(int length, Random random)
42+
{
43+
var buffer = new byte[length];
44+
random.NextBytes(buffer);
45+
return buffer;
46+
}
47+
}
48+
}

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_Closed_FileAccessRead
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)};
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint) random.Next(0, 1000);
3735
_readBufferSize = (uint) random.Next(0, 1000);
3836
_writeBufferSize = (uint) random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)};
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint) random.Next(0, 1000);
3735
_readBufferSize = (uint) random.Next(0, 1000);
3836
_writeBufferSize = (uint) random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_Closed_FileAccessWrite
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)};
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint) random.Next(0, 1000);
3735
_readBufferSize = (uint) random.Next(0, 1000);
3836
_writeBufferSize = (uint) random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_Disposed_FileAccessRead
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint)random.Next(0, 1000);
3735
_readBufferSize = (uint)random.Next(0, 1000);
3836
_writeBufferSize = (uint)random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint)random.Next(0, 1000);
3735
_readBufferSize = (uint)random.Next(0, 1000);
3836
_writeBufferSize = (uint)random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_Disposed_FileAccessWrite
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint)random.Next(0, 1000);
3735
_readBufferSize = (uint)random.Next(0, 1000);
3836
_writeBufferSize = (uint)random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint)random.Next(0, 1000);
3735
_readBufferSize = (uint)random.Next(0, 1000);
3836
_writeBufferSize = (uint)random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint)random.Next(0, 1000);
3735
_readBufferSize = (uint)random.Next(0, 1000);
3836
_writeBufferSize = (uint)random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite
1414
private string _path;
1515
private SftpFileStream _sftpFileStream;
1616
private byte[] _handle;
17-
private SftpFileAttributes _fileAttributes;
1817
private uint _bufferSize;
1918
private uint _readBufferSize;
2019
private uint _writeBufferSize;
@@ -32,7 +31,6 @@ protected void Arrange()
3231
var random = new Random();
3332
_path = random.Next().ToString(CultureInfo.InvariantCulture);
3433
_handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
35-
_fileAttributes = SftpFileAttributes.Empty;
3634
_bufferSize = (uint)random.Next(0, 1000);
3735
_readBufferSize = (uint)random.Next(0, 1000);
3836
_writeBufferSize = (uint)random.Next(0, 1000);
@@ -43,7 +41,6 @@ protected void Arrange()
4341
_sftpSessionMock.InSequence(sequence)
4442
.Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
4543
.Returns(_handle);
46-
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle, false)).Returns(_fileAttributes);
4744
_sftpSessionMock.InSequence(sequence)
4845
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
4946
.Returns(_readBufferSize);

0 commit comments

Comments
 (0)