Example #1
0
        /// <summary>
        /// Verifies that any <see cref="TransactionalBusinessObject"/>'s that are marked for deletion
        ///   can be deleted. <see cref="TransactionalBusinessObject.CheckCanDelete"/>
        /// </summary>
        private void ValidateObjectsCanBeDeleted()
        {
            string allMessages = "";

            foreach (ITransactional transaction in _originalTransactions)
            {
                if (!(transaction is TransactionalBusinessObject))
                {
                    continue;
                }
                TransactionalBusinessObject trnBusObj = (TransactionalBusinessObject)transaction;

                if (!trnBusObj.IsDeleted)
                {
                    continue;
                }

                string errMsg;

                if (!trnBusObj.CheckCanDelete(out errMsg))
                {
                    allMessages = Util.StringUtilities.AppendMessage(allMessages, errMsg);
                }
            }
            if (!string.IsNullOrEmpty(allMessages))
            {
                throw new BusinessObjectReferentialIntegrityException(allMessages);
            }
        }
Example #2
0
        /// <summary>
        /// Verifies that any <see cref="TransactionalBusinessObject"/>'s that are marked can be persisted
        ///   can be deleted. <see cref="TransactionalBusinessObject.CheckCanDelete"/>
        /// </summary>
        private void CheckTransactionsCanBePersisted()
        {
            string allMessages = "";

            foreach (ITransactional transaction in _originalTransactions)
            {
                if (!(transaction is TransactionalBusinessObject))
                {
                    continue;
                }
                TransactionalBusinessObject trnBusObj = (TransactionalBusinessObject)transaction;
                if (trnBusObj.BusinessObject.Status.IsNew && trnBusObj.BusinessObject.Status.IsDeleted)
                {
                    continue;
                }
                string errMsg;
                if (!trnBusObj.CanBePersisted(out errMsg))
                {
                    allMessages = Util.StringUtilities.AppendMessage(allMessages, errMsg);
                }
            }
            if (!string.IsNullOrEmpty(allMessages))
            {
                throw new BusObjPersistException(allMessages);
            }
        }
Example #3
0
 private void UpdateObjectBeforePersisting(TransactionalBusinessObject transaction, bool added)
 {
     if (added && _runningUpdatingBeforePersisting)
     {
         transaction.UpdateObjectBeforePersisting(this);
     }
 }
        public void Test_BusinessObject_TransactionID()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = MyBO.LoadDefaultClassDef_CompulsoryField_TestProp();
            BusinessObject bo = (BusinessObject)classDef.CreateNewBusinessObject();
            TransactionalBusinessObject transactionalBusinessObject = new TransactionalBusinessObject(bo);
            
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string transactionID = transactionalBusinessObject.TransactionID();
            //---------------Test Result -----------------------
            Assert.AreEqual(bo.ID.ObjectID.ToString(), transactionID);
        }
 public void Test_BusinessObject_TrySaveThrowsUserError_IfValidateFails()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Clear();
     IClassDef classDef = MyBO.LoadDefaultClassDef_CompulsoryField_TestProp();
     BusinessObject bo = (BusinessObject) classDef.CreateNewBusinessObject();
     TransactionalBusinessObject transactionalBusinessObject = new TransactionalBusinessObject(bo);
     //---------------Assert Precondition----------------
     
     //---------------Execute Test ----------------------
     string invalidReason;
     bool valid = transactionalBusinessObject.IsValid(out invalidReason);
     //---------------Test Result -----------------------
     StringAssert.Contains("Test Prop' is a compulsory field and has no value", invalidReason);
     Assert.IsFalse(valid);
     Assert.IsFalse(bo.Status.IsValid());
 }
