using System.Diagnostics;
using Renci.SshNet.Abstractions;
namespace Renci.SshNet.IntegrationTests.TestsFixtures
{
///
/// The base class for integration tests
///
public abstract class IntegrationTestBase
{
private readonly InfrastructureFixture _infrastructureFixture;
///
/// The SSH Server host name.
///
public string SshServerHostName
{
get
{
return _infrastructureFixture.SshServerHostName;
}
}
///
/// The SSH Server host name
///
public ushort SshServerPort
{
get
{
return _infrastructureFixture.SshServerPort;
}
}
///
/// The admin user that can use SSH Server.
///
public SshUser AdminUser
{
get
{
return _infrastructureFixture.AdminUser;
}
}
///
/// The normal user that can use SSH Server.
///
public SshUser User
{
get
{
return _infrastructureFixture.User;
}
}
protected IntegrationTestBase()
{
_infrastructureFixture = InfrastructureFixture.Instance;
ShowInfrastructureInformation();
}
private void ShowInfrastructureInformation()
{
Console.WriteLine($"SSH Server host name: {_infrastructureFixture.SshServerHostName}");
Console.WriteLine($"SSH Server port: {_infrastructureFixture.SshServerPort}");
}
///
/// Creates the test file.
///
/// Name of the file.
/// Size in megabytes.
protected void CreateTestFile(string fileName, int size)
{
using (var testFile = File.Create(fileName))
{
var random = new Random();
for (int i = 0; i < 1024 * size; i++)
{
var buffer = new byte[1024];
random.NextBytes(buffer);
testFile.Write(buffer, 0, buffer.Length);
}
}
}
protected void EnableTracing()
{
DiagnosticAbstraction.Source.Switch = new SourceSwitch("sourceSwitch", nameof(SourceLevels.Verbose));
DiagnosticAbstraction.Source.Listeners.Remove("Default");
DiagnosticAbstraction.Source.Listeners.Add(new ConsoleTraceListener() { Name = "TestConsoleLogger" });
}
protected void DisableTracing()
{
DiagnosticAbstraction.Source.Switch = new SourceSwitch("sourceSwitch", nameof(SourceLevels.Off));
DiagnosticAbstraction.Source.Listeners.Remove("TestConsoleLogger");
}
}
}