Skip to content

Commit

Permalink
Use different names for environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus Mikkelsen committed Dec 9, 2019
1 parent 60d0652 commit ef92b54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
43 changes: 23 additions & 20 deletions Source/EventFlow.TestHelpers/MsSql/MsSqlHelpz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<string>
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));
}
}
}
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ef92b54

Please sign in to comment.