public GrainStorageTests(ITestOutputHelper output) { timingFactor = CalibrateTimings(); this.output = output; var rnd = new Random(); dbNames = new Dictionary <string, SqlConnectionStringBuilder>(); dbInstanceName = rnd.Next().ToString(); ISqlLocalDbProvider provider = new SqlLocalDbProvider(); instance = provider.GetOrCreateInstance(dbInstanceName); instance.Start(); //do the database setups dbNames.Add("basic", CreateADatabase(rnd)); dbNames.Add("SimpleSQLStore", CreateADatabase(rnd)); //this is the call to start up the test cluster base.Initialize(); }
private bool CheckSqlServer() { try { ISqlLocalDbProvider provider = new SqlLocalDbProvider(); ISqlLocalDbInstance instance = provider.GetOrCreateInstance(Global.Product); instance.Start(); } catch (Exception e) { MessageBox.Show("LocalDB Instance could not be started:\n\n" + e.Message, $"{Global.Product}", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } // create Database and Files if MDF not exists if (!File.Exists(Global.DatabaseMdfPath)) { DbCreator.Create(Global.Product, Global.DatabaseFolder); } using (SqlConnection c = new SqlConnection(Properties.Settings.Default.SQLEXPRESS)) { try { c.Open(); return(true); } catch (Exception e) { MessageBox.Show("Error opening Database:\n\n" + e.Message, $"{Global.Product}", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } }
private void Initialize(string instanceName, string databaseName) { this.databaseName = databaseName; this.instanceName = instanceName; var existing = SqlLocalDbApi.GetInstanceInfo(instanceName); if (existing.Exists) { if (existing.IsRunning) { SqlLocalDbApi.StopInstance(instanceName); } SqlLocalDbApi.DeleteInstance(instanceName); } ISqlLocalDbProvider provider = new SqlLocalDbProvider(); this.instance = provider.GetOrCreateInstance(instanceName); instance.Start(); var connectionStringBuilder = instance.CreateConnectionStringBuilder(); using (var conn = new SqlConnection(connectionStringBuilder.ConnectionString)) { var serverConnection = new ServerConnection(conn); // By default, LocalDB stores database files in the user's home folder. Messy for temporary test databases. // Store them in the user's temp folder instead. var testDatabasesDirectory = Path.Combine(Path.GetTempPath(), "TestDatabases"); if (!Directory.Exists(testDatabasesDirectory)) { Directory.CreateDirectory(testDatabasesDirectory); } // Generate a unique name for our mdf file to avoid clashing with other ongoing test runs. var databaseFileNameRoot = string.Format("{0}_{1}_{2}", databaseName, DateTime.Now.ToString("yyyyMMdd_HHmmss"), Guid.NewGuid().ToString("N")); var mdfFileName = databaseFileNameRoot + ".mdf"; var ldfFileName = databaseFileNameRoot + "_log.ldf"; this.mdfFilePath = Path.Combine(testDatabasesDirectory, mdfFileName); this.ldfFilePath = Path.Combine(testDatabasesDirectory, ldfFileName); var sql = string.Format("CREATE DATABASE {0} ON (NAME = N'{0}', FILENAME = '{1}')", databaseName, this.mdfFilePath); Console.WriteLine(string.Format("Creating database {0} at {1}", databaseName, this.mdfFilePath)); serverConnection.ExecuteNonQuery(sql); } connectionStringBuilder.InitialCatalog = this.databaseName; this.connectionString = connectionStringBuilder.ConnectionString; }
public ISqlLocalDbInstance Start(string serverInstanceName) { Debug.WriteLine("Starting localDb server..."); var localDbProvider = new SqlLocalDbProvider(); LocalDb = localDbProvider.GetOrCreateInstance(serverInstanceName); if (!LocalDb.GetInstanceInfo().IsRunning) { LocalDb.Start(); } return(LocalDb); }
public MsSqlStreamStoreFixture(string schema) { _schema = schema; var localDbProvider = new SqlLocalDbProvider { Version = s_sqlLocalDbProviderVersionToUse }; _localDbInstance = localDbProvider.GetOrCreateInstance("StreamStoreTests"); _localDbInstance.Start(); var uniqueName = Guid.NewGuid().ToString().Replace("-", string.Empty); _databaseName = $"StreamStoreTests-{uniqueName}"; ConnectionString = CreateConnectionString(); }
public MsSqlEventStoreFixture(string schema) { _schema = schema; var localDbProvider = new SqlLocalDbProvider { Version = "11.0" }; _localDbInstance = localDbProvider.GetOrCreateInstance("CedarEventStoreTests"); _localDbInstance.Start(); var uniqueName = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString().PadLeft(20, '0'); _databaseName = $"CedarEventStoreTests_{uniqueName}"; ConnectionString = CreateConnectionString(); }
public PubSubStoreTests(ITestOutputHelper output) : base() { this.output = output; var rnd = new Random(); dbNames = new Dictionary <string, string>() { { "PubSubStore", rnd.Next().ToString() }, }; dbInstanceName = rnd.Next().ToString(); ISqlLocalDbProvider provider = new SqlLocalDbProvider(); instance = provider.GetOrCreateInstance(dbInstanceName); instance.Start(); Initialize(); }