Ejemplo n.º 1
0
        public void CommitAndRollbackTest()
        {
            int[] toCommitData   = new[] { 1, 3, 5, 7 };
            int[] toRollbackData = new[] { 2, 6, 8, 10 };

            HashTableWrapper wrapper = new HashTableWrapper();

            wrapper.BeginTransaction();
            for (int i = 0; i < toCommitData.Length; i++)
            {
                wrapper.Add(toCommitData[i], toCommitData[i]);
            }
            wrapper.CommitTransaction();

            wrapper.BeginTransaction();
            for (int i = 0; i < toRollbackData.Length; i++)
            {
                wrapper.Add(toRollbackData[i], toRollbackData[i]);
            }
            wrapper.RollbackTransaction();

            for (int i = 0; i < toCommitData.Length; i++)
            {
                Assert.IsTrue(wrapper.ContainsKey(toCommitData[i]), "Data committed successfully.");
            }

            for (int i = 0; i < toRollbackData.Length; i++)
            {
                Assert.IsFalse(wrapper.ContainsKey(toRollbackData[i]), "Data rollback performed successfully.");
            }
        }
Ejemplo n.º 2
0
        public void HashTableBlockedByTransactionTest()
        {
            HashTableWrapper wrapper = new HashTableWrapper();

            wrapper.BeginTransaction();

            for (int i = 0; i < 1000; i++)
            {
                wrapper.Add(i, i);
            }

            Assert.IsTrue(wrapper.IsLocked, "Data locked by transaction successfully.");

            wrapper.RollbackTransaction();
        }
Ejemplo n.º 3
0
        public void RollbackTest()
        {
            HashTableWrapper wrapper = new HashTableWrapper();

            wrapper.BeginTransaction();

            int expectedNumberOfElements = 0;

            for (int i = 0; i < 1000; i++)
            {
                wrapper.Add(i, i);
            }

            wrapper.RollbackTransaction();

            Assert.AreEqual(expectedNumberOfElements, wrapper.Count);
        }