コード例 #1
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));
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
 public void Does_not_call_db_in_constructor()
 {
     var eventStore = new SqlServerEventStore("SomeStringThatDoesNotPointToARealSqlServer", new SingleThreadUseGuard());
 }