Skip to content

Commit f60f24f

Browse files
committed
Fix more tests to pass on .NET Core.
1 parent a5148ae commit f60f24f

File tree

4 files changed

+50
-52
lines changed

4 files changed

+50
-52
lines changed

src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingRead.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using System;
1+
using System.Threading;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using Renci.SshNet.Common;
4+
using Renci.SshNet.Tests.Common;
45

56
namespace Renci.SshNet.Tests.Classes.Common
67
{
78
[TestClass]
8-
public class PipeStream_Close_BlockingRead
9+
public class PipeStream_Close_BlockingRead : TripleATestBase
910
{
1011
private PipeStream _pipeStream;
1112
private int _bytesRead;
12-
private IAsyncResult _asyncReadResult;
13+
private Thread _readThread;
1314

14-
[TestInitialize]
15-
public void Init()
15+
protected override void Arrange()
1616
{
1717
_pipeStream = new PipeStream();
1818

@@ -22,26 +22,25 @@ public void Init()
2222

2323
_bytesRead = 123;
2424

25-
Action readAction = () => _bytesRead = _pipeStream.Read(new byte[4], 0, 4);
26-
_asyncReadResult = readAction.BeginInvoke(null, null);
27-
// ensure we've started reading
28-
_asyncReadResult.AsyncWaitHandle.WaitOne(50);
25+
_readThread = new Thread(() => _bytesRead = _pipeStream.Read(new byte[4], 0, 4));
26+
_readThread.Start();
2927

30-
Act();
28+
// ensure we've started reading
29+
Assert.IsFalse(_readThread.Join(50));
3130
}
3231

33-
protected void Act()
32+
protected override void Act()
3433
{
3534
_pipeStream.Close();
3635

3736
// give async read time to complete
38-
_asyncReadResult.AsyncWaitHandle.WaitOne(100);
37+
_readThread.Join(100);
3938
}
4039

4140
[TestMethod]
4241
public void BlockingReadShouldHaveBeenInterrupted()
4342
{
44-
Assert.IsTrue(_asyncReadResult.IsCompleted);
43+
Assert.AreEqual(ThreadState.Stopped, _readThread.ThreadState);
4544
}
4645

4746
[TestMethod]

src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingWrite.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
using System;
2+
using System.Threading;
23
using Microsoft.VisualStudio.TestTools.UnitTesting;
34
using Renci.SshNet.Common;
5+
using Renci.SshNet.Tests.Common;
46

57
namespace Renci.SshNet.Tests.Classes.Common
68
{
79
[TestClass]
8-
public class PipeStream_Close_BlockingWrite
10+
public class PipeStream_Close_BlockingWrite : TripleATestBase
911
{
1012
private PipeStream _pipeStream;
1113
private Exception _writeException;
12-
private IAsyncResult _asyncWriteResult;
14+
private Thread _writehread;
1315

14-
[TestInitialize]
15-
public void Init()
16+
protected override void Arrange()
1617
{
1718
_pipeStream = new PipeStream {MaxBufferLength = 3};
1819

19-
Action writeAction = () =>
20+
_writehread = new Thread(() =>
2021
{
2122
_pipeStream.WriteByte(10);
2223
_pipeStream.WriteByte(13);
@@ -33,26 +34,25 @@ public void Init()
3334
_writeException = ex;
3435
throw;
3536
}
36-
};
37-
_asyncWriteResult = writeAction.BeginInvoke(null, null);
38-
// ensure we've started writing
39-
_asyncWriteResult.AsyncWaitHandle.WaitOne(50);
37+
});
38+
_writehread.Start();
4039

41-
Act();
40+
// ensure we've started writing
41+
Assert.IsFalse(_writehread.Join(50));
4242
}
4343

44-
protected void Act()
44+
protected override void Act()
4545
{
4646
_pipeStream.Close();
4747

48-
// give async write time to complete
49-
_asyncWriteResult.AsyncWaitHandle.WaitOne(100);
48+
// give write time to complete
49+
_writehread.Join(100);
5050
}
5151

5252
[TestMethod]
5353
public void BlockingWriteShouldHaveBeenInterrupted()
5454
{
55-
Assert.IsTrue(_asyncWriteResult.IsCompleted);
55+
Assert.AreEqual(ThreadState.Stopped, _writehread.ThreadState);
5656
}
5757

5858
[TestMethod]

src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_BytesRemainingAfterRead.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
using System;
2-
using System.Threading;
1+
using System.Threading;
32
using Microsoft.VisualStudio.TestTools.UnitTesting;
43
using Renci.SshNet.Common;
4+
using Renci.SshNet.Tests.Common;
55

66
namespace Renci.SshNet.Tests.Classes.Common
77
{
88
[TestClass]
9-
public class PipeStream_Flush_BytesRemainingAfterRead
9+
public class PipeStream_Flush_BytesRemainingAfterRead : TripleATestBase
1010
{
1111
private PipeStream _pipeStream;
1212
private byte[] _readBuffer;
1313
private int _bytesRead;
14-
private IAsyncResult _asyncReadResult;
14+
private Thread _readThread;
1515

16-
[TestInitialize]
17-
public void Init()
16+
protected override void Arrange()
1817
{
1918
_pipeStream = new PipeStream();
2019
_pipeStream.WriteByte(10);
@@ -27,25 +26,25 @@ public void Init()
2726
_bytesRead = 0;
2827
_readBuffer = new byte[4];
2928

30-
Action readAction = () => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length);
31-
_asyncReadResult = readAction.BeginInvoke(null, null);
32-
_asyncReadResult.AsyncWaitHandle.WaitOne(50);
29+
_readThread = new Thread(() => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length));
30+
_readThread.Start();
3331

34-
Act();
32+
// ensure we've started reading
33+
_readThread.Join(50);
3534
}
3635

37-
protected void Act()
36+
protected override void Act()
3837
{
3938
_pipeStream.Flush();
4039

4140
// give async read time to complete
42-
_asyncReadResult.AsyncWaitHandle.WaitOne(100);
41+
_readThread.Join(100);
4342
}
4443

4544
[TestMethod]
4645
public void AsyncReadShouldHaveFinished()
4746
{
48-
Assert.IsTrue(_asyncReadResult.IsCompleted);
47+
Assert.AreEqual(ThreadState.Stopped, _readThread.ThreadState);
4948
}
5049

5150
[TestMethod]

src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_NoBytesRemainingAfterRead.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
using System;
1+
using System.Threading;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using Renci.SshNet.Common;
4+
using Renci.SshNet.Tests.Common;
45

56
namespace Renci.SshNet.Tests.Classes.Common
67
{
78
[TestClass]
8-
public class PipeStream_Flush_NoBytesRemainingAfterRead
9+
public class PipeStream_Flush_NoBytesRemainingAfterRead : TripleATestBase
910
{
1011
private PipeStream _pipeStream;
1112
private byte[] _readBuffer;
1213
private int _bytesRead;
13-
private IAsyncResult _asyncReadResult;
14+
private Thread _readThread;
1415

15-
[TestInitialize]
16-
public void Init()
16+
protected override void Arrange()
1717
{
1818
_pipeStream = new PipeStream();
1919
_pipeStream.WriteByte(10);
@@ -22,25 +22,25 @@ public void Init()
2222
_bytesRead = 0;
2323
_readBuffer = new byte[4];
2424

25-
Action readAction = () => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length);
26-
_asyncReadResult = readAction.BeginInvoke(null, null);
27-
_asyncReadResult.AsyncWaitHandle.WaitOne(50);
25+
_readThread = new Thread(() => _bytesRead = _pipeStream.Read(_readBuffer, 0, _readBuffer.Length));
26+
_readThread.Start();
2827

29-
Act();
28+
// ensure we've started reading
29+
Assert.IsFalse(_readThread.Join(50));
3030
}
3131

32-
protected void Act()
32+
protected override void Act()
3333
{
3434
_pipeStream.Flush();
3535

3636
// give async read time to complete
37-
_asyncReadResult.AsyncWaitHandle.WaitOne(100);
37+
_readThread.Join(100);
3838
}
3939

4040
[TestMethod]
4141
public void AsyncReadShouldHaveFinished()
4242
{
43-
Assert.IsTrue(_asyncReadResult.IsCompleted);
43+
Assert.AreEqual(ThreadState.Stopped, _readThread.ThreadState);
4444
}
4545

4646
[TestMethod]

0 commit comments

Comments
 (0)