瀏覽代碼

Fix more tests to pass on .NET Core.

drieseng 4 年之前
父節點
當前提交
f60f24fb9c

+ 12 - 13
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingRead.cs

@@ -1,18 +1,18 @@
-using System;
+using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
-    public class PipeStream_Close_BlockingRead
+    public class PipeStream_Close_BlockingRead : TripleATestBase
     {
         private PipeStream _pipeStream;
         private int _bytesRead;
-        private IAsyncResult _asyncReadResult;
+        private Thread _readThread;
 
-        [TestInitialize]
-        public void Init()
+        protected override void Arrange()
         {
             _pipeStream = new PipeStream();
 
@@ -22,26 +22,25 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             _bytesRead = 123;
 
-            Action readAction = () => _bytesRead = _pipeStream.Read(new byte[4], 0, 4);
-            _asyncReadResult = readAction.BeginInvoke(null, null);
-            // ensure we've started reading
-            _asyncReadResult.AsyncWaitHandle.WaitOne(50);
+            _readThread = new Thread(() => _bytesRead = _pipeStream.Read(new byte[4], 0, 4));
+            _readThread.Start();
 
-            Act();
+            // ensure we've started reading
+            Assert.IsFalse(_readThread.Join(50));
         }
 
-        protected void Act()
+        protected override void Act()
         {
             _pipeStream.Close();
 
             // give async read time to complete
-            _asyncReadResult.AsyncWaitHandle.WaitOne(100);
+            _readThread.Join(100);
         }
 
         [TestMethod]
         public void BlockingReadShouldHaveBeenInterrupted()
         {
-            Assert.IsTrue(_asyncReadResult.IsCompleted);
+            Assert.AreEqual(ThreadState.Stopped, _readThread.ThreadState);
         }
 
         [TestMethod]

+ 14 - 14
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingWrite.cs

@@ -1,22 +1,23 @@
 using System;
+using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
-    public class PipeStream_Close_BlockingWrite
+    public class PipeStream_Close_BlockingWrite : TripleATestBase
     {
         private PipeStream _pipeStream;
         private Exception _writeException;
-        private IAsyncResult _asyncWriteResult;
+        private Thread _writehread;
 
-        [TestInitialize]
-        public void Init()
+        protected override void Arrange()
         {
             _pipeStream = new PipeStream {MaxBufferLength = 3};
 
-            Action writeAction = () =>
+            _writehread = new Thread(() =>
                 {
                     _pipeStream.WriteByte(10);
                     _pipeStream.WriteByte(13);
@@ -33,26 +34,25 @@ namespace Renci.SshNet.Tests.Classes.Common
                         _writeException = ex;
                         throw;
                     }
-                };
-            _asyncWriteResult = writeAction.BeginInvoke(null, null);
-            // ensure we've started writing
-            _asyncWriteResult.AsyncWaitHandle.WaitOne(50);
+                });
+            _writehread.Start();
 
-            Act();
+            // ensure we've started writing
+            Assert.IsFalse(_writehread.Join(50));
         }
 
-        protected void Act()
+        protected override void Act()
         {
             _pipeStream.Close();
 
-            // give async write time to complete
-            _asyncWriteResult.AsyncWaitHandle.WaitOne(100);
+            // give write time to complete
+            _writehread.Join(100);
         }
 
         [TestMethod]
         public void BlockingWriteShouldHaveBeenInterrupted()
         {
-            Assert.IsTrue(_asyncWriteResult.IsCompleted);
+            Assert.AreEqual(ThreadState.Stopped, _writehread.ThreadState);
         }
 
         [TestMethod]

+ 12 - 13
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_BytesRemainingAfterRead.cs

@@ -1,20 +1,19 @@
-using System;
-using System.Threading;
+using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
-    public class PipeStream_Flush_BytesRemainingAfterRead
+    public class PipeStream_Flush_BytesRemainingAfterRead : TripleATestBase
     {
         private PipeStream _pipeStream;
         private byte[] _readBuffer;
         private int _bytesRead;
-        private IAsyncResult _asyncReadResult;
+        private Thread _readThread;
 
-        [TestInitialize]
-        public void Init()
+        protected override void Arrange()
         {
             _pipeStream = new PipeStream();
             _pipeStream.WriteByte(10);
@@ -27,25 +26,25 @@ namespace Renci.SshNet.Tests.Classes.Common
             _bytesRead = 0;
             _readBuffer = new byte[4];
 
-            Action readAction = () => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length);
-            _asyncReadResult = readAction.BeginInvoke(null, null);
-            _asyncReadResult.AsyncWaitHandle.WaitOne(50);
+            _readThread = new Thread(() => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length));
+            _readThread.Start();
 
-            Act();
+            // ensure we've started reading
+            _readThread.Join(50);
         }
 
-        protected void Act()
+        protected override void Act()
         {
             _pipeStream.Flush();
 
             // give async read time to complete
-            _asyncReadResult.AsyncWaitHandle.WaitOne(100);
+            _readThread.Join(100);
         }
 
         [TestMethod]
         public void AsyncReadShouldHaveFinished()
         {
-            Assert.IsTrue(_asyncReadResult.IsCompleted);
+            Assert.AreEqual(ThreadState.Stopped, _readThread.ThreadState);
         }
 
         [TestMethod]

+ 12 - 12
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_NoBytesRemainingAfterRead.cs

@@ -1,19 +1,19 @@
-using System;
+using System.Threading;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
-    public class PipeStream_Flush_NoBytesRemainingAfterRead
+    public class PipeStream_Flush_NoBytesRemainingAfterRead : TripleATestBase
     {
         private PipeStream _pipeStream;
         private byte[] _readBuffer;
         private int _bytesRead;
-        private IAsyncResult _asyncReadResult;
+        private Thread _readThread;
 
-        [TestInitialize]
-        public void Init()
+        protected override void Arrange()
         {
             _pipeStream = new PipeStream();
             _pipeStream.WriteByte(10);
@@ -22,25 +22,25 @@ namespace Renci.SshNet.Tests.Classes.Common
             _bytesRead = 0;
             _readBuffer = new byte[4];
 
-            Action readAction = () => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length);
-            _asyncReadResult = readAction.BeginInvoke(null, null);
-            _asyncReadResult.AsyncWaitHandle.WaitOne(50);
+            _readThread = new Thread(() => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length));
+            _readThread.Start();
 
-            Act();
+            // ensure we've started reading
+            Assert.IsFalse(_readThread.Join(50));
         }
 
-        protected void Act()
+        protected override void Act()
         {
             _pipeStream.Flush();
 
             // give async read time to complete
-            _asyncReadResult.AsyncWaitHandle.WaitOne(100);
+            _readThread.Join(100);
         }
 
         [TestMethod]
         public void AsyncReadShouldHaveFinished()
         {
-            Assert.IsTrue(_asyncReadResult.IsCompleted);
+            Assert.AreEqual(ThreadState.Stopped, _readThread.ThreadState);
         }
 
         [TestMethod]