public IDocumentStore GetDocumentStore(GetDocumentStoreOptions options = null, [CallerMemberName] string database = null) { options = options ?? GetDocumentStoreOptions.Default; var name = database + "_" + Interlocked.Increment(ref _index); ReportInfo($"GetDocumentStore for db ${ database }."); var documentStore = GlobalServer.Value; var createDatabaseOperation = new CreateDatabaseOperation(new DatabaseRecord(name)); documentStore.Maintenance.Server.Send(createDatabaseOperation); var store = new DocumentStore { Urls = documentStore.Urls, Database = name }; PreInitialize(store); store.Initialize(); store.AfterDispose += (sender, args) => { if (_documentStores.TryRemove(store, out _) == false) { return; } try { store.Maintenance.Server.Send(new DeleteDatabasesOperation(store.Database, true)); } catch (DatabaseDoesNotExistException) { } catch (NoLeaderException) { } }; ImportDatabase(store, name); SetupDatabase(store); if (options.WaitForIndexingTimeout.HasValue) { WaitForIndexing(store, name, options.WaitForIndexingTimeout); } _documentStores[store] = null; return(store); }
protected IDocumentStore GetDocumentStore(GetDocumentStoreOptions options = null, [CallerMemberName] string database = null) { options = options ?? GetDocumentStoreOptions.Default; if (string.Equals(database, ".ctor", StringComparison.OrdinalIgnoreCase)) { database = $"{GetType().Name}_ctor"; } else if (string.Equals(database, ".cctor", StringComparison.OrdinalIgnoreCase)) { database = $"{GetType().Name}_cctor"; } var name = database + "_" + Interlocked.Increment(ref _index); var documentStore = TestServerStore.Value; var createDatabaseOperation = new CreateDatabaseOperation(new DatabaseRecord(name)); documentStore.Maintenance.Server.Send(createDatabaseOperation); var store = new DocumentStore { Urls = documentStore.Urls, Database = name }; PreInitialize(store); store.Initialize(); store.AfterDispose += (sender, args) => { if (_documentStores.TryRemove(store, out _) == false) { return; } try { store.Maintenance.Server.Send(new DeleteDatabasesOperation(store.Database, hardDelete: true)); } catch (DatabaseDoesNotExistException) { } catch (NoLeaderException) { } }; AsyncHelpers.RunSync(() => ImportDatabaseAsync(store, name)); SetupDatabase(store); if (options.WaitForIndexingTimeout.HasValue) { WaitForIndexing(store, name, options.WaitForIndexingTimeout); } _documentStores[store] = null; return(store); }