11namespace FileProcessor . IntegrationTests . Common
22{
33 using System ;
4+ using System . Data ;
5+ using System . Data . SqlClient ;
6+ using System . Net ;
7+ using System . Threading ;
8+ using Ductus . FluentDocker . Builders ;
49 using Ductus . FluentDocker . Services ;
510 using Ductus . FluentDocker . Services . Extensions ;
11+ using Microsoft . Extensions . Logging ;
612 using NLog ;
713 using Shared . Logger ;
814 using Shouldly ;
915 using TechTalk . SpecFlow ;
16+ using ILogger = Microsoft . Extensions . Logging . ILogger ;
1017
1118 [ Binding ]
1219 public class Setup
@@ -20,6 +27,78 @@ public class Setup
2027 public const String SqlUserName = "sa" ;
2128
2229 public const String SqlPassword = "thisisalongpassword123!" ;
30+
31+ //public static IContainerService StartSqlContainerWithOpenConnection(String containerName,
32+ // ILogger logger,
33+ // String imageName,
34+ // INetworkService networkService,
35+ // String hostFolder,
36+ // (String URL, String UserName, String Password)? dockerCredentials,
37+ // String sqlUserName = "sa",
38+ // String sqlPassword = "thisisalongpassword123!")
39+ //{
40+ // //logger.LogInformation("About to start SQL Server Container");
41+ // IContainerService databaseServerContainer = new Builder().UseContainer().WithName(containerName).UseImage(imageName)
42+ // .WithEnvironment("ACCEPT_EULA=Y", $"SA_PASSWORD={sqlPassword}").ExposePort(1433)
43+ // .UseNetwork(networkService).KeepContainer().KeepRunning().ReuseIfExists().Build().Start()
44+ // .WaitForPort("1433/tcp", 30000);
45+
46+ // //logger.LogInformation("SQL Server Container Started");
47+
48+ // //logger.LogInformation("About to SQL Server Container is running");
49+ // IPEndPoint sqlServerEndpoint = databaseServerContainer.ToHostExposedEndpoint("1433/tcp");
50+
51+ // // Try opening a connection
52+ // Int32 maxRetries = 10;
53+ // Int32 counter = 1;
54+
55+ // String server = "127.0.0.1";
56+ // String database = "master";
57+ // String user = sqlUserName;
58+ // String password = sqlPassword;
59+ // String port = sqlServerEndpoint.Port.ToString();
60+
61+ // String connectionString = $"server={server},{port};user id={user}; password={password}; database={database};";
62+ // //logger.LogInformation($"Connection String {connectionString}");
63+ // SqlConnection connection = new SqlConnection(connectionString);
64+
65+ // while (counter <= maxRetries)
66+ // {
67+ // try
68+ // {
69+ // //logger.LogInformation($"Database Connection Attempt {counter}");
70+
71+ // connection.Open();
72+
73+ // SqlCommand command = connection.CreateCommand();
74+ // command.CommandText = "SELECT * FROM sys.databases";
75+ // command.ExecuteNonQuery();
76+
77+ // //logger.LogInformation("Connection Opened");
78+
79+ // connection.Close();
80+ // //logger.LogInformation("SQL Server Container Running");
81+ // break;
82+ // }
83+ // catch (SqlException ex)
84+ // {
85+ // if (connection.State == ConnectionState.Open)
86+ // {
87+ // connection.Close();
88+ // }
89+
90+ // //logger.LogError(ex);
91+ // Thread.Sleep(20000);
92+ // }
93+ // finally
94+ // {
95+ // counter++;
96+ // }
97+ // }
98+
99+ // return databaseServerContainer;
100+ //}
101+
23102 [ BeforeTestRun ]
24103 protected static void GlobalSetup ( )
25104 {
@@ -35,7 +114,7 @@ protected static void GlobalSetup()
35114 LogManager . AddHiddenAssembly ( typeof ( NlogLogger ) . Assembly ) ;
36115
37116 // Start the Database Server here
38- Setup . DatabaseServerContainer = global :: Shared . IntegrationTesting . DockerHelper . StartSqlContainerWithOpenConnection ( Setup . SqlServerContainerName ,
117+ Setup . DatabaseServerContainer = Shared . IntegrationTesting . DockerHelper . StartSqlContainerWithOpenConnection ( Setup . SqlServerContainerName ,
39118 logger ,
40119 "mcr.microsoft.com/mssql/server:2019-latest" ,
41120 Setup . DatabaseServerNetwork ,
0 commit comments