浏览代码

Fix some test failures on .NET Core.

drieseng 4 年之前
父节点
当前提交
a5148aea1a

+ 4 - 0
src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndDirectoryInfo_SendExecRequestReturnsFalse.cs

@@ -55,6 +55,10 @@ namespace Renci.SshNet.Tests.Classes
                                .Returns(false);
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _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());
         }
 
         protected override void Arrange()

+ 4 - 0
src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndFileInfo_SendExecRequestReturnsFalse.cs

@@ -54,6 +54,10 @@ namespace Renci.SshNet.Tests.Classes
                 .Setup(p => p.SendExecRequest(string.Format("scp -pf {0}", _transformedPath))).Returns(false);
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _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());
         }
 
         protected override void Arrange()

+ 14 - 9
src/Renci.SshNet.Tests/Classes/ScpClientTest_Download_PathAndStream_SendExecRequestReturnsFalse.cs

@@ -19,15 +19,6 @@ namespace Renci.SshNet.Tests.Classes
         private IList<ScpUploadEventArgs> _uploadingRegister;
         private SshException _actualException;
 
-        [TestCleanup]
-        public void Cleanup()
-        {
-            if (_destination != null)
-            {
-                _destination.Dispose();
-            }
-        }
-
         protected override void SetupData()
         {
             var random = new Random();
@@ -64,6 +55,10 @@ namespace Renci.SshNet.Tests.Classes
                                .Returns(false);
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _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());
         }
 
         protected override void Arrange()
@@ -75,6 +70,16 @@ namespace Renci.SshNet.Tests.Classes
             _scpClient.Connect();
         }
 
+        protected override void TearDown()
+        {
+            base.TearDown();
+
+            if (_destination != null)
+            {
+                _destination.Dispose();
+            }
+        }
+
         protected override void Act()
         {
             try

+ 4 - 0
src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_DirectoryInfoAndPath_SendExecRequestReturnsFalse.cs

@@ -54,6 +54,10 @@ namespace Renci.SshNet.Tests.Classes
                                .Returns(false);
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _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());
         }
 
         protected override void Arrange()

+ 16 - 11
src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs

@@ -21,16 +21,6 @@ namespace Renci.SshNet.Tests.Classes
         private IList<ScpUploadEventArgs> _uploadingRegister;
         private SshException _actualException;
 
-        [TestCleanup]
-        public void Cleanup()
-        {
-            if (_fileName != null)
-            {
-                File.Delete(_fileName);
-                _fileName = null;
-            }
-        }
-
         protected override void SetupData()
         {
             var random = new Random();
@@ -70,7 +60,11 @@ namespace Renci.SshNet.Tests.Classes
                                .Returns(false);
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _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());
+}
 
         protected override void Arrange()
         {
@@ -81,6 +75,17 @@ namespace Renci.SshNet.Tests.Classes
             _scpClient.Connect();
         }
 
+        protected override void TearDown()
+        {
+            base.TearDown();
+
+            if (_fileName != null)
+            {
+                File.Delete(_fileName);
+                _fileName = null;
+            }
+        }
+
         protected override void Act()
         {
             try

+ 15 - 10
src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_FileInfoAndPath_Success.cs

@@ -25,16 +25,6 @@ namespace Renci.SshNet.Tests.Classes
         private int _fileSize;
         private IList<ScpUploadEventArgs> _uploadingRegister;
 
-        [TestCleanup]
-        public void Cleanup()
-        {
-            if (_fileName != null)
-            {
-                File.Delete(_fileName);
-                _fileName = null;
-            }
-        }
-
         protected override void SetupData()
         {
             var random = new Random();
@@ -95,6 +85,10 @@ namespace Renci.SshNet.Tests.Classes
             _pipeStreamMock.InSequence(sequence).Setup(p => p.ReadByte()).Returns(0);
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _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());
         }
 
         protected override void Arrange()
@@ -109,6 +103,17 @@ namespace Renci.SshNet.Tests.Classes
             _scpClient.Connect();
         }
 
+        protected override void TearDown()
+        {
+            base.TearDown();
+
+            if (_fileName != null)
+            {
+                File.Delete(_fileName);
+                _fileName = null;
+            }
+        }
+
         protected override void Act()
         {
             _scpClient.Upload(_fileInfo, _remotePath);

+ 14 - 9
src/Renci.SshNet.Tests/Classes/ScpClientTest_Upload_StreamAndPath_SendExecRequestReturnsFalse.cs

@@ -20,15 +20,6 @@ namespace Renci.SshNet.Tests.Classes
         private IList<ScpUploadEventArgs> _uploadingRegister;
         private SshException _actualException;
 
-        [TestCleanup]
-        public void Cleanup()
-        {
-            if (_source != null)
-            {
-                _source.Dispose();
-            }
-        }
-
         protected override void SetupData()
         {
             var random = new Random();
@@ -67,6 +58,10 @@ namespace Renci.SshNet.Tests.Classes
                                .Returns(false);
             _channelSessionMock.InSequence(sequence).Setup(p => p.Dispose());
             _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());
         }
 
         protected override void Arrange()
@@ -78,6 +73,16 @@ namespace Renci.SshNet.Tests.Classes
             _scpClient.Connect();
         }
 
+        protected override void TearDown()
+        {
+            base.TearDown();
+
+            if (_source != null)
+            {
+                _source.Dispose();
+            }
+        }
+
         protected override void Act()
         {
             try