예제 #1
0
        void Common_Can_save_transaction(ITransactionBoundFactory xf, IRepository<Product> p, IRepository<Question> q)
        {
            using (var tx = xf.BeginTransaction())
            {
                p.Save(new Product { ProductName = "Hello", Category = "What", MinimumPrice = 2 });
                tx.Complete();
            }

            Assert.AreEqual(1, p.All.Count());
        }
예제 #2
0
        void Common_Can_rollback_transaction(ITransactionBoundFactory xf, IRepository<Product> p, IRepository<Question> q)
        {
            try
            {
                // Arrange
                using (var tx = xf.BeginTransaction())
                {
                    p.Save(new Product { ProductName = "Hello", Category = "What", MinimumPrice = 2 });

                    int n = 0;

                    // Act
                    int px = 7 / n;
                    q.Save(new Question { Text = "Answer to life", Poster = "42" });

                    tx.Complete();
                }

            }
            catch(DivideByZeroException)
            {
            }
            finally
            {
                // Assert
                Assert.AreEqual(0, p.All.Count()); // product Count should be zero. automatically rolled back
            }
        }