コード例 #1
0
        public void TearDown()
        {
            TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            Criteria criteria1 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "MyShape");
            Criteria criteria2 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "MyShapeChanged");
            Criteria criteria  = new Criteria(criteria1, Criteria.LogicalOp.Or, criteria2);
            BusinessObjectCollection <Shape> shapes =
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <Shape>(criteria, null);

            while (shapes.Count > 0)
            {
                Shape shape = shapes[0];
                shape.MarkForDelete();
                committer.AddBusinessObject(shape);
            }

            criteria1 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "Circle");
            criteria2 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "CircleChanged");
            criteria  = new Criteria(criteria1, Criteria.LogicalOp.Or, criteria2);
            BusinessObjectCollection <CircleNoPrimaryKey> circles
                = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection
                  <CircleNoPrimaryKey>(criteria, null);

            foreach (CircleNoPrimaryKey circle in circles)

            {
                circle.MarkForDelete();
                committer.AddBusinessObject(circle);
            }
            committer.CommitTransaction();
        }
コード例 #2
0
        public void TestAcceptanceTransactionLog_DB_DeleteContactPerson()
        {
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB          tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);

            tc.AddBusinessObject(cp);
            tc.CommitTransaction();
            cp.MarkForDelete();
            tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            var colTransactions =
                new BusinessObjectCollection <TransactionLogBusObj>();

            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            var trLog = colTransactions[colTransactions.Count - 1];

            //CRUD = Deleted
            Assert.AreEqual("Deleted", trLog.CrudAction);

            //---------------Tear Down -------------------------
        }
コード例 #3
0
        public void TestAcceptanceTransactionLog_DB_NewContactPerson()
        {
            //Test that the transaction log
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB          tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);

            tc.AddBusinessObject(cp);
            string dirtyXML = cp.DirtyXML;

            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            BusinessObjectCollection <TransactionLogBusObj> colTransactions =
                new BusinessObjectCollection <TransactionLogBusObj>();

            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            TransactionLogBusObj trLog = colTransactions[colTransactions.Count - 1];

            Assert.AreEqual("Created", trLog.CrudAction);
            Assert.AreEqual(dirtyXML, trLog.DirtyXMLLog);
            Assert.AreEqual("ContactPersonTransactionLogging", trLog.BusinessObjectTypeName);
            //Assert.AreEqual(WindowsIdentity.GetCurrent().Name, trLog.WindowsUser);
            Assert.AreEqual(Environment.MachineName, trLog.MachineUpdatedName);
            //Assert.GreaterOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddMinutes(-1));
            Assert.LessOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddSeconds(1));
            Assert.AreEqual(cp.ToString(), trLog.BusinessObjectToString);
            //---------------Tear Down -------------------------
        }
コード例 #4
0
        public void TearDown()
        {
            TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            Criteria criteria1 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "MyShape");
            Criteria criteria2 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "MyShapeChanged");
            Criteria criteria = new Criteria(criteria1, Criteria.LogicalOp.Or, criteria2);
            BusinessObjectCollection<Shape> shapes = 
                BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection<Shape>(criteria, null);
            while (shapes.Count > 0)
            {
                Shape shape = shapes[0];
                shape.MarkForDelete();
                committer.AddBusinessObject(shape);
            }

            criteria1 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "Circle");
            criteria2 = new Criteria("ShapeName", Criteria.ComparisonOp.Equals, "CircleChanged");
            criteria = new Criteria(criteria1, Criteria.LogicalOp.Or, criteria2);
            BusinessObjectCollection<CircleNoPrimaryKey> circles 
                = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection
                    <CircleNoPrimaryKey>(criteria, null);
            foreach (CircleNoPrimaryKey circle in circles)

            {
                circle.MarkForDelete();
                committer.AddBusinessObject(circle);
            }
            committer.CommitTransaction();
        }
