本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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;
}
}
示例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());
}