public void TransactionManagerRollsbackAmbientTransactionsOnAllThreads()
        {
            var seed = new Seed32();

            using (var manager = new TransactionManager<int, MockClassA>() )
            {
                manager.TransactionCommitted += new TransactionCommit<int, MockClassA>
                    (delegate(ITransaction<int, MockClassA> transaction)
                    {
                        transaction.MarkComplete();

                        Assert.Fail();
                    });

                var testEntities = TestResourceFactory.GetMockClassAObjects(3).ToList();
                testEntities.ForEach(e => e.Id = seed.Increment());

                using (var tLock1 = manager.GetActiveTransaction(false))
                {
                    foreach (var entity in testEntities)
                        tLock1.Transaction.Enlist(Action.Create, entity.Id, entity);

                    using (var tLock2 = manager.GetActiveTransaction(false))
                    {
                        testEntities = TestResourceFactory.GetMockClassAObjects(3).ToList();
                        testEntities.ForEach(e => e.Id = seed.Increment());

                        foreach (var entity in testEntities)
                            tLock2.Transaction.Enlist(Action.Create, entity.Id, entity);

                        manager.RollBackAll(true);
                    }
                }

                Assert.AreEqual(manager.GetCached().Count(), 0);
            }
        }
        public void TransactionManagerRollsbackAll()
        {
            var seed = new Seed32();

            using (var manager = new TransactionManager<int, MockClassA>() )
            {
                manager.TransactionCommitted += new TransactionCommit<int, MockClassA>
                    (delegate(ITransaction<int, MockClassA> transaction)
                    {
                        transaction.MarkComplete();

                        Assert.Fail();
                    });

                var testEntities = TestResourceFactory.GetMockClassAObjects(3).ToList();
                testEntities.ForEach(e => e.Id = seed.Increment());

                using (var tLock1 = manager.BeginTransaction())
                {
                    foreach (var entity in testEntities)
                        tLock1.Transaction.Enlist(Action.Create, entity.Id, entity);

                    using (var tLock2 = manager.BeginTransaction())
                    {
                        testEntities = TestResourceFactory.GetMockClassAObjects(3).ToList();
                        testEntities.ForEach(e => e.Id = seed.Increment());

                        foreach (var entity in testEntities)
                            tLock2.Transaction.Enlist(Action.Create, entity.Id, entity);

                        using (var tLock3 = manager.BeginTransaction())
                        {
                            testEntities = TestResourceFactory.GetMockClassAObjects(3).ToList();
                            testEntities.ForEach(e => e.Id = seed.Increment());

                            foreach (var entity in testEntities)
                                tLock3.Transaction.Enlist(Action.Create, entity.Id, entity);

                            using (var tLock4 = manager.BeginTransaction())
                            {
                                testEntities = TestResourceFactory.GetMockClassAObjects(3).ToList();
                                testEntities.ForEach(e => e.Id = seed.Increment());

                                foreach (var entity in testEntities)
                                    tLock4.Transaction.Enlist(Action.Create, entity.Id, entity);

                                using (var tLock5 = manager.BeginTransaction())
                                {
                                    testEntities = TestResourceFactory.GetMockClassAObjects(3).ToList();
                                    testEntities.ForEach(e => e.Id = seed.Increment());

                                    foreach (var entity in testEntities)
                                        tLock5.Transaction.Enlist(Action.Create, entity.Id, entity);

                                    manager.RollBackAll(true);

                                    while (manager.HasActiveTransactions)
                                        Thread.Sleep(100);

                                    Assert.IsTrue(tLock5.Transaction.IsComplete);
                                }

                                Assert.IsTrue(tLock4.Transaction.IsComplete);
                            }

                            Assert.IsTrue(tLock3.Transaction.IsComplete);
                        }

                        Assert.IsTrue(tLock2.Transaction.IsComplete);
                    }

                    Assert.IsTrue(tLock1.Transaction.IsComplete);
                }
            }
        }