コード例 #5
0
        private static ContactPersonPessimisticLockingDB CreateSavedContactPersonPessimisticLocking()
        {
            ContactPersonPessimisticLockingDB.LoadDefaultClassDef();
            ContactPersonPessimisticLockingDB cp = new ContactPersonPessimisticLockingDB();

            cp.Surname = Guid.NewGuid().ToString();
            TransactionCommitter tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);

            tc.AddBusinessObject(cp);
            tc.CommitTransaction();
            return(cp);
        }
コード例 #6
0
        public void TestAcceptanceTransactionLog_DuplicateAlternativeKeyEntries()
        {
            //---------------Cleanup databse ------------------
            CleanDB();
            ClassDef.ClassDefs.Clear();
            ContactPersonTransactionLogging.LoadClassDef_SurnameAlternateKey();
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp1 = CreateUnsavedContactPersonTransactionLogging();
            const string AltSurname             = "TestAltKey";

            cp1.Surname = AltSurname;
            ContactPersonTransactionLogging cp2 = CreateUnsavedContactPersonTransactionLogging();

            cp2.Surname = AltSurname;

            //---------------Execute Test ----------------------
            TransactionCommitterDB tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);

            tc.AddBusinessObject(cp1);
            tc.AddBusinessObject(cp2);
            try
            {
                tc.CommitTransaction();
                Assert.Fail(
                    "The transaction should not be committed as there are 2 objects in the transaction with the same alternate key");
            }

            //---------------Test Result -----------------------
            catch (BusObjDuplicateConcurrencyControlException)
            {
            }

            //---------------Tear Down -------------------------
            finally
            {
                const string sql = "DELETE FROM Contact_Person where Surname_field = '" + AltSurname + "'";
                DatabaseConnection.CurrentConnection.ExecuteRawSql(sql);
            }
        }
コード例 #7
0
        public void TestAutoIncrementingFieldInNewPrimaryKeyDoesntCheckDuplicates()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            TestAutoInc.LoadClassDefWithAutoIncrementingID();

            TestAutoInc bo = new TestAutoInc();
            bo.SetPropertyValue("testfield", "testing 123");

            MockRepository mockRepos = new MockRepository();
            IBusinessObjectLoader mockBusinessObjectLoader = mockRepos.DynamicMock<IBusinessObjectLoader>();

            Expect.Call(
                mockBusinessObjectLoader.GetBusinessObjectCollection(null, new Criteria("", Criteria.ComparisonOp.Equals, "")))
                .IgnoreArguments()
                .Repeat.Never();

            DataAccessorStub dataAccessor = new DataAccessorStub();
            dataAccessor.BusinessObjectLoader = mockBusinessObjectLoader;

            BORegistry.DataAccessor = dataAccessor;
            mockRepos.ReplayAll();
            TransactionCommitterDB transactionCommitterDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            transactionCommitterDB.AddBusinessObject(bo);

            //---------------Execute Test ----------------------
            transactionCommitterDB.CommitTransaction();

            //---------------Test Result -----------------------
            mockRepos.VerifyAll();

        }
コード例 #8
0
        public void TestPreventDelete_WhenPreventDeleteMessageIsSpecified_OuterExceptionMessageIsSpecifiedPreventDeleteMessage()
        {
            //---------------Set up test pack-------------------
            AddressTestBO address;
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateContactPersonWithOneAddress_PreventDelete(out address);
//            contactPersonTestBO.MarkForDelete();
            var customMessageStart = TestUtil.GetRandomString(30);
            var specialString = customMessageStart + " :: {0}";
            var expectedMessage = String.Format(specialString, contactPersonTestBO.ToString());
            contactPersonTestBO.Relationships["Addresses"].RelationshipDef.PreventDeleteMessage = specialString;
            ReflectionUtilities.SetPropertyValue(contactPersonTestBO.Status, "IsDeleted", true);

            TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddBusinessObject(contactPersonTestBO);
            //---------------Execute Test ----------------------
            try
            {
                committerDB.CommitTransaction();
                Assert.Fail("Expected to throw an BusObjPersistException");
            }
                //---------------Test Result -----------------------
            catch (BusObjPersistException ex)
            {
                Assert.AreEqual(expectedMessage, ex.Message);
            }
        }
