2
0

ForwardedPortRemote.NET40.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.Diagnostics;
  7. using System.Threading;
  8. namespace Renci.SshNet.Tests.SshClientTests
  9. {
  10. /// <summary>
  11. /// Summary description for UnitTest1
  12. /// </summary>
  13. [TestClass]
  14. public partial class ForwardedPortRemoteTest : TestBase
  15. {
  16. [TestMethod]
  17. public void Test_PortForwarding_Remote()
  18. {
  19. // ******************************************************************
  20. // ************* Tests are still in not finished ********************
  21. // ******************************************************************
  22. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  23. {
  24. client.Connect();
  25. var port1 = new ForwardedPortRemote(8082, "www.renci.org", 80);
  26. client.AddForwardedPort(port1);
  27. port1.Exception += delegate(object sender, ExceptionEventArgs e)
  28. {
  29. Assert.Fail(e.Exception.ToString());
  30. };
  31. port1.Start();
  32. var boundport = port1.BoundPort;
  33. System.Threading.Tasks.Parallel.For(0, 5,
  34. //new ParallelOptions
  35. //{
  36. // MaxDegreeOfParallelism = 1,
  37. //},
  38. (counter) =>
  39. {
  40. var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport));
  41. var result = cmd.Execute();
  42. var end = DateTime.Now;
  43. Debug.WriteLine(string.Format("Length: {0}", result.Length));
  44. }
  45. );
  46. Thread.Sleep(1000 * 100);
  47. port1.Stop();
  48. }
  49. }
  50. }
  51. }