IntegrationTestBase.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. namespace Renci.SshNet.IntegrationTests.TestsFixtures
  2. {
  3. /// <summary>
  4. /// The base class for integration tests
  5. /// </summary>
  6. public abstract class IntegrationTestBase
  7. {
  8. private readonly InfrastructureFixture _infrastructureFixture;
  9. /// <summary>
  10. /// The SSH Server host name.
  11. /// </summary>
  12. public string SshServerHostName
  13. {
  14. get
  15. {
  16. return _infrastructureFixture.SshServerHostName;
  17. }
  18. }
  19. /// <summary>
  20. /// The SSH Server host name
  21. /// </summary>
  22. public ushort SshServerPort
  23. {
  24. get
  25. {
  26. return _infrastructureFixture.SshServerPort;
  27. }
  28. }
  29. /// <summary>
  30. /// The admin user that can use SSH Server.
  31. /// </summary>
  32. public SshUser AdminUser
  33. {
  34. get
  35. {
  36. return _infrastructureFixture.AdminUser;
  37. }
  38. }
  39. /// <summary>
  40. /// The normal user that can use SSH Server.
  41. /// </summary>
  42. public SshUser User
  43. {
  44. get
  45. {
  46. return _infrastructureFixture.User;
  47. }
  48. }
  49. protected IntegrationTestBase()
  50. {
  51. _infrastructureFixture = InfrastructureFixture.Instance;
  52. ShowInfrastructureInformation();
  53. }
  54. private void ShowInfrastructureInformation()
  55. {
  56. Console.WriteLine($"SSH Server host name: {_infrastructureFixture.SshServerHostName}");
  57. Console.WriteLine($"SSH Server port: {_infrastructureFixture.SshServerPort}");
  58. }
  59. /// <summary>
  60. /// Creates the test file.
  61. /// </summary>
  62. /// <param name="fileName">Name of the file.</param>
  63. /// <param name="size">Size in megabytes.</param>
  64. protected void CreateTestFile(string fileName, int size)
  65. {
  66. using (var testFile = File.Create(fileName))
  67. {
  68. var random = new Random();
  69. for (int i = 0; i < 1024 * size; i++)
  70. {
  71. var buffer = new byte[1024];
  72. random.NextBytes(buffer);
  73. testFile.Write(buffer, 0, buffer.Length);
  74. }
  75. }
  76. }
  77. }
  78. }