コード例 #9
0
 private static ContactPersonTestBO GetSavedContactPersonCompositeKey()
 {
     ContactPersonTestBO contactPersonCompositeKey = GetUnsavedContactPersonCompositeKey();
     TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
     committer.AddBusinessObject(contactPersonCompositeKey);
     committer.CommitTransaction();
     return contactPersonCompositeKey;
 }
コード例 #10
0
        public void TestPersistSimpleBO_Update_NotUsingTransactionalBusinessObject_DB()
        {
            //---------------Set up test pack-------------------
            MockBO mockBo = CreateSavedMockBO();
            Guid mockBOProp1 = Guid.NewGuid();
            mockBo.MockBOProp1 = mockBOProp1;
            TransactionCommitter committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddBusinessObject(mockBo);

            //---------------Execute Test ----------------------
            committerDB.CommitTransaction();

            //---------------Test Result -----------------------
            TransactionCommitterTestHelper.AssertBOStateIsValidAfterInsert_Updated(mockBo);
            BORegistry.DataAccessor.BusinessObjectLoader.Refresh(mockBo);
            Assert.AreEqual(mockBOProp1, mockBo.MockBOProp1);
        }
コード例 #11
0
        public void TestPreventDelete()
        {
            //---------------Set up test pack-------------------
            AddressTestBO address;
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateContactPersonWithOneAddress_PreventDelete(out address);
//            contactPersonTestBO.MarkForDelete();
            ReflectionUtilities.SetPropertyValue(contactPersonTestBO.Status, "IsDeleted", true);

            TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddBusinessObject(contactPersonTestBO);
            //---------------Execute Test ----------------------
            try
            {
                committerDB.CommitTransaction();
                Assert.Fail("Expected to throw an BusObjPersistException");
            }
                //---------------Test Result -----------------------
            catch (BusObjPersistException ex)
            {
                StringAssert.Contains("You cannot delete ContactPersonTestBO identified by ", ex.Message);
            }
            //---------------Test Result -----------------------
        }
コード例 #12
0
        public void Test3LayerDeleteRelated_WithDeletedObjectChildAndGrandchild()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            OrganisationTestBO.LoadDefaultClassDef_WithMultipleRelationshipToAddress();
            AddressTestBO address;
            var contactPersonTestBO = CreateContactPersonWithOneAddress(out address);

            var org = new OrganisationTestBO();
            contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID);
            org.Save();
            contactPersonTestBO.Save();
            address.OrganisationID = org.OrganisationID;
            address.Save();
            org.MarkForDelete();

            TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committer.AddBusinessObject(org);

            //---------------Assert Precondition----------------
            //Assert.AreEqual(1, org.ContactPeople.Count);
            Assert.AreEqual(0, org.ContactPeople.Count);
            Assert.AreEqual(1, org.ContactPeople.MarkedForDeleteBusinessObjects.Count);
            Assert.AreEqual(0, ((IMultipleRelationship) org.Relationships["Addresses"]).BusinessObjectCollection.Count);
            Assert.AreEqual(1, ((IMultipleRelationship) org.Relationships["Addresses"]).BusinessObjectCollection.MarkedForDeleteBusinessObjects.Count);
            Assert.AreEqual(0, contactPersonTestBO.Addresses.Count);
            Assert.AreEqual(1, contactPersonTestBO.Addresses.MarkedForDeleteBusinessObjects.Count);
            Assert.AreEqual(2, org.Relationships.Count);
            Assert.IsTrue(org.Relationships.Contains("ContactPeople"));
            Assert.AreEqual(DeleteParentAction.DeleteRelated, org.Relationships["ContactPeople"].DeleteParentAction);
            Assert.AreEqual(DeleteParentAction.DeleteRelated, org.Relationships["Addresses"].DeleteParentAction);

            //---------------Execute Test ----------------------

            committer.CommitTransaction();
            //---------------Test Result -----------------------
            BOTestUtils.AssertBOStateIsValidAfterDelete(org);
            BOTestUtils.AssertBOStateIsValidAfterDelete(contactPersonTestBO);
            BOTestUtils.AssertBOStateIsValidAfterDelete(address);

            AssertBusinessObjectNotInDatabase(org);
            AssertBusinessObjectNotInDatabase(contactPersonTestBO);
            AssertBusinessObjectNotInDatabase(address);
        }
