1
1
using System ;
2
+ using System . IO ;
3
+ using System . Threading ;
2
4
using Microsoft . VisualStudio . TestTools . UnitTesting ;
3
5
using Renci . SshNet . Sftp ;
4
6
using Renci . SshNet . Tests . Common ;
@@ -12,17 +14,71 @@ namespace Renci.SshNet.Tests.Classes.Sftp
12
14
[ TestClass ]
13
15
public class SftpDownloadAsyncResultTest : TestBase
14
16
{
15
- /// <summary>
16
- ///A test for SftpDownloadAsyncResult Constructor
17
- ///</summary>
18
17
[ TestMethod ]
19
- [ Ignore ] // placeholder
20
18
public void SftpDownloadAsyncResultConstructorTest ( )
21
19
{
22
- AsyncCallback asyncCallback = null ; // TODO: Initialize to an appropriate value
23
- object state = null ; // TODO: Initialize to an appropriate value
24
- SftpDownloadAsyncResult target = new SftpDownloadAsyncResult ( asyncCallback , state ) ;
25
- Assert . Inconclusive ( "TODO: Implement code to verify target" ) ;
20
+ const AsyncCallback asyncCallback = null ;
21
+ var state = new object ( ) ;
22
+ var target = new SftpDownloadAsyncResult ( asyncCallback , state ) ;
23
+
24
+ Assert . IsFalse ( target . CompletedSynchronously ) ;
25
+ Assert . IsFalse ( target . EndInvokeCalled ) ;
26
+ Assert . IsFalse ( target . IsCompleted ) ;
27
+ Assert . IsFalse ( target . IsDownloadCanceled ) ;
28
+ Assert . AreEqual ( 0UL , target . DownloadedBytes ) ;
29
+ Assert . AreSame ( state , target . AsyncState ) ;
30
+ }
31
+
32
+ [ TestMethod ]
33
+ public void SetAsCompleted_Exception_CompletedSynchronously ( )
34
+ {
35
+ var downloadCompleted = new ManualResetEvent ( false ) ;
36
+ object state = "STATE" ;
37
+ Exception exception = new IOException ( ) ;
38
+ IAsyncResult callbackResult = null ;
39
+ var target = new SftpDownloadAsyncResult ( asyncResult =>
40
+ {
41
+ downloadCompleted . Set ( ) ;
42
+ callbackResult = asyncResult ;
43
+ } , state ) ;
44
+
45
+ target . SetAsCompleted ( exception , true ) ;
46
+
47
+ Assert . AreSame ( target , callbackResult ) ;
48
+ Assert . IsFalse ( target . IsDownloadCanceled ) ;
49
+ Assert . IsTrue ( target . IsCompleted ) ;
50
+ Assert . IsTrue ( target . CompletedSynchronously ) ;
51
+ Assert . IsTrue ( downloadCompleted . WaitOne ( TimeSpan . Zero ) ) ;
52
+ }
53
+
54
+ [ TestMethod ]
55
+ public void EndInvoke_CompletedWithException ( )
56
+ {
57
+ object state = "STATE" ;
58
+ Exception exception = new IOException ( ) ;
59
+ var target = new SftpDownloadAsyncResult ( null , state ) ;
60
+ target . SetAsCompleted ( exception , true ) ;
61
+
62
+ try
63
+ {
64
+ target . EndInvoke ( ) ;
65
+ Assert . Fail ( ) ;
66
+ }
67
+ catch ( IOException ex )
68
+ {
69
+ Assert . AreSame ( exception , ex ) ;
70
+ }
71
+ }
72
+
73
+ [ TestMethod ]
74
+ public void Update ( )
75
+ {
76
+ var target = new SftpDownloadAsyncResult ( null , null ) ;
77
+
78
+ target . Update ( 123 ) ;
79
+ target . Update ( 431 ) ;
80
+
81
+ Assert . AreEqual ( 431UL , target . DownloadedBytes ) ;
26
82
}
27
83
}
28
84
}
0 commit comments