@@ -17,22 +17,25 @@ public void Init()
17
17
_pipeStream = new PipeStream { MaxBufferLength = 3 } ;
18
18
19
19
Action writeAction = ( ) =>
20
- {
21
- _pipeStream . WriteByte ( 10 ) ;
22
- _pipeStream . WriteByte ( 13 ) ;
23
- _pipeStream . WriteByte ( 25 ) ;
24
-
25
- try
26
- {
27
- _pipeStream . WriteByte ( 35 ) ;
28
- }
29
- catch ( Exception ex )
30
20
{
31
- _writeException = ex ;
32
- throw ;
33
- }
34
- } ;
21
+ _pipeStream . WriteByte ( 10 ) ;
22
+ _pipeStream . WriteByte ( 13 ) ;
23
+ _pipeStream . WriteByte ( 25 ) ;
24
+
25
+ // attempting to write more bytes than the max. buffer length should block
26
+ // until bytes are read or the stream is closed
27
+ try
28
+ {
29
+ _pipeStream . WriteByte ( 35 ) ;
30
+ }
31
+ catch ( Exception ex )
32
+ {
33
+ _writeException = ex ;
34
+ throw ;
35
+ }
36
+ } ;
35
37
_asyncWriteResult = writeAction . BeginInvoke ( null , null ) ;
38
+ // ensure we've started writing
36
39
_asyncWriteResult . AsyncWaitHandle . WaitOne ( 50 ) ;
37
40
38
41
Act ( ) ;
@@ -44,14 +47,16 @@ protected void Act()
44
47
}
45
48
46
49
[ TestMethod ]
47
- public void AsyncWriteShouldHaveFinished ( )
50
+ public void BlockingWriteShouldHaveBeenInterrupted ( )
48
51
{
49
- Assert . IsTrue ( _asyncWriteResult . IsCompleted ) ;
52
+ Assert . IsTrue ( _asyncWriteResult . AsyncWaitHandle . WaitOne ( 200 ) ) ;
50
53
}
51
54
52
55
[ TestMethod ]
53
- public void WriteThatExceedsMaxBufferLengthShouldHaveThrownObjectDisposedException ( )
56
+ public void WriteShouldHaveThrownObjectDisposedException ( )
54
57
{
58
+ _asyncWriteResult . AsyncWaitHandle . WaitOne ( 200 ) ;
59
+
55
60
Assert . IsNotNull ( _writeException ) ;
56
61
Assert . AreEqual ( typeof ( ObjectDisposedException ) , _writeException . GetType ( ) ) ;
57
62
}
0 commit comments