コード例 #13
0
 public void TestNotPreventDelete_ForNonDeleted()
 {
     //---------------Set up test pack-------------------
     AddressTestBO address;
     ContactPersonTestBO contactPersonTestBO =
         ContactPersonTestBO.CreateContactPersonWithOneAddress_PreventDelete(out address);
     contactPersonTestBO.FirstName = Guid.NewGuid().ToString();
     TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
     committerDB.AddBusinessObject(contactPersonTestBO);
     //---------------Execute Test ----------------------
     committerDB.CommitTransaction();
     //---------------Test Result -----------------------
     Assert.IsFalse(contactPersonTestBO.Status.IsDirty);
 }
コード例 #14
0
        public void TestAcceptanceTransactionLog_DB_DeleteContactPerson()
        {
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            tc.CommitTransaction();
            cp.MarkForDelete();
            tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            var colTransactions =
                new BusinessObjectCollection<TransactionLogBusObj>();
            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            var trLog = colTransactions[colTransactions.Count - 1];

            //CRUD = Deleted
            Assert.AreEqual("Deleted", trLog.CrudAction);

            //---------------Tear Down -------------------------          
        }
コード例 #15
0
        public void TestAcceptanceTransactionLog_DB_NewContactPerson()
        {
            //Test that the transaction log 
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp = CreateUnsavedContactPersonTransactionLogging();
            TransactionCommitterDB tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp);
            string dirtyXML = cp.DirtyXML;
            //---------------Execute Test ----------------------
            tc.CommitTransaction();
            //---------------Test Result -----------------------
            //Test that a transaction Log was created with
            BusinessObjectCollection<TransactionLogBusObj> colTransactions =
                new BusinessObjectCollection<TransactionLogBusObj>();
            colTransactions.LoadAll("TransactionSequenceNo");

            //CRUD = Insert and Dirty XML all properties in DirtyXML.
            Assert.IsTrue(colTransactions.Count > 0);
            TransactionLogBusObj trLog = colTransactions[colTransactions.Count - 1];
            Assert.AreEqual("Created", trLog.CrudAction);
            Assert.AreEqual(dirtyXML, trLog.DirtyXMLLog);
            Assert.AreEqual("ContactPersonTransactionLogging", trLog.BusinessObjectTypeName);
            //Assert.AreEqual(WindowsIdentity.GetCurrent().Name, trLog.WindowsUser);
            Assert.AreEqual(Environment.MachineName, trLog.MachineUpdatedName);
            //Assert.GreaterOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddMinutes(-1));
            Assert.LessOrEqual(trLog.DateTimeUpdated, DateTime.Now.AddSeconds(1));
            Assert.AreEqual(cp.ToString(),trLog.BusinessObjectToString);
            //---------------Tear Down -------------------------          
        }
コード例 #16
0
        public void TestDeleteDoNothing()
        {
            //---------------Set up test pack-------------------
            AddressTestBO address;
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateContactPersonWithOneAddress_DeleteDoNothing(out address);
            contactPersonTestBO.MarkForDelete();
            TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddBusinessObject(contactPersonTestBO);

            //---------------Execute Test ----------------------
            try
            {
                committerDB.CommitTransaction();
                Assert.Fail("Delete should fail as there is referential integrity and the delete action is 'Do Nothing'");
            }
            catch (DatabaseWriteException ex)
            {
                StringAssert.Contains("There was an error writing to the database", ex.Message);
            }
            //---------------Test Result -----------------------
        }
