public void TestMessageTwoPersistSimpleBO_Failing() { //---------------Set up test pack------------------- FakeBOWithCustomRule fakeBO = new FakeBOWithCustomRule(); TransactionCommitter committerDB = new TransactionCommitterStub(); committerDB.AddBusinessObject(fakeBO); ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated(); ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPersonNoAddresses(); contactPersonTestBO.Surname = null; committerDB.AddBusinessObject(contactPersonTestBO); //---------------Execute Test ---------------------- try { committerDB.CommitTransaction(); } catch (BusObjectInAnInvalidStateException ex) //---------------Test Result ----------------------- { Assert.IsTrue(ex.Message.Contains(_customRuleErrorMessage)); Assert.IsTrue(ex.Message.Contains("Surname")); } }
public void TestAddTransactionsToATransactionCommiter() { //---------------Set up test pack------------------- TransactionCommitter committer = new TransactionCommitterStub(); //---------------Execute Test ---------------------- committer.AddTransaction(new StubSuccessfullTransaction()); committer.AddTransaction(new StubSuccessfullTransaction()); //---------------Test Result ----------------------- Assert.AreEqual(2, committer.OriginalTransactions.Count); }
public void Test_InsertNull_DoesNotFailInTransactionCommitter() { //---------------Set up test pack------------------- TransactionCommitter committerDB = new TransactionCommitterStub(); //---------------Assert Preconditions--------------- Assert.AreEqual(0, committerDB.OriginalTransactions.Count); //---------------Execute Test ---------------------- committerDB.InsertBusinessObject(null); //---------------Test Result ----------------------- Assert.AreEqual(0, committerDB.OriginalTransactions.Count); }
public void TestUpdateWhenOnlyOneLevelUpdates() { FilledCircle myCircle = new FilledCircle(); TransactionCommitterStub committer = new TransactionCommitterStub(); committer.AddBusinessObject(myCircle); committer.CommitTransaction(); myCircle.SetPropertyValue("Colour", 4); var myUpdateSql = new UpdateStatementGenerator(myCircle, DatabaseConnection.CurrentConnection).Generate(); Assert.AreEqual(1, myUpdateSql.Count()); }
public void TestTransactionLogTransactionNotAddedToTransactionCommitter() { //---------------Set up test pack------------------- //Create Mock Business object that implements a stub transaction log. ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging(); TransactionCommitterStub tc = new TransactionCommitterStub(); tc.AddBusinessObject(cp); Assert.AreEqual(1, tc.OriginalTransactions.Count); //---------------Execute Test ---------------------- //call persist on the object tc.CommitTransaction(); //---------------Test Result ----------------------- //check that the transaction committer has 1 object // i.e. the transaction log object was not added to the transaction. Assert.AreEqual(1, tc.ExecutedTransactions.Count); }
public void TestAddBusinessObjectToTransactionInUpdateBeforePersisting_2LevelsDeep() { //---------------Set up test pack------------------- FakeBOWithUpdateBeforePersistingLevel2 fakeBO = new FakeBOWithUpdateBeforePersistingLevel2(); TransactionCommitterStub committer = new TransactionCommitterStub(); TransactionalBusinessObjectStub trnBusObj = new TransactionalBusinessObjectStub(fakeBO); committer.AddTransaction(trnBusObj); //---------------Execute Test ---------------------- committer.CommitTransaction(); //---------------Test Result ----------------------- Assert.AreEqual(3, committer.OriginalTransactions.Count); }
public void TestUpdateBeforePersisting_ExecutedBeforeValidation() { //---------------Set up test pack------------------- FakeBOWithBeforeSaveUpdatesCompulsoryField fakeBO = new FakeBOWithBeforeSaveUpdatesCompulsoryField(); TransactionCommitterStub committer = new TransactionCommitterStub(); TransactionalBusinessObjectStub trnBusObj = new TransactionalBusinessObjectStub(fakeBO); committer.AddTransaction(trnBusObj); //---------------Execute Test ---------------------- committer.CommitTransaction(); //---------------Test Result ----------------------- //Business object will throw an exception if executed in the incorrect order. Assert.AreEqual(1, committer.OriginalTransactions.Count); }
public void TestAddBusinessObjectToTransaction_NotUpdateBeforePersisting_2LevelsDeep() { //---------------Set up test pack------------------- FakeBOWithUpdateBeforePersistingLevel2 fakeBO = new FakeBOWithUpdateBeforePersistingLevel2(); TransactionCommitterStub committer = new TransactionCommitterStub(); TransactionalBusinessObjectStub trnBusObj = new TransactionalBusinessObjectStub(fakeBO); //---------------Execute Test ---------------------- committer.AddTransaction(trnBusObj); //---------------Test Result ----------------------- Assert.AreEqual(1, committer.OriginalTransactions.Count, "There should only be the recently added business object not any of its object that are added in update before persist"); }
public void TestPersistSimpleBO_Update_NotUsingTransactionalBusinessObject() { //---------------Set up test pack------------------- MockBO fakeBO = CreateSavedMockBO(); Guid mockBOProp1 = Guid.NewGuid(); fakeBO.MockBOProp1 = mockBOProp1; TransactionCommitter committerDB = new TransactionCommitterStub(); committerDB.AddBusinessObject(fakeBO); //---------------Execute Test ---------------------- committerDB.CommitTransaction(); //---------------Test Result ----------------------- TransactionCommitterTestHelper.AssertBOStateIsValidAfterInsert_Updated(fakeBO); }
public void Test_CannotAddSameTransactionToCommitter() { //---------------Set up test pack------------------- TransactionCommitter committer = new TransactionCommitterStub(); StubSuccessfullTransaction transaction = new StubSuccessfullTransaction(); committer.AddTransaction(transaction); //--------------Assert PreConditions---------------- Assert.AreEqual(1, committer.OriginalTransactions.Count); //---------------Execute Test ---------------------- committer.AddTransaction(transaction); //---------------Test Result ----------------------- Assert.AreEqual(1, committer.OriginalTransactions.Count); }
public void TestCalledByBusinessObjectInUpdateObjectBeforePersisting_New() { //-------------Setup Test Pack ------------------ TransactionCommitterStub transactionCommitterStub = new TransactionCommitterStub(); MyBusinessObjectUpdateLogBo myBusinessObjectUpdateLogBo = new MyBusinessObjectUpdateLogBo(); BusinessObjectUpdateLogStub businessObjectUpdateLog = myBusinessObjectUpdateLogBo.BusinessObjectUpdateLog as BusinessObjectUpdateLogStub; transactionCommitterStub.AddBusinessObject(myBusinessObjectUpdateLogBo); //-------------Test Pre-conditions -------------- Assert.IsTrue(myBusinessObjectUpdateLogBo.Status.IsNew, "BusinessObject should be new"); Assert.IsFalse(myBusinessObjectUpdateLogBo.Status.IsDeleted, "BusinessObject should not be deleted"); Assert.IsNotNull(businessObjectUpdateLog); Assert.IsFalse(businessObjectUpdateLog.Called, "BusinessObject Update Log should not have been called upon persisting."); //-------------Execute test --------------------- myBusinessObjectUpdateLogBo.UpdateObjectBeforePersisting(transactionCommitterStub); //-------------Test Result ---------------------- Assert.IsTrue(businessObjectUpdateLog.Called, "BusinessObject Update Log should have been called upon persisting."); }
public void TestCommitAddedTransactions() { //---------------Set up test pack------------------- TransactionCommitter committer = new TransactionCommitterStub(); StubSuccessfullTransaction transactional1 = new StubSuccessfullTransaction(); committer.AddTransaction(transactional1); StubSuccessfullTransaction transactional2 = new StubSuccessfullTransaction(); committer.AddTransaction(transactional2); //---------------Execute Test ---------------------- List <Guid> executedTransactions = committer.CommitTransaction(); //---------------Test Result ----------------------- Assert.AreEqual(2, executedTransactions.Count); Assert.IsTrue(transactional1.Committed); Assert.IsTrue(transactional2.Committed); }
public void TestPersistSimpleBO_FailingCustomRules() { //---------------Set up test pack------------------- FakeBOWithCustomRule fakeBO = new FakeBOWithCustomRule(); TransactionCommitter committerDB = new TransactionCommitterStub(); committerDB.AddBusinessObject(fakeBO); //---------------Execute Test ---------------------- try { committerDB.CommitTransaction(); } catch (BusObjectInAnInvalidStateException ex) //---------------Test Result ----------------------- { Assert.IsTrue(ex.Message.Contains(_customRuleErrorMessage)); } }
public void Test_AddCreatedBO_DoesNotFailInTransactionCommitter() { //---------------Set up test pack------------------- MockBO fakeBO = new MockBO(); Guid mockBOProp1 = Guid.NewGuid(); fakeBO.MockBOProp1 = mockBOProp1; fakeBO.MarkForDelete(); TransactionCommitter committerDB = new TransactionCommitterStub(); //---------------Assert Preconditions--------------- Assert.IsTrue(fakeBO.Status.IsNew); Assert.IsTrue(fakeBO.Status.IsDeleted); Assert.AreEqual(0, committerDB.OriginalTransactions.Count); //---------------Execute Test ---------------------- committerDB.AddBusinessObject(fakeBO); //---------------Test Result ----------------------- Assert.IsTrue(fakeBO.Status.IsNew); Assert.IsTrue(fakeBO.Status.IsDeleted); Assert.AreEqual(0, committerDB.OriginalTransactions.Count); }
public void TestPersistCreated_Deleted_Invalid_BO_DoesNotFailInTransactionCommitter() { //---------------Set up test pack------------------- MockBOWithCompulsoryField mockBo = new MockBOWithCompulsoryField(); mockBo.MockBOProp1 = null; TransactionCommitter committerDB = new TransactionCommitterStub(); committerDB.AddBusinessObject(mockBo); mockBo.MarkForDelete(); //---------------Assert Preconditions--------------- Assert.AreEqual(1, committerDB.OriginalTransactions.Count); Assert.IsTrue(mockBo.Status.IsNew); Assert.IsTrue(mockBo.Status.IsDeleted); //---------------Execute Test ---------------------- committerDB.CommitTransaction(); //---------------Test Result ----------------------- Assert.IsTrue(mockBo.Status.IsNew); Assert.IsTrue(mockBo.Status.IsDeleted); }
public void TestTransactionLogPersistsSQL_NotAddedToBusinessObjectPersistsSql_WhenObjectUnchanged() { //---------------Set up test pack------------------- //Create Mock Business object that implements a stub transaction log. ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging(); TransactionCommitterStub tc = new TransactionCommitterStub(); tc.AddBusinessObject(cp); tc.CommitTransaction(); TransactionalBusinessObjectDB transactionalBODB = new TransactionalBusinessObjectDB(cp, DatabaseConnection.CurrentConnection); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- IEnumerable <ISqlStatement> sqlStatementCollection = transactionalBODB.GetPersistSql(); //---------------Test Result ----------------------- //check if the transaction committer has 2 object // check that the one object is the transaction log object. Assert.AreEqual(0, sqlStatementCollection.Count()); //ISqlStatement sqlStatement = sqlStatementCollection[1]; //TransactionLogTable transactionLogTable = new TransactionLogTable(cp); //Assert.AreEqual(transactionLogTable.GetPersistSql()[0].Statement.ToString(), sqlStatement.Statement.ToString()); }
public void TestCommitAddedTransactions() { //---------------Set up test pack------------------- TransactionCommitter committer = new TransactionCommitterStub(); StubSuccessfullTransaction transactional1 = new StubSuccessfullTransaction(); committer.AddTransaction(transactional1); StubSuccessfullTransaction transactional2 = new StubSuccessfullTransaction(); committer.AddTransaction(transactional2); //---------------Execute Test ---------------------- List<Guid> executedTransactions = committer.CommitTransaction(); //---------------Test Result ----------------------- Assert.AreEqual(2, executedTransactions.Count); Assert.IsTrue(transactional1.Committed); Assert.IsTrue(transactional2.Committed); }
public void TestUpdateWhenOnlyOneLevelUpdates() { IMock connectionControl = new DynamicMock(typeof (IDatabaseConnection)); // IDatabaseConnection connection = (IDatabaseConnection) connectionControl.MockInstance; //connectionControl.ExpectAndReturn("LoadDataReader", null, new object[] {null}); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("GetConnection", DatabaseConnection.CurrentConnection.GetConnection()); //connectionControl.ExpectAndReturn("ExecuteSql", 3, new object[] { null, null }); FilledCircle myCircle = new FilledCircle(); // myCircle.SetDatabaseConnection(connection); TransactionCommitterStub committer = new TransactionCommitterStub(); committer.AddBusinessObject(myCircle); committer.CommitTransaction(); //myCircle.Save(); myCircle.SetPropertyValue("Colour", 4); var myUpdateSql = new UpdateStatementGenerator(myCircle, DatabaseConnection.CurrentConnection).Generate(); Assert.AreEqual(1, myUpdateSql.Count()); connectionControl.Verify(); }
public void TestApplyEditResetsPreviousValues() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); var classDef = MyBO.LoadDefaultClassDef(); var mock = new MockRepository(); var itsConnection = mock.DynamicMock<IDatabaseConnection>(); Expect.Call(itsConnection.GetConnection()).Return(DatabaseConnection.CurrentConnection.GetConnection()). Repeat.Times(2); Expect.Call(itsConnection.ExecuteSql(null, null)).IgnoreArguments().Return(1).Repeat.Times(1); mock.ReplayAll(); var bo = (MyBO) classDef.CreateNewBusinessObject(); bo.SetPropertyValue("TestProp", "Goodbye"); var committer = new TransactionCommitterStub(); committer.AddBusinessObject(bo); //-------------Assert Preconditions ------------- //---------------Execute Test ---------------------- committer.CommitTransaction(); bo.CancelEdits(); //---------------Test Result ----------------------- Assert.AreEqual("Goodbye", bo.GetPropertyValueString("TestProp")); }
public void TestDeleteObjce_WithAfterSaveImplemented() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); IClassDef classDef = AfterSaveBO.LoadDefaultClassDef(); AfterSaveBO bo = (AfterSaveBO) classDef.CreateNewBusinessObject(); bo.FirstPart = "foo"; bo.SecondPart = "bar"; TransactionCommitterStub committer = new TransactionCommitterStub(); committer.AddBusinessObject(bo); committer.CommitTransaction(); //--------------Assert PreConditions---------------- Assert.AreEqual("foobar", bo.CombinedParts); //---------------Execute Test ---------------------- bo.MarkForDelete(); committer = new TransactionCommitterStub(); committer.AddBusinessObject(bo); committer.CommitTransaction(); //---------------Test Result ----------------------- Assert.AreEqual("deleted", bo.CombinedParts); }
public void TestSaveWithBeforeSaveImplemented() { ClassDef.ClassDefs.Clear(); IClassDef classDef = BeforeSaveBo.LoadDefaultClassDef(); BeforeSaveBo bo = (BeforeSaveBo) classDef.CreateNewBusinessObject(); bo.FirstPart = "foo"; bo.SecondPart = "bar"; Assert.AreEqual("", bo.CombinedParts); TransactionCommitterStub committer = new TransactionCommitterStub(); committer.AddBusinessObject(bo); committer.CommitTransaction(); //bo.Save(); Assert.AreEqual("foobar", bo.CombinedParts); //mock.VerifyAll(); }
public void TestUpdateWhenOnlyOneLevelUpdates() { IMock connectionControl = new DynamicMock(typeof (IDatabaseConnection)); IDatabaseConnection connection = (IDatabaseConnection) connectionControl.MockInstance; FilledCircleInheritsCircleNoPK myCircle = new FilledCircleInheritsCircleNoPK(); TransactionCommitterStub committer = new TransactionCommitterStub(); committer.AddBusinessObject(myCircle); committer.CommitTransaction(); myCircle.SetPropertyValue("Colour", 4); var myUpdateSql = new UpdateStatementGenerator(myCircle, DatabaseConnection.CurrentConnection).Generate(); Assert.AreEqual(1, myUpdateSql.Count()); connectionControl.Verify(); }
public void TestTransactionLogPersistsSQL_NotAddedToBusinessObjectPersistsSql_WhenObjectUnchanged() { //---------------Set up test pack------------------- //Create Mock Business object that implements a stub transaction log. ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging(); TransactionCommitterStub tc = new TransactionCommitterStub(); tc.AddBusinessObject(cp); tc.CommitTransaction(); TransactionalBusinessObjectDB transactionalBODB = new TransactionalBusinessObjectDB(cp, DatabaseConnection.CurrentConnection); //---------------Assert Preconditions -------------- //---------------Execute Test ---------------------- IEnumerable<ISqlStatement> sqlStatementCollection = transactionalBODB.GetPersistSql(); //---------------Test Result ----------------------- //check if the transaction committer has 2 object // check that the one object is the transaction log object. Assert.AreEqual(0, sqlStatementCollection.Count()); //ISqlStatement sqlStatement = sqlStatementCollection[1]; //TransactionLogTable transactionLogTable = new TransactionLogTable(cp); //Assert.AreEqual(transactionLogTable.GetPersistSql()[0].Statement.ToString(), sqlStatement.Statement.ToString()); }
public void TestUpdateWhenOnlyOneLevelUpdates() { var myCircle = new FilledCircleInheritsCircleNoPK(); var committer = new TransactionCommitterStub(); committer.AddBusinessObject(myCircle); committer.CommitTransaction(); myCircle.SetPropertyValue("Colour", 4); var myUpdateSql = new UpdateStatementGenerator(myCircle, DatabaseConnection.CurrentConnection).Generate(); Assert.AreEqual(1, myUpdateSql.Count()); }
public void TestPersistSimpleCreatedBO_DoesNotFailInTransactionCommitter() { //---------------Set up test pack------------------- MockBO fakeBO = new MockBO(); Guid mockBOProp1 = Guid.NewGuid(); fakeBO.MockBOProp1 = mockBOProp1; TransactionCommitter committerDB = new TransactionCommitterStub(); committerDB.AddBusinessObject(fakeBO); fakeBO.MarkForDelete(); //---------------Assert Preconditions--------------- Assert.AreEqual(1, committerDB.OriginalTransactions.Count); Assert.IsTrue(fakeBO.Status.IsNew); Assert.IsTrue(fakeBO.Status.IsDeleted); //---------------Execute Test ---------------------- committerDB.CommitTransaction(); //---------------Test Result ----------------------- Assert.IsTrue(fakeBO.Status.IsNew); Assert.IsTrue(fakeBO.Status.IsDeleted); }