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 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 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 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 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 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 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 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 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); }
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() { 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 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 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() { 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 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 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 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 TestNotCalledByBusinessObjectInUpdateObjectBeforePersisting_Deleted() { //-------------Setup Test Pack ------------------ TransactionCommitterStub transactionCommitterStub = new TransactionCommitterStub(); MyBusinessObjectUpdateLogBo myBusinessObjectUpdateLogBo = new MyBusinessObjectUpdateLogBo(); transactionCommitterStub.AddBusinessObject(myBusinessObjectUpdateLogBo); transactionCommitterStub.CommitTransaction(); BusinessObjectUpdateLogStub businessObjectUpdateLog = myBusinessObjectUpdateLogBo.BusinessObjectUpdateLog as BusinessObjectUpdateLogStub; myBusinessObjectUpdateLogBo.MarkForDelete(); transactionCommitterStub = new TransactionCommitterStub(); transactionCommitterStub.AddBusinessObject(myBusinessObjectUpdateLogBo); //-------------Test Pre-conditions -------------- Assert.IsFalse(myBusinessObjectUpdateLogBo.Status.IsNew, "BusinessObject should not be new"); Assert.IsTrue(myBusinessObjectUpdateLogBo.Status.IsDeleted, "BusinessObject should be deleted"); Assert.IsNotNull(businessObjectUpdateLog); businessObjectUpdateLog.Called = false; //-------------Execute test --------------------- myBusinessObjectUpdateLogBo.UpdateObjectBeforePersisting(transactionCommitterStub); //-------------Test Result ---------------------- Assert.IsFalse(businessObjectUpdateLog.Called, "BusinessObject Update Log should have been called upon persisting."); }