コード例 #17
0
        public void TestDeleteRelated()
        {
            //---------------Set up test pack-------------------
            AddressTestBO address;
            var contactPersonTestBO = CreateContactPersonWithOneAddress(out address);

            contactPersonTestBO.MarkForDelete();
            var committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddBusinessObject(contactPersonTestBO);

            //---------------Execute Test ----------------------
            committerDB.CommitTransaction();

            //---------------Test Result -----------------------
            BOTestUtils.AssertBOStateIsValidAfterDelete(contactPersonTestBO);
            BOTestUtils.AssertBOStateIsValidAfterDelete(address);

            AssertBusinessObjectNotInDatabase(contactPersonTestBO);
            AssertBusinessObjectNotInDatabase(address);
        }
コード例 #18
0
 public void TestCompositePrimaryUpdatesOrigObjectIDAfterSaving()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadClassDefWithCompositePrimaryKeyNameSurname();
     ContactPersonTestBO contactPersonCompositeKey = new ContactPersonTestBO();
     string oldID = contactPersonCompositeKey.ID.AsString_CurrentValue();
     contactPersonCompositeKey.ContactPersonID = Guid.NewGuid();
     contactPersonCompositeKey.Surname = "Somebody";
     contactPersonCompositeKey.FirstName = "Else";
     TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
     committer.AddBusinessObject(contactPersonCompositeKey);
     //---------------Execute Test ----------------------
     committer.CommitTransaction();
     //---------------Test Result -----------------------
     IPrimaryKey objectID = contactPersonCompositeKey.ID;
     Assert.AreNotEqual(oldID, objectID.AsString_CurrentValue());
     Assert.IsTrue(BORegistry.BusinessObjectManager.Contains(contactPersonCompositeKey.ID.ObjectID));
 }
コード例 #19
0
 public void Test_DoNotChangeChangeCompositePrimaryKey()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadClassDefWithCompositePrimaryKeyNameSurname();
     ContactPersonTestBO contactPersonCompositeKey = GetSavedContactPersonCompositeKey();
     //            string oldID = contactPersonCompositeKey.ID.AsString_CurrentValue();
     //            Assert.IsNotNull(BusinessObjectManager.Instance[oldID]);
     TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
     committer.AddBusinessObject(contactPersonCompositeKey);
     string origFirstname = contactPersonCompositeKey.FirstName;
     contactPersonCompositeKey.FirstName = "Temp Firstname";
     contactPersonCompositeKey.FirstName = origFirstname;
     IBOProp prop = contactPersonCompositeKey.Props["FirstName"];
     //---------------Assert Precondition----------------
     Assert.IsFalse(prop.IsDirty);
     //---------------Execute Test ----------------------
     committer.CommitTransaction();
     //---------------Test Result -----------------------
     TransactionCommitterTestHelper.AssertBOStateIsValidAfterInsert_Updated(contactPersonCompositeKey);
     //            Assert.IsFalse(BusinessObjectManager.Instance.Contains(oldID));
     //            Assert.IsNotNull(BusinessObjectManager.Instance[contactPersonCompositeKey.ID.AsString_CurrentValue()]);
     //            //---------------Tear Down--------------------------
     //            contactPersonCompositeKey.MarkForDelete();
     //            contactPersonCompositeKey.Save();
 }
コード例 #20
0
 public void TestChangeCompositePrimaryKey()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadClassDefWithCompositePrimaryKeyNameSurname();
     ContactPersonTestBO contactPersonCompositeKey = GetSavedContactPersonCompositeKey();
     Guid oldID = contactPersonCompositeKey.ID.ObjectID;
     Assert.IsNotNull(BORegistry.BusinessObjectManager[oldID]);
     TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
     committer.AddBusinessObject(contactPersonCompositeKey);
     contactPersonCompositeKey.FirstName = "newName";
     //---------------Execute Test ----------------------
     committer.CommitTransaction();
     //---------------Test Result -----------------------
     TransactionCommitterTestHelper.AssertBOStateIsValidAfterInsert_Updated(contactPersonCompositeKey);
     Assert.IsTrue(BORegistry.BusinessObjectManager.Contains(oldID));
     Assert.IsNotNull(BORegistry.BusinessObjectManager[contactPersonCompositeKey.ID.ObjectID]);
     //---------------Tear Down--------------------------
     contactPersonCompositeKey.MarkForDelete();
     contactPersonCompositeKey.Save();
 }
		private static ContactPersonPessimisticLockingDB CreateSavedContactPersonPessimisticLocking()
		{
			ContactPersonPessimisticLockingDB.LoadDefaultClassDef();
			ContactPersonPessimisticLockingDB cp = new ContactPersonPessimisticLockingDB();
			cp.Surname = Guid.NewGuid().ToString();
			TransactionCommitter tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
			tc.AddBusinessObject(cp);
			tc.CommitTransaction();
			return cp;
		}
