public void TransactionExceedingTimeoutTest( )
        {
            var testCache = new TestCache( );

            using (var scope = new TransactionScope(TransactionScopeOption.Required))
            {
                // Create a notification manager with a time out interval of 1 seconds.
                var cacheManager = new TransactionEventNotificationManager(testCache, 0);

                // Add an items to the cache while inside a transaction
                testCache.AddItem("A");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("B");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("C");
                cacheManager.EnlistTransaction(Transaction.Current);

                scope.Complete( );

                // As the transaction exceeded the timeout, its data will not
                // be committed
            }

            Assert.IsFalse(testCache.Contains("A"));
            Assert.IsFalse(testCache.Contains("B"));
            Assert.IsFalse(testCache.Contains("C"));
        }
        public void EnlistCommitTransactionTest( )
        {
            var testCache = new TestCache( );

            using (var scope = new TransactionScope(TransactionScopeOption.Required))
            {
                var cacheManager = new TransactionEventNotificationManager(testCache);

                // Add some items to the cache while inside a transaction
                testCache.AddItem("A");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("B");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("C");
                cacheManager.EnlistTransaction(Transaction.Current);

                // Commit the transaction
                scope.Complete( );
            }

            Assert.IsTrue(testCache.Contains("A"));
            Assert.IsTrue(testCache.Contains("B"));
            Assert.IsTrue(testCache.Contains("C"));
        }
        public void EnlistRolledbackTransactionTest( )
        {
            var testCache = new TestCache( );

            using (new TransactionScope(TransactionScopeOption.Required))
            {
                var cacheManager = new TransactionEventNotificationManager(testCache);

                // Add some items to the cache while inside a transaction
                testCache.AddItem("A");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("B");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("C");
                cacheManager.EnlistTransaction(Transaction.Current);

                // Roll back transaction
            }

            Assert.IsFalse(testCache.Contains("A"));
            Assert.IsFalse(testCache.Contains("B"));
            Assert.IsFalse(testCache.Contains("C"));
        }
        public void ClearTransactionEventNotifiersTest( )
        {
            var testCache = new TestCache( );

            using (var scope = new TransactionScope(TransactionScopeOption.Required))
            {
                var cacheManager = new TransactionEventNotificationManager(testCache);

                // Add some items to the cache while inside a transaction
                testCache.AddItem("A");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("B");
                cacheManager.EnlistTransaction(Transaction.Current);

                testCache.AddItem("C");
                cacheManager.EnlistTransaction(Transaction.Current);

                // Clear the event notifiers
                cacheManager.ClearTransactionEventNotifiers( );

                // Commit the transaction
                // as the. As the event notifiers have been removed
                // the items will not be commited
                scope.Complete( );
            }

            Assert.IsFalse(testCache.Contains("A"));
            Assert.IsFalse(testCache.Contains("B"));
            Assert.IsFalse(testCache.Contains("C"));
        }