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));
            }
        }
Exemplo n.º 2
0
        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 Setup()
        {
            var masterConnectionString = ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString;

            _temporaryLocalDbManager = new TemporaryLocalDbManager(masterConnectionString);
            ConnectionString         = _temporaryLocalDbManager.CreateOrGetLocalDb($"SqlServerEventStoreSessionTests_EventStore");
        }
        public void Setup()
        {
            var masterConnectionString = ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString;
            _temporaryLocalDbManager = new TemporaryLocalDbManager(masterConnectionString);
            _connectionString = _temporaryLocalDbManager.CreateOrGetLocalDb($"SqlDocumentDbTests_DB");

            SqlServerDocumentDb.ResetDB(_connectionString);
        }
 public void Setup()
 {
     _windsorContainer = new WindsorContainer();
     Bus = new DummyServiceBus(_windsorContainer);
     var masterConnectionString = ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString;
     _connectionString = new TemporaryLocalDbManager(masterConnectionString, _windsorContainer)
         .CreateOrGetLocalDb("MigratedSqlServerEventStoreSessionTests_EventStore");
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
        public void Setup()
        {
            var masterConnectionString = ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString;

            _temporaryLocalDbManager = new TemporaryLocalDbManager(masterConnectionString);
            _connectionString        = _temporaryLocalDbManager.CreateOrGetLocalDb($"SqlDocumentDbTests_DB");

            SqlServerDocumentDb.ResetDB(_connectionString);
        }
            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 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);
            }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 13
0
        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);
        }
 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 SetupFixture()
 {
     _tempDbManager = new TemporaryLocalDbManager(ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString);
     _connectionString1 = _tempDbManager.CreateOrGetLocalDb("SqlServerEventStoreTests_EventStore1");
     _connectionString2 = _tempDbManager.CreateOrGetLocalDb("SqlServerEventStoreTests_EventStore2");
 }
Exemplo n.º 16
0
 public void SetupFixture()
 {
     _tempDbManager     = new TemporaryLocalDbManager(ConfigurationManager.ConnectionStrings["MasterDb"].ConnectionString);
     _connectionString1 = _tempDbManager.CreateOrGetLocalDb("SqlServerEventStoreTests_EventStore1");
     _connectionString2 = _tempDbManager.CreateOrGetLocalDb("SqlServerEventStoreTests_EventStore2");
 }
        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;
        }