Skip to content

Commit bb4e719

Browse files
committed
Added tests for SftpDownloadAsyncResult.
1 parent ae44666 commit bb4e719

File tree

1 file changed

+64
-8
lines changed

1 file changed

+64
-8
lines changed
Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.IO;
3+
using System.Threading;
24
using Microsoft.VisualStudio.TestTools.UnitTesting;
35
using Renci.SshNet.Sftp;
46
using Renci.SshNet.Tests.Common;
@@ -12,17 +14,71 @@ namespace Renci.SshNet.Tests.Classes.Sftp
1214
[TestClass]
1315
public class SftpDownloadAsyncResultTest : TestBase
1416
{
15-
/// <summary>
16-
///A test for SftpDownloadAsyncResult Constructor
17-
///</summary>
1817
[TestMethod]
19-
[Ignore] // placeholder
2018
public void SftpDownloadAsyncResultConstructorTest()
2119
{
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);
2682
}
2783
}
2884
}

0 commit comments

Comments
 (0)