コード例 #22
0
 private static void DoTestCheckForDuplicateObjects()
 {
     ContactPersonTestBO contactPersonCompositeKey = GetSavedContactPersonCompositeKey();
     FixtureEnvironment.ClearBusinessObjectManager();
     ContactPersonTestBO duplicateContactPerson = new ContactPersonTestBO
                                                      {
                                                          ContactPersonID = Guid.NewGuid(),
                                                          Surname = contactPersonCompositeKey.Surname,
                                                          FirstName = contactPersonCompositeKey.FirstName
                                                      };
     TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
     committer.AddBusinessObject(duplicateContactPerson);
     //---------------Execute Test ----------------------
     try
     {
         committer.CommitTransaction();
         Assert.Fail();
     }
         //---------------Test Result -----------------------
     catch (BusObjDuplicateConcurrencyControlException ex)
     {
         StringAssert.Contains("Surname", ex.Message);
         StringAssert.Contains("FirstName", ex.Message);
     }
     finally
     {
         //---------------Tear Down--------------------------
         contactPersonCompositeKey.MarkForDelete();
         contactPersonCompositeKey.Save();
         if (!duplicateContactPerson.Status.IsNew)
         {
             duplicateContactPerson.MarkForDelete();
             duplicateContactPerson.Save();
         }
     }
 }
コード例 #23
0
 public void TestDeleteRelated_WhenCircularDelete_ShouldResolve()
 {
     //---------------Set up test pack-------------------
     Entity.LoadDefaultClassDef_WithCircularDeleteRelatedToSelf();
     Entity entity1 = new Entity();
     Entity entity2 = new Entity();
     entity1.Relationships.SetRelatedObject("RelatedEntity", entity2);
     entity2.Relationships.SetRelatedObject("RelatedEntity", entity1);
     entity1.Save();
     entity2.Save();
     entity1.MarkForDelete();
     TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
     committer.AddBusinessObject(entity1);
     //---------------Execute Test ----------------------
     committer.CommitTransaction();
     //---------------Test Result -----------------------
     BOTestUtils.AssertBOStateIsValidAfterDelete(entity1);
     BOTestUtils.AssertBOStateIsValidAfterDelete(entity2);
     AssertBusinessObjectNotInDatabase(entity1);
     AssertBusinessObjectNotInDatabase(entity2);
 }
