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


C# UnitOfWork.RollBack方法代码示例

本文整理汇总了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());
        }
开发者ID:kayone,项目名称:Marr.DataMapper,代码行数:32,代码来源:UnitOfWorkTest.cs

示例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);
        }
开发者ID:kayone,项目名称:Marr.DataMapper,代码行数:42,代码来源:UnitOfWorkTest.cs

示例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();
        }
开发者ID:kayone,项目名称:Marr.DataMapper,代码行数:22,代码来源:UnitOfWorkTest.cs


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