public void CountAllWithTransactionInitiated() { var provider = new IProvider(); var command = new ICommand(); var schema = new TypeTable(typeof(Customer)); var transaction = new Mock<ITransaction>(); provider.Setup(p => p.GetSchema(typeof(Customer))).Returns(schema); provider.CommandBuilder.Setup(c => c.CreateCountCommand<Customer>()).Returns(command.Object); provider.CommandExecutor.Setup(c => c.InitiateTransaction()).Returns(transaction.Object); provider.CommandExecutor.Setup(c => c.ExecuteCount(command.Object, transaction.Object)).Returns(10); var target = new DataSession(provider.Object); target.BeginTransaction(); var result = target.Count<Customer>(); target.CommitTransaction(); Assert.IsTrue(result == 10); }
public void RollbackTransactionCallsExecutorRollBackTransaction() { var provider = new IProvider(); var transaction = new Mock<ITransaction>(); provider.CommandExecutor.Setup(c => c.InitiateTransaction()).Returns(transaction.Object); var target = new DataSession(provider.Object); target.BeginTransaction(); target.RollBackTransaction(); provider.CommandExecutor.Verify(c => c.InitiateTransaction()); provider.CommandExecutor.Verify(c => c.RollbackTransaction(transaction.Object)); }
public void SaveRollBacksTransactionWhenExceptionThrown() { var customer = new Customer { ID = 1, Balance = 0, BalanceRate = 0, DefaultContactID = 1, Name = "Customer1", ProfileID = 1 }; var provider = new IProvider(); var transaction = new Mock<ITransaction>(); provider.CommandExecutor.Setup(c => c.InitiateTransaction()).Returns(transaction.Object); provider.Setup(p => p.GetEntityStatus(customer)).Returns(EntityStatus.Insert); provider.CommandBuilder.Setup(c => c.CreateInsertCommand(customer)).Returns(default(Data.ICommand)); var target = new DataSession(provider.Object); try { target.BeginTransaction(); target.Save(customer); } catch (Exception) { Assert.IsTrue(!target.IsTransactionInitiated); } }
public void InitiateTransactionMoreThanOnceThrowsTransactionInstantiatedAlreadyException() { var provider = new IProvider(); var transaction = new Mock<ITransaction>(); provider.CommandExecutor.Setup(c => c.InitiateTransaction()).Returns(transaction.Object); var target = new DataSession(provider.Object); try { target.BeginTransaction(); target.BeginTransaction(); } catch (Exception ex) { Assert.IsTrue(ex is TransactionInstantiatedAlreadyException); } }