本文整理汇总了C#中UnitOfWork.RollBack方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.RollBack方法的具体用法?C# UnitOfWork.RollBack怎么用?C# UnitOfWork.RollBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork.RollBack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnitOfWork_WithNestedTransactions_InnerCommitShouldBeIgnored
public void UnitOfWork_WithNestedTransactions_InnerCommitShouldBeIgnored()
{
var db = MockRepository.GenerateStub<IDataMapper>();
var cmd = MockRepository.GenerateStub<DbCommand>();
db.Expect(d => d.Command).Return(cmd).Repeat.Any();
ITestDbFactory factory = MockRepository.GenerateMock<ITestDbFactory>();
factory.Expect(f => f.Create()).Return(db).Repeat.Any();
UnitOfWork uow = new UnitOfWork(() => factory.Create());
using (uow.SharedContext)
{
uow.BeginTransaction();
uow.DB.ExecuteNonQuery("query1");
using (uow)
{
uow.BeginTransaction();
uow.DB.ExecuteNonQuery("query2");
uow.DB.ExecuteNonQuery("query3");
uow.Commit();
}
uow.RollBack();
}
db.AssertWasCalled(d => d.BeginTransaction(), o => o.Repeat.Once());
db.AssertWasNotCalled(d => d.Commit());
db.AssertWasCalled(d => d.RollBack());
}
示例2: UnitOfWork_WithNestedTransactions_InnerRollBackShouldBeCalled
public void UnitOfWork_WithNestedTransactions_InnerRollBackShouldBeCalled()
{
var db = MockRepository.GenerateStub<IDataMapper>();
var cmd = MockRepository.GenerateStub<DbCommand>();
db.Expect(d => d.Command).Return(cmd).Repeat.Any();
ITestDbFactory factory = MockRepository.GenerateMock<ITestDbFactory>();
factory.Expect(f => f.Create()).Return(db).Repeat.Any();
UnitOfWork uow = new UnitOfWork(() => factory.Create());
bool exceptionThrown = false;
using (uow.SharedContext)
{
uow.BeginTransaction();
uow.DB.ExecuteNonQuery("query1");
try
{
using (uow)
{
uow.BeginTransaction();
uow.DB.ExecuteNonQuery("query2");
uow.DB.ExecuteNonQuery("query3");
uow.RollBack();
}
uow.Commit();
}
catch (NestedSharedContextRollBackException ex)
{
exceptionThrown = true;
}
}
db.AssertWasCalled(d => d.BeginTransaction(), o => o.Repeat.Once());
db.AssertWasCalled(d => d.RollBack());
db.AssertWasNotCalled(d => d.Commit());
Assert.IsTrue(exceptionThrown);
}
示例3: OneUnitOfWork_ShouldBeginAndRollBackOneTransaction
public void OneUnitOfWork_ShouldBeginAndRollBackOneTransaction()
{
var db = MockRepository.GenerateStub<IDataMapper>();
var cmd = MockRepository.GenerateStub<DbCommand>();
db.Expect(d => d.Command).Return(cmd).Repeat.Any();
ITestDbFactory factory = MockRepository.GenerateMock<ITestDbFactory>();
factory.Expect(f => f.Create()).Return(db).Repeat.Any();
UnitOfWork uow = new UnitOfWork(() => factory.Create());
using (uow)
{
uow.BeginTransaction();
uow.DB.ExecuteNonQuery("query1");
uow.DB.ExecuteNonQuery("query2");
uow.RollBack();
}
db.Expect(d => d.BeginTransaction()).Repeat.Once();
db.Expect(d => d.RollBack()).Repeat.Once();
}