コード例 #24
0
        public void Test3LayerDeleteRelated()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            BORegistry.DataAccessor = new DataAccessorDB();
            OrganisationTestBO.LoadDefaultClassDef();
            AddressTestBO address;
            var contactPersonTestBO = CreateContactPersonWithOneAddress(out address);

            var org = new OrganisationTestBO();
            contactPersonTestBO.SetPropertyValue("OrganisationID", org.OrganisationID);
            org.Save();
            contactPersonTestBO.Save();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1,org.ContactPeople.Count);
            Assert.AreEqual(1, contactPersonTestBO.Addresses.Count);
            Assert.AreEqual(1, org.Relationships.Count);
            Assert.IsTrue(org.Relationships.Contains("ContactPeople"));
            Assert.AreEqual(DeleteParentAction.DeleteRelated, org.Relationships["ContactPeople"].DeleteParentAction);
            //---------------Execute Test ----------------------
            //IBusinessObjectCollection colContactPeople = org.Relationships["ContactPeople"].GetRelatedBusinessObjectCol();
            //ContactPersonTestBO loadedCP = (ContactPersonTestBO)colContactPeople[0];
            //IBusinessObjectCollection colAddresses = loadedCP.Relationships["Addresses"].GetRelatedBusinessObjectCol();
            //Address loadedAdddress = (Address)colAddresses[0];

            org.MarkForDelete();

            TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committer.AddBusinessObject(org);
            committer.CommitTransaction();

            //---------------Test Result -----------------------
            //Assert.AreSame(contactPersonTestBO, loadedCP);
            //Assert.AreSame(address, loadedAdddress);

            AssertBusinessObjectNotInDatabase(org);
            AssertBusinessObjectNotInDatabase(contactPersonTestBO);
            AssertBusinessObjectNotInDatabase(address);

            BOTestUtils.AssertBOStateIsValidAfterDelete(org);
            BOTestUtils.AssertBOStateIsValidAfterDelete(contactPersonTestBO);
            BOTestUtils.AssertBOStateIsValidAfterDelete(address);
        }
コード例 #25
0
        public void TestAcceptanceTransactionLog_DuplicateAlternativeKeyEntries()
        {
            //---------------Cleanup databse ------------------
            CleanDB();
            ClassDef.ClassDefs.Clear();
            ContactPersonTransactionLogging.LoadClassDef_SurnameAlternateKey();
            //---------------Set up test pack-------------------
            ContactPersonTransactionLogging cp1 = CreateUnsavedContactPersonTransactionLogging();
            const string AltSurname = "TestAltKey";
            cp1.Surname = AltSurname;
            ContactPersonTransactionLogging cp2 = CreateUnsavedContactPersonTransactionLogging();
            cp2.Surname = AltSurname;

            //---------------Execute Test ----------------------
            TransactionCommitterDB tc = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            tc.AddBusinessObject(cp1);
            tc.AddBusinessObject(cp2);
            try
            {
                tc.CommitTransaction();
                Assert.Fail(
                    "The transaction should not be committed as there are 2 objects in the transaction with the same alternate key");
            }
               
                //---------------Test Result -----------------------
            catch (BusObjDuplicateConcurrencyControlException)
            {
            }

                //---------------Tear Down -------------------------   
            finally
            {
                const string sql = "DELETE FROM Contact_Person where Surname_field = '" + AltSurname + "'";
                DatabaseConnection.CurrentConnection.ExecuteRawSql(sql);
            }
        }
コード例 #26
0
        public void TestStorePersistedValue_BOProp()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDef();
            ContactPersonTestBO cp = new ContactPersonTestBO();
            cp.Surname = Guid.NewGuid().ToString();
            cp.Save();
            cp.Surname = Guid.NewGuid().ToString();
            TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committer.AddBusinessObject(cp);

            //---------------Execute Test ----------------------
            committer.CommitTransaction();
            //---------------Test Result -----------------------
            Assert.AreEqual(cp.Surname, cp.Props["Surname"].PersistedPropertyValueString);
        }
コード例 #27
0
        public void TestDeleteRelatedWithFailure_CancelEditsOnParent()
        {
            //---------------Set up test pack-------------------
            AddressTestBO address;
            ContactPersonTestBO contactPersonTestBO =
                ContactPersonTestBO.CreateContactPersonWithOneAddress_CascadeDelete(out address, TestUtil.GetRandomString());
            contactPersonTestBO.MarkForDelete();
            TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddBusinessObject(contactPersonTestBO);
            committerDB.AddTransaction(new StubDatabaseFailureTransaction());

            try
            {
                committerDB.CommitTransaction();
                Assert.Fail();
            }
            catch (NotImplementedException)
            {
            }

            //---------------Execute Test ----------------------
            contactPersonTestBO.CancelEdits();

            //---------------Test Result -----------------------
            Assert.IsFalse(contactPersonTestBO.Status.IsEditing);
            Assert.IsFalse(contactPersonTestBO.Status.IsDeleted);

            Assert.Ignore(
                "This test is being ignored due to the fact that we do not have a philosophy for compositional parents deleting their children etc");
            Assert.IsFalse(address.Status.IsEditing);
            Assert.IsFalse(address.Status.IsDeleted);
        }
