public void SetupTask() { _masterConnectionString = ConfigurationManager.ConnectionStrings["MasterDB"].ConnectionString; _masterConnection = new SqlServerConnectionUtilities(_masterConnectionString); _manager = new TemporaryLocalDbManager(_masterConnectionString); _dB1ConnectionString = _manager.CreateOrGetLocalDb(Db1); _dB2ConnectionString = _manager.CreateOrGetLocalDb(Db2); _dB1DbName = new SqlServerConnectionUtilities(_dB1ConnectionString).UseConnection(connection => connection.Database); _dB2DbName = new SqlServerConnectionUtilities(_dB2ConnectionString).UseConnection(connection => connection.Database); }
public void ShouldCacheEventsBetweenInstancesTransaction() { using (var dbManager = new TemporaryLocalDbManager(ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString)) { var connectionString = dbManager.CreateOrGetLocalDb("SqlServerEventStoreTest_EventStore2"); var something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); var user = new User(); user.Register("*****@*****.**", "password", Guid.NewGuid()); var stored = (IEventStored)user; using (var tran = new TransactionScope()) { something.SaveEvents(stored.GetChanges()); something.GetAggregateHistory(user.Id); Assert.That(something.GetAggregateHistory(user.Id), Is.Not.Empty); tran.Complete(); } something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); var firstRead = something.GetAggregateHistory(user.Id).Single(); something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); var secondRead = something.GetAggregateHistory(user.Id).Single(); Assert.That(firstRead, Is.SameAs(secondRead)); } }
public void Setup() { var masterConnectionString = ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString; _temporaryLocalDbManager = new TemporaryLocalDbManager(masterConnectionString); ConnectionString = _temporaryLocalDbManager.CreateOrGetLocalDb($"SqlServerEventStoreSessionTests_EventStore"); }
public void ShouldCacheEventsBetweenInstancesTransaction() { using(var dbManager = new TemporaryLocalDbManager(ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString)) { var connectionString = dbManager.CreateOrGetLocalDb("SqlServerEventStoreTest_EventStore2"); var something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); var user = new User(); user.Register("*****@*****.**", "password", Guid.NewGuid()); var stored = (IEventStored)user; using(var tran = new TransactionScope()) { something.SaveEvents(stored.GetChanges()); something.GetAggregateHistory(user.Id); Assert.That(something.GetAggregateHistory(user.Id), Is.Not.Empty); tran.Complete(); } something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); var firstRead = something.GetAggregateHistory(user.Id).Single(); something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); var secondRead = something.GetAggregateHistory(user.Id).Single(); Assert.That(firstRead, Is.SameAs(secondRead)); } }
public void Setup() { var masterConnectionString = ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString; _temporaryLocalDbManager = new TemporaryLocalDbManager(masterConnectionString); _connectionString = _temporaryLocalDbManager.CreateOrGetLocalDb($"SqlDocumentDbTests_DB"); SqlServerDocumentDb.ResetDB(_connectionString); }
override public void before_each() { base.before_each(); _connectionManager = new TemporaryLocalDbManager(new ConnectionStringConfigurationParameterProvider().GetConnectionString("MasterDB").ConnectionString); _connectionString = _connectionManager.CreateOrGetLocalDb($"{nameof(SqlServerDocumentDbSpecification)}DocumentDB"); SqlServerDocumentDb.ResetDB(_connectionString); _store = new SqlServerDocumentDb(_connectionString); }
public void ShouldNotCacheEventsSavedDuringFailedTransactionEvenIfReadDuringSameTransaction() { using(var dbManager = new TemporaryLocalDbManager(ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString)) { var connectionString = dbManager.CreateOrGetLocalDb("SqlServerEventStoreTest_EventStore1"); var something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); something.ResetDB(); //Sometimes the test would fail on the last line with information that the table was missing. Probably because the table was created during the aborted transaction. I'm hoping this will fix it. var user = new User(); user.Register("*****@*****.**", "password", Guid.NewGuid()); using(new TransactionScope()) { something.SaveEvents(((IEventStored)user).GetChanges()); something.GetAggregateHistory(user.Id); Assert.That(something.GetAggregateHistory(user.Id), Is.Not.Empty); } Assert.That(something.GetAggregateHistory(user.Id), Is.Empty); } }
public void ShouldNotCacheEventsSavedDuringFailedTransactionEvenIfReadDuringSameTransaction() { using (var dbManager = new TemporaryLocalDbManager(ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString)) { var connectionString = dbManager.CreateOrGetLocalDb("SqlServerEventStoreTest_EventStore1"); var something = new SqlServerEventStore(connectionString, new SingleThreadUseGuard()); something.ResetDB(); //Sometimes the test would fail on the last line with information that the table was missing. Probably because the table was created during the aborted transaction. I'm hoping this will fix it. var user = new User(); user.Register("*****@*****.**", "password", Guid.NewGuid()); using (new TransactionScope()) { something.SaveEvents(((IEventStored)user).GetChanges()); something.GetAggregateHistory(user.Id); Assert.That(something.GetAggregateHistory(user.Id), Is.Not.Empty); } Assert.That(something.GetAggregateHistory(user.Id), Is.Empty); } }
protected static WindsorContainer CreateContainerForEventStoreType(Func <IReadOnlyList <IEventMigration> > migrationsfactory, Type eventStoreType, string eventStoreConnectionString = null) { var container = new WindsorContainer(); container.ConfigureWiringForTestsCallBeforeAllOtherWiring(); container.Register( Component.For <IUtcTimeTimeSource, DummyTimeSource>() .Instance(DummyTimeSource.Now) .LifestyleSingleton(), Component.For <IServiceBus>() .ImplementedBy <SynchronousBus>() .LifestylePerWebRequest(), Component.For <IEnumerable <IEventMigration> >() .UsingFactoryMethod(migrationsfactory) .LifestylePerWebRequest(), Component.For <IEventStoreSession, IUnitOfWorkParticipant>() .ImplementedBy <EventStoreSession>() .LifestylePerWebRequest(), Component.For <IWindsorContainer>().Instance(container) ); if (eventStoreType == typeof(SqlServerEventStore)) { if (eventStoreConnectionString == null) { var masterConnectionSTring = new ConnectionStringConfigurationParameterProvider().GetConnectionString("MasterDB"); var dbManager = new TemporaryLocalDbManager(masterConnectionSTring.ConnectionString, container); eventStoreConnectionString = dbManager.CreateOrGetLocalDb($"{nameof(EventStreamMutatorTestsBase)}_EventStore"); } container.Register( Component.For <IEventStore>() .ImplementedBy <SqlServerEventStore>() .DependsOn(Dependency.OnValue <string>(eventStoreConnectionString)) .LifestyleScoped()); } else if (eventStoreType == typeof(InMemoryEventStore)) { container.Register( Component.For <IEventStore>() .UsingFactoryMethod( kernel => { var store = kernel.Resolve <InMemoryEventStore>(); store.TestingOnlyReplaceMigrations(migrationsfactory()); return(store); }) .LifestyleScoped(), Component.For <InMemoryEventStore>() .ImplementedBy <InMemoryEventStore>() .LifestyleSingleton()); } else { throw new Exception($"Unsupported type of event store {eventStoreType}"); } container.ConfigureWiringForTestsCallAfterAllOtherWiring(); return(container); }
public void SetupFixture() { _tempDbManager = new TemporaryLocalDbManager(ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString); _connectionString1 = _tempDbManager.CreateOrGetLocalDb("SqlServerEventStoreTests_EventStore1"); _connectionString2 = _tempDbManager.CreateOrGetLocalDb("SqlServerEventStoreTests_EventStore2"); }
public void Connection_to_Db1_can_be_opened_and_used() { new SqlServerConnectionUtilities(_manager.CreateOrGetLocalDb(Db1)).ExecuteScalar("select 1") .Should().Be(1); }
protected static WindsorContainer CreateContainerForEventStoreType(Func<IReadOnlyList<IEventMigration>> migrationsfactory, Type eventStoreType, string eventStoreConnectionString = null) { var container = new WindsorContainer(); container.ConfigureWiringForTestsCallBeforeAllOtherWiring(); container.Register( Component.For<IUtcTimeTimeSource, DummyTimeSource>() .Instance(DummyTimeSource.Now) .LifestyleSingleton(), Component.For<IServiceBus>() .ImplementedBy<SynchronousBus>() .LifestylePerWebRequest(), Component.For<IEnumerable<IEventMigration>>() .UsingFactoryMethod(migrationsfactory) .LifestylePerWebRequest(), Component.For<IEventStoreSession, IUnitOfWorkParticipant>() .ImplementedBy<EventStoreSession>() .LifestylePerWebRequest(), Component.For<IWindsorContainer>().Instance(container) ); if (eventStoreType == typeof(SqlServerEventStore)) { if(eventStoreConnectionString == null) { var masterConnectionSTring = new ConnectionStringConfigurationParameterProvider().GetConnectionString("MasterDB"); var dbManager = new TemporaryLocalDbManager(masterConnectionSTring.ConnectionString, container); eventStoreConnectionString = dbManager.CreateOrGetLocalDb($"{nameof(EventStreamMutatorTestsBase)}_EventStore"); } container.Register( Component.For<IEventStore>() .ImplementedBy<SqlServerEventStore>() .DependsOn(Dependency.OnValue<string>(eventStoreConnectionString)) .LifestyleScoped()); } else if(eventStoreType == typeof(InMemoryEventStore)) { container.Register( Component.For<IEventStore>() .UsingFactoryMethod( kernel => { var store = kernel.Resolve<InMemoryEventStore>(); store.TestingOnlyReplaceMigrations(migrationsfactory()); return store; }) .LifestyleScoped(), Component.For<InMemoryEventStore>() .ImplementedBy<InMemoryEventStore>() .LifestyleSingleton()); } else { throw new Exception($"Unsupported type of event store {eventStoreType}"); } container.ConfigureWiringForTestsCallAfterAllOtherWiring(); return container; }