Example #1
0
            public void should_not_commit_nested_unit_of_work()
            {
                //act
                UnitOfWork.Do(uow => UnitOfWork.Do(nested => nested.Commit()));

                //assert
                A.CallTo(() => SessionScope.Commit()).MustHaveHappened(Repeated.Exactly.Once);
            }
Example #2
0
            public void should_commit_and_dispose()
            {
                //act
                UnitOfWork.Do(uow => { });

                //assert
                A.CallTo(() => SessionScope.Commit()).MustHaveHappened(Repeated.Exactly.Once);
                A.CallTo(() => SessionScope.Dispose()).MustHaveHappened(Repeated.Exactly.Once);
            }
Example #3
0
 /// <summary>
 /// Commit database transaction explicitly(not necessarily to use in standard configuration, because transaction will be committed anyway in the end of the "Do" block).
 /// </summary>
 public void Commit()
 {
     Perform(() =>
     {
         if (Settings.EnableCommit)
         {
             SessionScope.Commit();
         }
     });
 }
Example #4
0
            public void should_not_commit()
            {
                //act
                UnitOfWork.Do(uow => { }, new UnitOfWorkSettings()
                {
                    EnableCommit = false
                });

                //assert
                A.CallTo(() => SessionScope.Commit()).MustNotHaveHappened();
            }
Example #5
0
            public void should_commit()
            {
                //act
                UnitOfWork.Do(uow => { }, new UnitOfWorkSettings()
                {
                    RollbackOnDispose = false
                });

                //assert
                A.CallTo(() => SessionScope.Rollback()).MustNotHaveHappened();
                A.CallTo(() => SessionScope.Commit()).MustHaveHappened();
            }
Example #6
0
            public void should_close_unit_of_work()
            {
                //arrange
                A.CallTo(() => SessionScope.Commit()).Throws <Exception>();

                //act
                try
                {
                    UnitOfWork.Do(uow =>
                    {
                    });
                }
                catch (Exception)
                {
                    //assert
                    A.CallTo(() => SessionScope.Dispose()).MustHaveHappened();
                    UnitOfWork.Current.IsNone.Should().BeTrue();
                }
            }
Example #7
0
            public void should_not_try_to_commit_or_rollback_and_should_close_unit_of_work()
            {
                //act
                try
                {
                    UnitOfWork.Do(uow =>
                    {
                        throw new Exception();
                    });
                }
                catch (Exception)
                {
                    //assert
                    A.CallTo(() => SessionScope.Rollback()).MustNotHaveHappened();
                    A.CallTo(() => SessionScope.Commit()).MustNotHaveHappened();

                    A.CallTo(() => SessionScope.Dispose()).MustHaveHappened();
                    UnitOfWork.Current.IsNone.Should().BeTrue();
                }
            }