public void TestDatabaseTransaction_Failure() { //---------------Set up test pack------------------- TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection); StubDatabaseTransaction transactional1 = new StubDatabaseTransaction(); StubDatabaseFailureTransaction transactional2 = new StubDatabaseFailureTransaction(); committerDB.AddTransaction(transactional1); committerDB.AddTransaction(transactional2); //---------------Execute Test ---------------------- try { committerDB.CommitTransaction(); } catch (NotImplementedException) { } //---------------Test Result ----------------------- Assert.IsFalse(transactional1.Committed); Assert.IsFalse(transactional2.Committed); AssertTransactionsInTableAre(0); }
public void TestDatabaseTransaction_SuccessTwoTransactions() { //---------------Set up test pack------------------- TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection); StubDatabaseTransaction transactional1 = new StubDatabaseTransaction(); StubDatabaseTransaction transactional2 = new StubDatabaseTransaction(); committerDB.AddTransaction(transactional1); committerDB.AddTransaction(transactional2); //---------------Execute Test ---------------------- committerDB.CommitTransaction(); //---------------Test Result ----------------------- AssertTransactionsInTableAre(2); }
public void TestRaisesException_onError_DoesNotCommit() { //---------------Set up test pack------------------- TransactionCommitter committer = new TransactionCommitterStubDB(DatabaseConnection.CurrentConnection); StubDatabaseTransaction transactional1 = new StubDatabaseTransaction(); committer.AddTransaction(transactional1); StubFailingTransaction transactional2 = new StubFailingTransaction(); committer.AddTransaction(transactional2); //---------------Execute Test ---------------------- try { committer.CommitTransaction(); Assert.Fail("Failure should have occurred as a StubFailingTransaction was added"); } //---------------Test Result ----------------------- catch (NotImplementedException) { Assert.IsFalse(transactional1.Committed); Assert.IsFalse(transactional2.Committed); } }