2
0

SftpDownloadAsyncResultTest.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using Renci.SshNet.Sftp;
  6. using Renci.SshNet.Tests.Common;
  7. namespace Renci.SshNet.Tests.Classes.Sftp
  8. {
  9. /// <summary>
  10. ///This is a test class for SftpDownloadAsyncResultTest and is intended
  11. ///to contain all SftpDownloadAsyncResultTest Unit Tests
  12. ///</summary>
  13. [TestClass]
  14. public class SftpDownloadAsyncResultTest : TestBase
  15. {
  16. [TestMethod]
  17. public void SftpDownloadAsyncResultConstructorTest()
  18. {
  19. const AsyncCallback asyncCallback = null;
  20. var state = new object();
  21. var target = new SftpDownloadAsyncResult(asyncCallback, state);
  22. Assert.IsFalse(target.CompletedSynchronously);
  23. Assert.IsFalse(target.EndInvokeCalled);
  24. Assert.IsFalse(target.IsCompleted);
  25. Assert.IsFalse(target.IsDownloadCanceled);
  26. Assert.AreEqual(0UL, target.DownloadedBytes);
  27. Assert.AreSame(state, target.AsyncState);
  28. }
  29. [TestMethod]
  30. public void SetAsCompleted_Exception_CompletedSynchronously()
  31. {
  32. var downloadCompleted = new ManualResetEvent(false);
  33. object state = "STATE";
  34. Exception exception = new IOException();
  35. IAsyncResult callbackResult = null;
  36. var target = new SftpDownloadAsyncResult(asyncResult =>
  37. {
  38. downloadCompleted.Set();
  39. callbackResult = asyncResult;
  40. }, state);
  41. target.SetAsCompleted(exception, true);
  42. Assert.AreSame(target, callbackResult);
  43. Assert.IsFalse(target.IsDownloadCanceled);
  44. Assert.IsTrue(target.IsCompleted);
  45. Assert.IsTrue(target.CompletedSynchronously);
  46. Assert.IsTrue(downloadCompleted.WaitOne(TimeSpan.Zero));
  47. }
  48. [TestMethod]
  49. public void EndInvoke_CompletedWithException()
  50. {
  51. object state = "STATE";
  52. Exception exception = new IOException();
  53. var target = new SftpDownloadAsyncResult(null, state);
  54. target.SetAsCompleted(exception, true);
  55. try
  56. {
  57. target.EndInvoke();
  58. Assert.Fail();
  59. }
  60. catch (IOException ex)
  61. {
  62. Assert.AreSame(exception, ex);
  63. }
  64. }
  65. [TestMethod]
  66. public void Update()
  67. {
  68. var target = new SftpDownloadAsyncResult(null, null);
  69. target.Update(123);
  70. target.Update(431);
  71. Assert.AreEqual(431UL, target.DownloadedBytes);
  72. }
  73. }
  74. }