ForwardedPortRemoteTest.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Common;
  3. using Renci.SshNet.Tests.Common;
  4. using Renci.SshNet.Tests.Properties;
  5. using System;
  6. using System.Net;
  7. using System.Threading;
  8. namespace Renci.SshNet.Tests.Classes
  9. {
  10. /// <summary>
  11. /// Provides functionality for remote port forwarding
  12. /// </summary>
  13. [TestClass]
  14. public partial class ForwardedPortRemoteTest : TestBase
  15. {
  16. [TestMethod]
  17. [Description("Test passing null to AddForwardedPort hosts (remote).")]
  18. [ExpectedException(typeof(ArgumentNullException))]
  19. [TestCategory("integration")]
  20. public void Test_AddForwardedPort_Remote_Hosts_Are_Null()
  21. {
  22. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  23. {
  24. client.Connect();
  25. var port1 = new ForwardedPortRemote((string)null, 8080, (string)null, 80);
  26. client.AddForwardedPort(port1);
  27. client.Disconnect();
  28. }
  29. }
  30. [TestMethod]
  31. [Description("Test passing invalid port numbers to AddForwardedPort.")]
  32. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  33. [TestCategory("integration")]
  34. public void Test_AddForwardedPort_Invalid_PortNumber()
  35. {
  36. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  37. {
  38. client.Connect();
  39. var port1 = new ForwardedPortRemote("localhost", IPEndPoint.MaxPort + 1, "www.renci.org", IPEndPoint.MaxPort + 1);
  40. client.AddForwardedPort(port1);
  41. client.Disconnect();
  42. }
  43. }
  44. /// <summary>
  45. ///A test for ForwardedPortRemote Constructor
  46. ///</summary>
  47. [TestMethod]
  48. [TestCategory("integration")]
  49. public void Test_ForwardedPortRemote()
  50. {
  51. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  52. {
  53. #region Example SshClient AddForwardedPort Start Stop ForwardedPortRemote
  54. client.Connect();
  55. var port = new ForwardedPortRemote(8082, "www.cnn.com", 80);
  56. client.AddForwardedPort(port);
  57. port.Exception += delegate(object sender, ExceptionEventArgs e)
  58. {
  59. Console.WriteLine(e.Exception.ToString());
  60. };
  61. port.Start();
  62. Thread.Sleep(1000 * 60 * 20); // Wait 20 minutes for port to be forwarded
  63. port.Stop();
  64. #endregion
  65. }
  66. Assert.Inconclusive("TODO: Implement code to verify target");
  67. }
  68. /// <summary>
  69. ///A test for Stop
  70. ///</summary>
  71. [TestMethod]
  72. public void StopTest()
  73. {
  74. uint boundPort = 0; // TODO: Initialize to an appropriate value
  75. string host = string.Empty; // TODO: Initialize to an appropriate value
  76. uint port = 0; // TODO: Initialize to an appropriate value
  77. ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value
  78. target.Stop();
  79. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  80. }
  81. [TestMethod]
  82. public void Start_NotAddedToClient()
  83. {
  84. const int boundPort = 80;
  85. string host = string.Empty;
  86. const uint port = 22;
  87. var target = new ForwardedPortRemote(boundPort, host, port);
  88. try
  89. {
  90. target.Start();
  91. Assert.Fail();
  92. }
  93. catch (InvalidOperationException ex)
  94. {
  95. Assert.IsNull(ex.InnerException);
  96. Assert.AreEqual("Forwarded port is not added to a client.", ex.Message);
  97. }
  98. }
  99. /// <summary>
  100. ///A test for Dispose
  101. ///</summary>
  102. [TestMethod]
  103. public void DisposeTest()
  104. {
  105. uint boundPort = 0; // TODO: Initialize to an appropriate value
  106. string host = string.Empty; // TODO: Initialize to an appropriate value
  107. uint port = 0; // TODO: Initialize to an appropriate value
  108. ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value
  109. target.Dispose();
  110. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  111. }
  112. /// <summary>
  113. ///A test for ForwardedPortRemote Constructor
  114. ///</summary>
  115. [TestMethod]
  116. public void ForwardedPortRemoteConstructorTest()
  117. {
  118. string boundHost = string.Empty; // TODO: Initialize to an appropriate value
  119. uint boundPort = 0; // TODO: Initialize to an appropriate value
  120. string host = string.Empty; // TODO: Initialize to an appropriate value
  121. uint port = 0; // TODO: Initialize to an appropriate value
  122. ForwardedPortRemote target = new ForwardedPortRemote(boundHost, boundPort, host, port);
  123. Assert.Inconclusive("TODO: Implement code to verify target");
  124. }
  125. /// <summary>
  126. ///A test for ForwardedPortRemote Constructor
  127. ///</summary>
  128. [TestMethod]
  129. public void ForwardedPortRemoteConstructorTest1()
  130. {
  131. uint boundPort = 0; // TODO: Initialize to an appropriate value
  132. string host = string.Empty; // TODO: Initialize to an appropriate value
  133. uint port = 0; // TODO: Initialize to an appropriate value
  134. ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port);
  135. Assert.Inconclusive("TODO: Implement code to verify target");
  136. }
  137. }
  138. }