2
0

IntegrationTestBase.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Diagnostics;
  2. using Renci.SshNet.Abstractions;
  3. namespace Renci.SshNet.IntegrationTests.TestsFixtures
  4. {
  5. /// <summary>
  6. /// The base class for integration tests
  7. /// </summary>
  8. public abstract class IntegrationTestBase
  9. {
  10. private readonly InfrastructureFixture _infrastructureFixture;
  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. ShowInfrastructureInformation();
  55. }
  56. private void ShowInfrastructureInformation()
  57. {
  58. Console.WriteLine($"SSH Server host name: {_infrastructureFixture.SshServerHostName}");
  59. Console.WriteLine($"SSH Server port: {_infrastructureFixture.SshServerPort}");
  60. }
  61. /// <summary>
  62. /// Creates the test file.
  63. /// </summary>
  64. /// <param name="fileName">Name of the file.</param>
  65. /// <param name="size">Size in megabytes.</param>
  66. protected void CreateTestFile(string fileName, int size)
  67. {
  68. using (var testFile = File.Create(fileName))
  69. {
  70. var random = new Random();
  71. for (int i = 0; i < 1024 * size; i++)
  72. {
  73. var buffer = new byte[1024];
  74. random.NextBytes(buffer);
  75. testFile.Write(buffer, 0, buffer.Length);
  76. }
  77. }
  78. }
  79. protected void EnableTracing()
  80. {
  81. DiagnosticAbstraction.Source.Switch = new SourceSwitch("sourceSwitch", nameof(SourceLevels.Verbose));
  82. DiagnosticAbstraction.Source.Listeners.Remove("Default");
  83. DiagnosticAbstraction.Source.Listeners.Add(new ConsoleTraceListener() { Name = "TestConsoleLogger" });
  84. }
  85. protected void DisableTracing()
  86. {
  87. DiagnosticAbstraction.Source.Switch = new SourceSwitch("sourceSwitch", nameof(SourceLevels.Off));
  88. DiagnosticAbstraction.Source.Listeners.Remove("TestConsoleLogger");
  89. }
  90. }
  91. }