Socks5ConnectorTestBase.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Moq;
  2. using Renci.SshNet.Connection;
  3. using Renci.SshNet.Tests.Common;
  4. using System;
  5. using System.Net;
  6. using System.Text;
  7. namespace Renci.SshNet.Tests.Classes.Connection
  8. {
  9. public abstract class Socks5ConnectorTestBase : TripleATestBase
  10. {
  11. internal Mock<ISocketFactory> SocketFactoryMock { get; private set; }
  12. internal Socks5Connector Connector { get; private set; }
  13. internal SocketFactory SocketFactory { get; private set; }
  14. protected virtual void CreateMocks()
  15. {
  16. SocketFactoryMock = new Mock<ISocketFactory>(MockBehavior.Strict);
  17. }
  18. protected virtual void SetupData()
  19. {
  20. Connector = new Socks5Connector(SocketFactoryMock.Object);
  21. SocketFactory = new SocketFactory();
  22. }
  23. protected virtual void SetupMocks()
  24. {
  25. }
  26. protected sealed override void Arrange()
  27. {
  28. CreateMocks();
  29. SetupData();
  30. SetupMocks();
  31. }
  32. protected ConnectionInfo CreateConnectionInfo(string proxyUser, string proxyPassword)
  33. {
  34. return new ConnectionInfo(IPAddress.Loopback.ToString(),
  35. 1029,
  36. "user",
  37. ProxyTypes.Socks5,
  38. IPAddress.Loopback.ToString(),
  39. 8122,
  40. proxyUser,
  41. proxyPassword,
  42. new KeyboardInteractiveAuthenticationMethod("user"));
  43. }
  44. protected static string GenerateRandomString(int minLength, int maxLength)
  45. {
  46. var random = new Random();
  47. var length = random.Next(minLength, maxLength);
  48. var sb = new StringBuilder(length);
  49. int offset = 'a';
  50. for (var i = 0; i < length; i++)
  51. {
  52. var c = (char) random.Next(offset, offset + 26);
  53. _ = sb.Append(c);
  54. }
  55. return sb.ToString();
  56. }
  57. }
  58. }