2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-12-12 11:33:57 +00:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Testing
|
2020-12-12 11:33:57 +00:00
|
|
|
{
|
|
|
|
|
public class TestDbMeta
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; }
|
|
|
|
|
|
|
|
|
|
public bool IsEmpty { get; }
|
|
|
|
|
|
|
|
|
|
public string ConnectionString { get; set; }
|
|
|
|
|
|
|
|
|
|
private TestDbMeta(string name, bool isEmpty, string connectionString)
|
|
|
|
|
{
|
|
|
|
|
IsEmpty = isEmpty;
|
|
|
|
|
Name = name;
|
|
|
|
|
ConnectionString = connectionString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string ConstructConnectionString(string masterConnectionString, string databaseName)
|
|
|
|
|
{
|
2020-12-23 11:35:49 +01:00
|
|
|
string prefix = Regex.Replace(masterConnectionString, "Database=.+?;", string.Empty);
|
|
|
|
|
string connectionString = $"{prefix};Database={databaseName};";
|
2020-12-12 11:33:57 +00:00
|
|
|
return connectionString.Replace(";;", ";");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 11:35:49 +01:00
|
|
|
public static TestDbMeta CreateWithMasterConnectionString(string name, bool isEmpty, string masterConnectionString) =>
|
|
|
|
|
new TestDbMeta(name, isEmpty, ConstructConnectionString(masterConnectionString, name));
|
2020-12-12 11:33:57 +00:00
|
|
|
|
|
|
|
|
// LocalDb mdf funtimes
|
2020-12-23 11:35:49 +01:00
|
|
|
public static TestDbMeta CreateWithoutConnectionString(string name, bool isEmpty) =>
|
|
|
|
|
new TestDbMeta(name, isEmpty, null);
|
2020-12-12 11:33:57 +00:00
|
|
|
}
|
|
|
|
|
}
|