Example #6
0
        /// <summary>
        /// Check that the object is in a valid state i.e. no <see cref="IPropRule"/>'s are broken.
        /// </summary>
        private void CheckObjectsAreValid()
        {
            string allMessages = "";

            foreach (ITransactional transaction in _originalTransactions)
            {
                if (!(transaction is TransactionalBusinessObject))
                {
                    continue;
                }
                TransactionalBusinessObject trnBusObj = (TransactionalBusinessObject)transaction;

                string errMsg;
                if (!trnBusObj.IsValid(out errMsg))
                {
                    allMessages = Util.StringUtilities.AppendMessage(allMessages, errMsg);
                }
            }

            if (!string.IsNullOrEmpty(allMessages))
            {
                throw new BusObjectInAnInvalidStateException(allMessages);
            }
        }
        public void Test_BusinessObject_TransactionID_CompositeKey()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithCompositePrimaryKey();
            ContactPersonTestBO bo = ContactPersonTestBO.CreateUnsavedContactPerson_NoFirstNameProp();
            TransactionalBusinessObject transactionalBusinessObject = new TransactionalBusinessObject(bo);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string transactionID = transactionalBusinessObject.TransactionID();
            //---------------Test Result -----------------------
            Assert.AreEqual(bo.ID.ObjectID.ToString(), transactionID);
        }
        public void Test_CheckDuplicateIdentifier_WhenTransactionCommitterHasAddedBOAndUpdatedBOWithSameUniqueKey_ShouldReturnError()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadDefaultClassDefWithKeyOnSurname();
            var surname = BOTestUtils.RandomString;
            var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(BOTestUtils.RandomString, BOTestUtils.RandomString);
            contactPersonTestBO.Save();
            contactPersonTestBO.Surname = surname;

            var transactionalBusinessObject = new TransactionalBusinessObject(contactPersonTestBO);
            var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);
            var transactionalBusinessObjectDuplicate = new TransactionalBusinessObject(newContactPersonTestBOWithSameSurname);
            var pendingTransactions = new List<ITransactional> { transactionalBusinessObject, transactionalBusinessObjectDuplicate };
            //---------------Assert Precondition----------------
            Assert.IsFalse(contactPersonTestBO.Status.IsNew);
            Assert.IsTrue(contactPersonTestBO.Status.IsDirty);
            Assert.IsTrue(newContactPersonTestBOWithSameSurname.Status.IsNew);
            Assert.AreEqual(surname, contactPersonTestBO.Surname);
            Assert.AreEqual(surname, newContactPersonTestBOWithSameSurname.Surname);
            //---------------Execute Test ----------------------
            var errorMessages = new List<string>();
            transactionalBusinessObject.CheckDuplicateIdentifier(pendingTransactions, errorMessages);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, errorMessages.Count);
            Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}.", surname), errorMessages[0]);
        }
 public void Test_CheckDuplicateIdentifier_WhenTransactionCommitterHasAddedBOsWithSamePrimaryKey_ShouldReturnError()
 {
     //---------------Set up test pack-------------------
     ContactPersonTestBO.LoadClassDefWithCompositePrimaryKeyNameSurname();
     var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson();
     var surname = contactPersonTestBO.Surname;
     var firstName = contactPersonTestBO.FirstName;
     var transactionalBusinessObject = new TransactionalBusinessObject(contactPersonTestBO);
     var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, firstName);
     var transactionalBusinessObjectDuplicate = new TransactionalBusinessObject(newContactPersonTestBOWithSameSurname);
     var pendingTransactions = new List<ITransactional> { transactionalBusinessObject, transactionalBusinessObjectDuplicate };
     //---------------Assert Precondition----------------
     Assert.IsTrue(contactPersonTestBO.Status.IsNew);
     Assert.IsTrue(newContactPersonTestBOWithSameSurname.Status.IsNew);
     Assert.AreEqual(contactPersonTestBO.FirstName, newContactPersonTestBOWithSameSurname.FirstName);
     Assert.AreEqual(contactPersonTestBO.Surname, newContactPersonTestBOWithSameSurname.Surname);
     //---------------Execute Test ----------------------
     var errorMessages = new List<string>();
     transactionalBusinessObject.CheckDuplicateIdentifier(pendingTransactions, errorMessages);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, errorMessages.Count);
     Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}, FirstName = {1}.", surname, firstName), errorMessages[0]);
 }
 public void Test_CheckDuplicateIdentifier_WhenTransactionCommitterHasAddedBOWithSameUniqueKeyAsMarkedForDeleteBO_WhenDeletedBONotInPendingTransactions_ShouldReturnError()
 {
     //---------------Set up test pack-------------------
     BORegistry.BusinessObjectManager = new BusinessObjectManagerNull();
     ContactPersonTestBO.LoadDefaultClassDefWithKeyOnSurname();
     var surname = BOTestUtils.RandomString;
     var contactPersonTestBO = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);
     contactPersonTestBO.Save();
     contactPersonTestBO.MarkForDelete();
     var transactionalBusinessObjectForDeletedDuplicate = new TransactionalBusinessObject(contactPersonTestBO);
     var newContactPersonTestBOWithSameSurname = ContactPersonTestBO.CreateUnsavedContactPerson(surname, BOTestUtils.RandomString);
     var transactionalBusinessObject = new TransactionalBusinessObject(newContactPersonTestBOWithSameSurname);
     var pendingTransactions = new List<ITransactional> { transactionalBusinessObject };
     //---------------Assert Precondition----------------
     Assert.IsFalse(transactionalBusinessObjectForDeletedDuplicate.IsNew());
     Assert.IsTrue(transactionalBusinessObjectForDeletedDuplicate.IsDeleted);
     Assert.IsTrue(transactionalBusinessObject.IsNew());
     Assert.IsFalse(transactionalBusinessObject.IsDeleted);
     Assert.AreEqual(surname, contactPersonTestBO.Props["Surname"].PersistedPropertyValueString);
     //---------------Execute Test ----------------------
     var errorMessages = new List<string>();
     transactionalBusinessObject.CheckDuplicateIdentifier(pendingTransactions, errorMessages);
     //---------------Test Result -----------------------
     Assert.AreEqual(1, errorMessages.Count);
     Assert.AreEqual(string.Format("A 'Contact Person Test BO' already exists with the same identifier: Surname = {0}.", surname), errorMessages[0]);
 }