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); }
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); }
/// <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(); } }); }
public void should_not_commit() { //act UnitOfWork.Do(uow => { }, new UnitOfWorkSettings() { EnableCommit = false }); //assert A.CallTo(() => SessionScope.Commit()).MustNotHaveHappened(); }
public void should_commit() { //act UnitOfWork.Do(uow => { }, new UnitOfWorkSettings() { RollbackOnDispose = false }); //assert A.CallTo(() => SessionScope.Rollback()).MustNotHaveHappened(); A.CallTo(() => SessionScope.Commit()).MustHaveHappened(); }
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(); } }
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(); } }