ForwardedPortRemote.NET40.cs 1.9 KB

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