private void InsertSampleData(string databaseServerContainerName) { // Setup user, database var dbSetupSql = "/tmp/databaseSetup.sql"; var databaseSetupScript = new ShellScriptBuilder() .AddCommand($"echo \"USE {Constants.DatabaseName};\" > {dbSetupSql}") .AddCommand($"echo \"CREATE TABLE Products (Name varchar(50) NOT NULL);\" >> {dbSetupSql}") .AddCommand($"echo \"INSERT INTO Products VALUES('Car');\" >> {dbSetupSql}") .AddCommand($"echo \"INSERT INTO Products VALUES('Television');\" >> {dbSetupSql}") .AddCommand($"echo \"INSERT INTO Products VALUES('Table');\" >> {dbSetupSql}") .AddCommand($"mysql -u {Constants.DatabaseUserName} -p{Constants.DatabaseUserPwd} < {dbSetupSql}") .ToString(); var setupDatabaseResult = _dockerCli.Exec( databaseServerContainerName, "/bin/sh", new[] { "-c", databaseSetupScript }); RunAsserts( () => { Assert.True(setupDatabaseResult.IsSuccess); }, setupDatabaseResult.GetDebugInfo()); }
private void InsertSampleData(string databaseServerContainerName) { // Setup user, database var dbSetupSql = "/tmp/databaseSetup.sql"; var databaseSetupScript = new ShellScriptBuilder() .AddCommand($"echo \"CREATE DATABASE {Constants.DatabaseName};\" >> {dbSetupSql}") .AddCommand($"echo GO >> {dbSetupSql}") .AddCommand($"echo \"Use {Constants.DatabaseName};\" >> {dbSetupSql}") .AddCommand($"echo GO >> {dbSetupSql}") .AddCommand($"echo \"CREATE TABLE Products (Name nvarchar(50));\" >> {dbSetupSql}") .AddCommand($"echo GO >> {dbSetupSql}") .AddCommand($"echo \"INSERT INTO Products VALUES ('Car');\" >> {dbSetupSql}") .AddCommand($"echo \"INSERT INTO Products VALUES ('Television');\" >> {dbSetupSql}") .AddCommand($"echo \"INSERT INTO Products VALUES ('Table');\" >> {dbSetupSql}") .AddCommand($"echo GO >> {dbSetupSql}") .AddCommand($"/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P {Constants.DatabaseUserPwd} -i {dbSetupSql}") .ToString(); DockerCommandResult setupDatabaseResult; var maxRetries = 10; do { // Wait for the database server to be up Thread.Sleep(TimeSpan.FromSeconds(30)); setupDatabaseResult = _dockerCli.Exec( databaseServerContainerName, "/bin/sh", new[] { "-c", databaseSetupScript }); maxRetries--; } while (maxRetries > 0 && setupDatabaseResult.IsSuccess == false); if (setupDatabaseResult.IsSuccess == false) { Console.WriteLine(setupDatabaseResult.GetDebugInfo()); throw new Exception("Couldn't setup MS SQL Server on time"); } }