コード例 #28
0
        public void CommitTransaction_WhenBoHasStringPropWithLengthGreaterThanDbField_ShouldRollbackConcurrencyStrategy_FixBugBug_2136()
        {
            //---------------Set up test pack-------------------
            TransactionCommitter committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            var temp = new NumberGeneratorPessimisticLockingImpl("tmp");
            temp.CallReleaseLocks();
            var pessimisticLocking = new NumberGeneratorPessimisticLockingImpl("tmp");

            var mockBO = new MockBO
                             {
                                 // force a database write exception as MockBOProp2 only allows varchar(50)
                                 MockBOProp2 = RandomValueGen.GetRandomString(51, 55)
                             };
            committer.AddBusinessObject(mockBO);
            pessimisticLocking.AddToTransaction(committer);
            var nextNumber = pessimisticLocking.NextNumber();
            //---------------Assert Precondition----------------
            Assert.IsTrue(pessimisticLocking.BoSequenceNumber.Status.IsDirty);
            Assert.IsFalse(pessimisticLocking.BoSequenceNumber.Props["Locked"].IsDirty);
            Assert.Greater(nextNumber, 0);
            Assert.Greater(mockBO.MockBOProp2.Length, 50);
            //---------------Execute Test ----------------------
            try
            {
                committer.CommitTransaction();
                //---------------Test Result -----------------------
                Assert.Fail("Expected to throw an DatabaseWriteException");
            }
            catch (DatabaseWriteException ex)
            {
                StringAssert.Contains("There was an error writing to the database", ex.Message);
            }

            //---------------Test Result -----------------------
            Assert.AreEqual(nextNumber, pessimisticLocking.NextNumber());


        }
コード例 #29
0
        public void TestDeleteRelatedWithFailureAfter()
        {
            //---------------Set up test pack-------------------
            AddressTestBO address;          
            var contactPersonTestBO = CreateContactPersonWithOneAddress(out address);

            contactPersonTestBO.MarkForDelete();
            TransactionCommitterDB committerDB = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committerDB.AddBusinessObject(contactPersonTestBO);
            committerDB.AddTransaction(new StubDatabaseFailureTransaction());

            //---------------Execute Test ----------------------
            try
            {
                committerDB.CommitTransaction();
                Assert.Fail();
            }
            catch (NotImplementedException)
            {
            }
            //---------------Test Result -----------------------
            AssertBusinessObjectInDatabase(contactPersonTestBO);
            AssertBusinessObjectInDatabase(address);

            Assert.IsTrue(address.Status.IsDeleted);
            Assert.IsTrue(address.Status.IsEditing);
            Assert.IsFalse(address.Status.IsNew);
            Assert.IsTrue(contactPersonTestBO.Status.IsDeleted);
            Assert.IsTrue(contactPersonTestBO.Status.IsEditing);
            Assert.IsFalse(contactPersonTestBO.Status.IsNew);
        }
コード例 #30
0
        public void TestSearchForChildrenToDeleteWithChildDeletedInTransaction()
        {
            //---------------Set up test pack-------------------
            AddressTestBO address;
            var contactPersonTestBO = CreateContactPersonWithOneAddress(out address);
            //---------------Execute Test ----------------------
            address.MarkForDelete();
            contactPersonTestBO.MarkForDelete();
            TransactionCommitterDB committer = new TransactionCommitterDB(DatabaseConnection.CurrentConnection);
            committer.AddBusinessObject(address);
            committer.AddBusinessObject(contactPersonTestBO);
            committer.CommitTransaction();
            //---------------Test Result -----------------------

            BOTestUtils.AssertBOStateIsValidAfterDelete(address);
            BOTestUtils.AssertBOStateIsValidAfterDelete(contactPersonTestBO);
            //---------------Tear Down -------------------------          
        }