IntegrationTestBase.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Microsoft.Extensions.Logging;
  2. namespace Renci.SshNet.IntegrationTests.TestsFixtures
  3. {
  4. /// <summary>
  5. /// The base class for integration tests
  6. /// </summary>
  7. public abstract class IntegrationTestBase
  8. {
  9. private readonly InfrastructureFixture _infrastructureFixture;
  10. private readonly ILogger _logger;
  11. /// <summary>
  12. /// The SSH Server host name.
  13. /// </summary>
  14. public string SshServerHostName
  15. {
  16. get
  17. {
  18. return _infrastructureFixture.SshServerHostName;
  19. }
  20. }
  21. /// <summary>
  22. /// The SSH Server host name
  23. /// </summary>
  24. public ushort SshServerPort
  25. {
  26. get
  27. {
  28. return _infrastructureFixture.SshServerPort;
  29. }
  30. }
  31. /// <summary>
  32. /// The admin user that can use SSH Server.
  33. /// </summary>
  34. public SshUser AdminUser
  35. {
  36. get
  37. {
  38. return _infrastructureFixture.AdminUser;
  39. }
  40. }
  41. /// <summary>
  42. /// The normal user that can use SSH Server.
  43. /// </summary>
  44. public SshUser User
  45. {
  46. get
  47. {
  48. return _infrastructureFixture.User;
  49. }
  50. }
  51. protected IntegrationTestBase()
  52. {
  53. _infrastructureFixture = InfrastructureFixture.Instance;
  54. _logger = SshNetLoggingConfiguration.LoggerFactory.CreateLogger(GetType());
  55. _logger.LogDebug("SSH Server: {Host}:{Port}",
  56. _infrastructureFixture.SshServerHostName,
  57. _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. }