当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.Execute方法代码示例

本文整理汇总了C#中Transaction.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Execute方法的具体用法?C# Transaction.Execute怎么用?C# Transaction.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transaction的用法示例。


在下文中一共展示了Transaction.Execute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestExecuteFails

        public void TestExecuteFails()
        {
            var operations = new List<IOperation>
                                 {
                                     MockRepository.GenerateMock<IOperation>(),
                                     MockRepository.GenerateMock<IOperation>()
                                 };

            operations[0].Expect(m => m.PreCondition());
            operations[1].Expect(m => m.PreCondition());

            operations[0].Expect(m => m.Execute());
            operations[1].Expect(m => m.Execute());

            operations[0].Expect(m => m.Rollback());

            operations[0].Expect(m => m.PostCondition());
            operations[1].Expect(m => m.PostCondition()).Throw(new Exception());

            using (sut = new Transaction(new SingleThreadingPolicy()))
            {
                Assert.Throws<Exception>(() => sut.Execute(operations));
            }

            operations.ForEach(m => m.VerifyAllExpectations());
        }
开发者ID:repne,项目名称:WitchHunter,代码行数:26,代码来源:TransactionTests.cs

示例2: TestInsertSuccess

        public void TestInsertSuccess()
        {
            EntityManagerTest<TempTransactionRecord>.Instance.DeleteAll();
            Assert.AreEqual(0, GetRecordCount());

            Exception outException;

            var transaction = new Transaction();

            var success = transaction.Execute(() =>
            {
                var firstRecord = GenerateTransactionTest();
                var secondRecord = GenerateTransactionTest();

                EntityManagerTest<TempTransactionRecord>.Instance.InsertOne(firstRecord);
                Assert.AreEqual(1, GetRecordCount());

                EntityManagerTest<TempTransactionRecord>.Instance.InsertOne(secondRecord);
                Assert.AreEqual(2, GetRecordCount());
            }, out outException);

            Assert.IsTrue(success);
            Assert.IsNull(outException);
            Assert.AreEqual(2, GetRecordCount());

            EntityManagerTest<TempTransactionRecord>.Instance.DeleteAll();
            Assert.AreEqual(0, GetRecordCount());
        }
开发者ID:ukionik,项目名称:EasyORM,代码行数:28,代码来源:TransactionTest.cs

示例3: TestInsertFail

        public void TestInsertFail()
        {
            EntityManagerTest<TempTransactionRecord>.Instance.DeleteAll();
            Assert.AreEqual(0, GetRecordCount());

            var exception = new Exception("Something goes wrong!");
            Exception outException;

            var transaction = new Transaction();

            var success = transaction.Execute(() =>
                {
                    var firstRecord = GenerateTransactionTest();
                    var secondRecord = GenerateTransactionTest();

                    EntityManagerTest<TempTransactionRecord>.Instance.InsertOne(firstRecord);
                    Assert.AreEqual(1, GetRecordCount());

                    EntityManagerTest<TempTransactionRecord>.Instance.InsertOne(secondRecord);
                    Assert.AreEqual(2, GetRecordCount());

                    throw exception;
                }, out outException);

            Assert.IsFalse(success);
            Assert.AreEqual(exception, outException);
            Assert.AreEqual(0, GetRecordCount());
        }
开发者ID:ukionik,项目名称:EasyORM,代码行数:28,代码来源:TransactionTest.cs

示例4: ExecuteTransaction

 public bool ExecuteTransaction(Transaction transaction)
 {
     //Execute transaction if either:
     //1. It's a InsertCashTransaction.
     //2. It's a BuyTransaction and the product is active, and the user has the balance to buy the product.
     if (transaction != null 
         && ((transaction is BuyTransaction && (transaction.User.Balance >= transaction.Amount && (transaction as BuyTransaction).Product.Active)) 
         || transaction is InsertCashTransaction))
     {
         transaction.Execute();
         log.WriteLine(transaction.ToString());
         Transactions.Add(transaction);
         return true;
     }
     else
     {
         return false;
     }
 }
开发者ID:Hejsil,项目名称:2.-Semester-Examen,代码行数:19,代码来源:LineSystem.cs

示例5: TestExecuteSucceed

        public void TestExecuteSucceed()
        {
            var operations = new List<IOperation>
                                 {
                                     MockRepository.GenerateMock<IOperation>(),
                                     MockRepository.GenerateMock<IOperation>()
                                 };

            operations[0].Expect(m => m.PreCondition());
            operations[1].Expect(m => m.PreCondition());

            operations[0].Expect(m => m.Execute());
            operations[1].Expect(m => m.Execute());

            operations[0].Expect(m => m.PostCondition());
            operations[1].Expect(m => m.PostCondition());

            using (sut = new Transaction(new SingleThreadingPolicy()))
            {
                sut.Execute(operations);
            }

            operations.ForEach(m => m.VerifyAllExpectations());
        }
开发者ID:repne,项目名称:WitchHunter,代码行数:24,代码来源:TransactionTests.cs


注:本文中的Transaction.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。