From ef92b54e22ce9b1a7ad01f6f3c3c99e2993e8baf Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Mon, 9 Dec 2019 12:36:21 +0100 Subject: [PATCH] Use different names for environment variables --- .../EventFlow.TestHelpers/MsSql/MsSqlHelpz.cs | 43 ++++++++++--------- appveyor.yml | 6 +-- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Source/EventFlow.TestHelpers/MsSql/MsSqlHelpz.cs b/Source/EventFlow.TestHelpers/MsSql/MsSqlHelpz.cs index 156236fc0..a4bc710d8 100644 --- a/Source/EventFlow.TestHelpers/MsSql/MsSqlHelpz.cs +++ b/Source/EventFlow.TestHelpers/MsSql/MsSqlHelpz.cs @@ -22,7 +22,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; -using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; namespace EventFlow.TestHelpers.MsSql { @@ -43,34 +44,36 @@ public static MsSqlConnectionString CreateConnectionString(string label) { var databaseName = $"{label}_{DateTime.Now:yyyy-MM-dd-HH-mm}_{Guid.NewGuid():N}"; - // TODO: Move to connection string builder - - var connectionStringParts = new List + var connectionStringBuilder = new SqlConnectionStringBuilder() { - $"Database={databaseName}" + InitialCatalog = databaseName, + DataSource = FirstNonEmpty( + Environment.GetEnvironmentVariable("EVENTFLOW_MSSQL_SERVER"), + ".") }; - var environmentServer = Environment.GetEnvironmentVariable("HELPZ_MSSQL_SERVER"); - var environmentPassword = Environment.GetEnvironmentVariable("HELPZ_MSSQL_PASS"); - var environmentUsername = Environment.GetEnvironmentVariable("HELPZ_MSSQL_USER"); + var password = Environment.GetEnvironmentVariable("EVENTFLOW_MSSQL_PASS"); + var username = Environment.GetEnvironmentVariable("EVENTFLOW_MSSQL_USER"); - connectionStringParts.Add(string.IsNullOrEmpty(environmentServer) - ? @"Server=." - : $"Server={environmentServer}"); - connectionStringParts.Add(string.IsNullOrEmpty(environmentUsername) - ? @"Integrated Security=True" - : $"User Id={environmentUsername}"); - connectionStringParts.Add("Connection Timeout=60"); - if (!string.IsNullOrEmpty(environmentPassword)) + if (!string.IsNullOrEmpty(username) && + !string.IsNullOrEmpty(password)) + { + connectionStringBuilder.UserID = username; + connectionStringBuilder.Password = password; + } + else { - connectionStringParts.Add($"Password={environmentPassword}"); + connectionStringBuilder.IntegratedSecurity = true; } - var connectionString = string.Join(";", connectionStringParts); + Console.WriteLine($"Using connection string for tests: {connectionStringBuilder.ConnectionString}"); - Console.WriteLine($"Using connection string for tests: {connectionString}"); + return new MsSqlConnectionString(connectionStringBuilder.ConnectionString); + } - return new MsSqlConnectionString(connectionString); + private static string FirstNonEmpty(params string[] parts) + { + return parts.First(s => !string.IsNullOrEmpty(s)); } } } diff --git a/appveyor.yml b/appveyor.yml index d0f7dfb04..a5deebbd5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,9 +15,9 @@ image: Visual Studio 2019 environment: HELPZ_POSTGRESQL_PASS: Password12! - HELPZ_MSSQL_SERVER: (local)\SQL2017 - HELPZ_MSSQL_USER: sa - HELPZ_MSSQL_PASS: Password12! + EVENTFLOW_MSSQL_SERVER: (local)\SQL2017 + EVENTFLOW_MSSQL_USER: sa + EVENTFLOW_MSSQL_PASS: Password12! test: off