ForwardedPortRemoteTest.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. public void Test_AddForwardedPort_Remote_Hosts_Are_Null()
  20. {
  21. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  22. {
  23. client.Connect();
  24. var port1 = new ForwardedPortRemote((string)null, 8080, (string)null, 80);
  25. client.AddForwardedPort(port1);
  26. client.Disconnect();
  27. }
  28. }
  29. [TestMethod]
  30. [Description("Test passing invalid port numbers to AddForwardedPort.")]
  31. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  32. public void Test_AddForwardedPort_Invalid_PortNumber()
  33. {
  34. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  35. {
  36. client.Connect();
  37. var port1 = new ForwardedPortRemote("localhost", IPEndPoint.MaxPort + 1, "www.renci.org", IPEndPoint.MaxPort + 1);
  38. client.AddForwardedPort(port1);
  39. client.Disconnect();
  40. }
  41. }
  42. /// <summary>
  43. ///A test for ForwardedPortRemote Constructor
  44. ///</summary>
  45. [TestMethod()]
  46. public void Test_ForwardedPortRemote()
  47. {
  48. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  49. {
  50. #region Example SshClient AddForwardedPort Start Stop ForwardedPortRemote
  51. client.Connect();
  52. var port = new ForwardedPortRemote(8082, "www.cnn.com", 80);
  53. client.AddForwardedPort(port);
  54. port.Exception += delegate(object sender, ExceptionEventArgs e)
  55. {
  56. Console.WriteLine(e.Exception.ToString());
  57. };
  58. port.Start();
  59. Thread.Sleep(1000 * 60 * 20); // Wait 20 minutes for port to be forwarded
  60. port.Stop();
  61. #endregion
  62. }
  63. Assert.Inconclusive("TODO: Implement code to verify target");
  64. }
  65. /// <summary>
  66. ///A test for Stop
  67. ///</summary>
  68. [TestMethod()]
  69. public void StopTest()
  70. {
  71. uint boundPort = 0; // TODO: Initialize to an appropriate value
  72. string host = string.Empty; // TODO: Initialize to an appropriate value
  73. uint port = 0; // TODO: Initialize to an appropriate value
  74. ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value
  75. target.Stop();
  76. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  77. }
  78. /// <summary>
  79. ///A test for Start
  80. ///</summary>
  81. [TestMethod()]
  82. public void StartTest()
  83. {
  84. uint boundPort = 0; // TODO: Initialize to an appropriate value
  85. string host = string.Empty; // TODO: Initialize to an appropriate value
  86. uint port = 0; // TODO: Initialize to an appropriate value
  87. ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value
  88. target.Start();
  89. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  90. }
  91. /// <summary>
  92. ///A test for Dispose
  93. ///</summary>
  94. [TestMethod()]
  95. public void DisposeTest()
  96. {
  97. uint boundPort = 0; // TODO: Initialize to an appropriate value
  98. string host = string.Empty; // TODO: Initialize to an appropriate value
  99. uint port = 0; // TODO: Initialize to an appropriate value
  100. ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value
  101. target.Dispose();
  102. Assert.Inconclusive("A method that does not return a value cannot be verified.");
  103. }
  104. /// <summary>
  105. ///A test for ForwardedPortRemote Constructor
  106. ///</summary>
  107. [TestMethod()]
  108. public void ForwardedPortRemoteConstructorTest()
  109. {
  110. string boundHost = string.Empty; // TODO: Initialize to an appropriate value
  111. uint boundPort = 0; // TODO: Initialize to an appropriate value
  112. string host = string.Empty; // TODO: Initialize to an appropriate value
  113. uint port = 0; // TODO: Initialize to an appropriate value
  114. ForwardedPortRemote target = new ForwardedPortRemote(boundHost, boundPort, host, port);
  115. Assert.Inconclusive("TODO: Implement code to verify target");
  116. }
  117. /// <summary>
  118. ///A test for ForwardedPortRemote Constructor
  119. ///</summary>
  120. [TestMethod()]
  121. public void ForwardedPortRemoteConstructorTest1()
  122. {
  123. uint boundPort = 0; // TODO: Initialize to an appropriate value
  124. string host = string.Empty; // TODO: Initialize to an appropriate value
  125. uint port = 0; // TODO: Initialize to an appropriate value
  126. ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port);
  127. Assert.Inconclusive("TODO: Implement code to verify target");
  128. }
  129. }
  130. }