Skip to content

Commit a5148ae

Browse files
committed
Fix some test failures on .NET Core.
1 parent d5fefcc commit a5148ae

7 files changed

+71
-39
lines changed

src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndDirectoryInfo_SendExecRequestReturnsFalse.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ protected override void SetupMocks()
5555
.Returns(false);
5656
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
5757
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
58+
59+
// On .NET Core, Dispose() in turn invokes Close() and since we're not mocking
60+
// an interface, we need to expect this call as well
61+
_pipeStreamMock.Setup(p => p.Close());
5862
}
5963

6064
protected override void Arrange()

src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndFileInfo_SendExecRequestReturnsFalse.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ protected override void SetupMocks()
5454
.Setup(p => p.SendExecRequest(string.Format("scp -pf {0}", _transformedPath))).Returns(false);
5555
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
5656
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
57+
58+
// On .NET Core, Dispose() in turn invokes Close() and since we're not mocking
59+
// an interface, we need to expect this call as well
60+
_pipeStreamMock.Setup(p => p.Close());
5761
}
5862

5963
protected override void Arrange()

src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndStream_SendExecRequestReturnsFalse.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ public class ScpClientTest_Download_PathAndStream_SendExecRequestReturnsFalse :
1919
private IList<ScpUploadEventArgs> _uploadingRegister;
2020
private SshException _actualException;
2121

22-
[TestCleanup]
23-
public void Cleanup()
24-
{
25-
if (_destination != null)
26-
{
27-
_destination.Dispose();
28-
}
29-
}
30-
3122
protected override void SetupData()
3223
{
3324
var random = new Random();
@@ -64,6 +55,10 @@ protected override void SetupMocks()
6455
.Returns(false);
6556
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
6657
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
58+
59+
// On .NET Core, Dispose() in turn invokes Close() and since we're not mocking
60+
// an interface, we need to expect this call as well
61+
_pipeStreamMock.Setup(p => p.Close());
6762
}
6863

6964
protected override void Arrange()
@@ -75,6 +70,16 @@ protected override void Arrange()
7570
_scpClient.Connect();
7671
}
7772

73+
protected override void TearDown()
74+
{
75+
base.TearDown();
76+
77+
if (_destination != null)
78+
{
79+
_destination.Dispose();
80+
}
81+
}
82+
7883
protected override void Act()
7984
{
8085
try

src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_DirectoryInfoAndPath_SendExecRequestReturnsFalse.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ protected override void SetupMocks()
5454
.Returns(false);
5555
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
5656
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
57+
58+
// On .NET Core, Dispose() in turn invokes Close() and since we're not mocking
59+
// an interface, we need to expect this call as well
60+
_pipeStreamMock.Setup(p => p.Close());
5761
}
5862

5963
protected override void Arrange()

src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ public class ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse :
2121
private IList<ScpUploadEventArgs> _uploadingRegister;
2222
private SshException _actualException;
2323

24-
[TestCleanup]
25-
public void Cleanup()
26-
{
27-
if (_fileName != null)
28-
{
29-
File.Delete(_fileName);
30-
_fileName = null;
31-
}
32-
}
33-
3424
protected override void SetupData()
3525
{
3626
var random = new Random();
@@ -70,7 +60,11 @@ protected override void SetupMocks()
7060
.Returns(false);
7161
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
7262
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
73-
}
63+
64+
// On .NET Core, Dispose() in turn invokes Close() and since we're not mocking
65+
// an interface, we need to expect this call as well
66+
_pipeStreamMock.Setup(p => p.Close());
67+
}
7468

7569
protected override void Arrange()
7670
{
@@ -81,6 +75,17 @@ protected override void Arrange()
8175
_scpClient.Connect();
8276
}
8377

78+
protected override void TearDown()
79+
{
80+
base.TearDown();
81+
82+
if (_fileName != null)
83+
{
84+
File.Delete(_fileName);
85+
_fileName = null;
86+
}
87+
}
88+
8489
protected override void Act()
8590
{
8691
try

src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ public class ScpClientTest_Upload_FileInfoAndPath_Success : ScpClientTestBase
2525
private int _fileSize;
2626
private IList<ScpUploadEventArgs> _uploadingRegister;
2727

28-
[TestCleanup]
29-
public void Cleanup()
30-
{
31-
if (_fileName != null)
32-
{
33-
File.Delete(_fileName);
34-
_fileName = null;
35-
}
36-
}
37-
3828
protected override void SetupData()
3929
{
4030
var random = new Random();
@@ -95,6 +85,10 @@ protected override void SetupMocks()
9585
_pipeStreamMock.InSequence(sequence).Setup(p => p.ReadByte()).Returns(0);
9686
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
9787
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
88+
89+
// On .NET Core, Dispose() in turn invokes Close() and since we're not mocking
90+
// an interface, we need to expect this call as well
91+
_pipeStreamMock.Setup(p => p.Close());
9892
}
9993

10094
protected override void Arrange()
@@ -109,6 +103,17 @@ protected override void Arrange()
109103
_scpClient.Connect();
110104
}
111105

106+
protected override void TearDown()
107+
{
108+
base.TearDown();
109+
110+
if (_fileName != null)
111+
{
112+
File.Delete(_fileName);
113+
_fileName = null;
114+
}
115+
}
116+
112117
protected override void Act()
113118
{
114119
_scpClient.Upload(_fileInfo, _remotePath);

src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ public class ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse : Sc
2020
private IList<ScpUploadEventArgs> _uploadingRegister;
2121
private SshException _actualException;
2222

23-
[TestCleanup]
24-
public void Cleanup()
25-
{
26-
if (_source != null)
27-
{
28-
_source.Dispose();
29-
}
30-
}
31-
3223
protected override void SetupData()
3324
{
3425
var random = new Random();
@@ -67,6 +58,10 @@ protected override void SetupMocks()
6758
.Returns(false);
6859
_channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
6960
_pipeStreamMock.As<IDisposable>().InSequence(sequence).Setup(p => p.Dispose());
61+
62+
// On .NET Core, Dispose() in turn invokes Close() and since we're not mocking
63+
// an interface, we need to expect this call as well
64+
_pipeStreamMock.Setup(p => p.Close());
7065
}
7166

7267
protected override void Arrange()
@@ -78,6 +73,16 @@ protected override void Arrange()
7873
_scpClient.Connect();
7974
}
8075

76+
protected override void TearDown()
77+
{
78+
base.TearDown();
79+
80+
if (_source != null)
81+
{
82+
_source.Dispose();
83+
}
84+
}
85+
8186
protected override void Act()
8287
{
8388
try

0 commit comments

Comments
 (0)