Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ jobs:

- name: Run Integration Tests
run: dotnet test "TransactionProcessorACL.IntegrationTests\TransactionProcessorACL.IntegrationTests.csproj" --filter Category=PRTest

- name: Setup tmate session
if: failure()
uses: mxschmitt/action-tmate@v1
343 changes: 189 additions & 154 deletions TransactionProcessorACL.IntegrationTests/Common/DockerHelper.cs

Large diffs are not rendered by default.

46 changes: 43 additions & 3 deletions TransactionProcessorACL.IntegrationTests/Common/GenericSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace TransactionProcessor.IntegrationTests.Common
{
using System.Threading;
using System.Threading.Tasks;
using global::Shared.Logger;
using NLog;
using TechTalk.SpecFlow;

[Binding]
Expand All @@ -22,17 +25,54 @@ public GenericSteps(ScenarioContext scenarioContext,
this.TestingContext = testingContext;
}

[BeforeScenario()]
[BeforeScenario]
public async Task StartSystem()
{
// Initialise a logger
String scenarioName = this.ScenarioContext.ScenarioInfo.Title.Replace(" ", "");
this.TestingContext.DockerHelper = new DockerHelper();
NlogLogger logger = new NlogLogger();
logger.Initialise(LogManager.GetLogger(scenarioName), scenarioName);
LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly);

this.TestingContext.DockerHelper = new DockerHelper(logger);
this.TestingContext.Logger = logger;
this.TestingContext.Logger.LogInformation("About to Start Containers for Scenario Run");
await this.TestingContext.DockerHelper.StartContainersForScenarioRun(scenarioName).ConfigureAwait(false);
this.TestingContext.Logger.LogInformation("Containers for Scenario Run Started");

Thread.Sleep(20000);
}

[AfterScenario()]
[AfterScenario]
public async Task StopSystem()
{
if (this.ScenarioContext.TestError != null)
{
//Exception currentEx = this.ScenarioContext.TestError;
//Console.Out.WriteLine(currentEx.Message);
//while (currentEx.InnerException != null)
//{
// currentEx = currentEx.InnerException;
// Console.Out.WriteLine(currentEx.Message);
//}

//// The test has failed, grab the logs from all the containers
//List<IContainerService> containers = new List<IContainerService>();
//containers.Add(this.TestingContext.DockerHelper.EstateManagementContainer);
//containers.Add(this.TestingContext.DockerHelper.TransactionProcessorContainer);

//foreach (IContainerService containerService in containers)
//{
// ConsoleStream<String> logStream = containerService.Logs();
// IList<String> logData = logStream.ReadToEnd();

// foreach (String s in logData)
// {
// Console.Out.WriteLine(s);
// }
//}
}

await this.TestingContext.DockerHelper.StopContainersForScenarioRun().ConfigureAwait(false);
}
}
Expand Down
86 changes: 8 additions & 78 deletions TransactionProcessorACL.IntegrationTests/Common/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,93 +25,23 @@ public class Setup
[BeforeTestRun]
protected static void GlobalSetup()
{
ShouldlyConfiguration.DefaultTaskTimeout = TimeSpan.FromMinutes(1);
(String, String, String) dockerCredentials = ("https://www.docker.com", "stuartferguson", "Sc0tland");

// Setup a network for the DB Server
DatabaseServerNetwork = new Builder().UseNetwork($"sharednetwork").ReuseIfExist().Build();
DatabaseServerNetwork = global::Shared.IntegrationTesting.DockerHelper.SetupTestNetwork("sharednetwork", true);

// Start the Database Server here
DbConnectionStringWithNoDatabase = StartMySqlContainerWithOpenConnection();
DbConnectionStringWithNoDatabase = global::Shared.IntegrationTesting.DockerHelper.StartSqlContainerWithOpenConnection("shareddatabasesqlserver",
null,
"stuartferguson/subscriptionservicedatabasesqlserver",
Setup.DatabaseServerNetwork,
"",
dockerCredentials);
}

public static String GetConnectionString(String databaseName)
{
return $"{DbConnectionStringWithNoDatabase} database={databaseName};";
}

private static String StartMySqlContainerWithOpenConnection()
{
String containerName = $"shareddatabasesqlserver";
DatabaseServerContainer = new Ductus.FluentDocker.Builders.Builder()
.UseContainer()
.WithName(containerName)
.WithCredential("https://docker.io", "stuartferguson", "Sc0tland")
.UseImage("stuartferguson/subscriptionservicedatabasesqlserver")
.WithEnvironment("ACCEPT_EULA=Y", $"SA_PASSWORD=thisisalongpassword123!")
.ExposePort(1433)
.UseNetwork(DatabaseServerNetwork)
.KeepContainer()
.KeepRunning()
.ReuseIfExists()
.Build()
.Start()
.WaitForPort("1433/tcp", 30000);

IPEndPoint sqlServerEndpoint = DatabaseServerContainer.ToHostExposedEndpoint("1433/tcp");

// Try opening a connection
Int32 maxRetries = 10;
Int32 counter = 1;

String server = "127.0.0.1";
String database = "SubscriptionServiceConfiguration";
String user = "sa";
String password = "thisisalongpassword123!";
String port = sqlServerEndpoint.Port.ToString();

String connectionString = $"server={server},{port};user id={user}; password={password}; database={database};";

SqlConnection connection = new SqlConnection(connectionString);

using (StreamWriter sw = new StreamWriter("C:\\Temp\\testlog.log", true))
{
while (counter <= maxRetries)
{
try
{
sw.WriteLine($"Attempt {counter}");
sw.WriteLine(DateTime.Now);

connection.Open();

SqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM EventStoreServers";
command.ExecuteNonQuery();

sw.WriteLine("Connection Opened");

connection.Close();

break;
}
catch (SqlException ex)
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}

sw.WriteLine(ex);
Thread.Sleep(20000);
}
finally
{
counter++;
}
}
}

return $"server={containerName};user id={user}; password={password};";
}
}
}
Loading