예제 #1
0
        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"));
            }
        }
예제 #2
0
        public void Test_BusinessObject_WhenSet_HavingExistingNonSingleRelationshipOnRelatedBO_ShouldThrowError()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            AddressTestBO.LoadDefaultClassDef();
            IClassDef            contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO  contactPersonTestBO   = new ContactPersonTestBO();
            const string         innerRelationshipName = "ContactPersonTestBO";
            const string         outerRelationshipName = "Addresses";
            const string         relationshipName      = outerRelationshipName + "." + innerRelationshipName;
            BORelationshipMapper boRelationshipMapper  = new BORelationshipMapper(relationshipName);

            //---------------Assert Precondition----------------
            Assert.IsNull(boRelationshipMapper.BusinessObject);
            Assert.IsNull(boRelationshipMapper.Relationship);
            //---------------Execute Test ----------------------
            try
            {
                boRelationshipMapper.BusinessObject = contactPersonTestBO;
                Assert.Fail("Expected to throw a HabaneroDeveloperException");
            }
            //---------------Test Result -----------------------
            catch (HabaneroDeveloperException ex)
            {
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on '"
                                      + contactPersonClassDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.", ex.Message);
                StringAssert.Contains("The relationship '" + outerRelationshipName + "' on the BusinessObject '"
                                      + contactPersonClassDef.ClassNameFull + "' is not a Single Relationship therefore cannot be traversed.", ex.DeveloperMessage);
                Assert.IsNull(boRelationshipMapper.BusinessObject);
                Assert.IsNull(boRelationshipMapper.Relationship);
            }
        }
예제 #3
0
        public void TestRemoveRelatedObject_AsBusinessObjectCollection()
        {
            //-----Create Test pack---------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPersonNoAddresses();
            AddressTestBO       address             = contactPersonTestBO.Addresses.CreateBusinessObject();

            address.Save();
            //-------Assert Precondition ------------------------------------
            Assert.AreEqual(1, contactPersonTestBO.Addresses.Count);

            //-----Run tests----------------------------
            BusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;

            addresses.Remove(address);

            ////-----Test results-------------------------
            Assert.AreEqual(1, addresses.RemovedBusinessObjects.Count);
            Assert.AreEqual(0, addresses.Count);
            Assert.IsNull(address.ContactPersonID);
            Assert.IsNull(address.ContactPersonTestBO);
//            Assert.IsTrue(address.Status.IsDeleted);
            Assert.AreEqual(1, addresses.PersistedBusinessObjects.Count);
        }
예제 #4
0
        public void Test_AddNewObject_AddsObjectToCollection_SetsUpForeignKey()
        {
            //---------------Set up test pack-------------------
            //The Foreign Key (address.ContactPersonId) should be set up to be
            // equal to the contactPerson.ContactPersonID
            //SetupTests
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();

            //Run tests
            AddressTestBO address = new AddressTestBO();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, contactPersonTestBO.Addresses.CreatedBusinessObjects.Count);
            Assert.AreEqual(0, contactPersonTestBO.Addresses.Count);
            Assert.AreEqual(0, contactPersonTestBO.Addresses.PersistedBusinessObjects.Count);

            //---------------Execute Test ----------------------
            contactPersonTestBO.Addresses.Add(address);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, contactPersonTestBO.Addresses.CreatedBusinessObjects.Count);
            Assert.AreEqual(0, contactPersonTestBO.Addresses.AddedBusinessObjects.Count);
            Assert.AreEqual(1, contactPersonTestBO.Addresses.Count);
            Assert.AreEqual(0, contactPersonTestBO.Addresses.PersistedBusinessObjects.Count);
            Assert.AreEqual(contactPersonTestBO.ContactPersonID, address.ContactPersonID);
        }
예제 #5
0
        public void Test_CreateBusinessObject_ForeignKeySetUp_BeforeAddedEventFired()
        {
            //---------------Set up test pack-------------------
            //The Foreign Key (address.ContactPersonId) should be set up to be
            // equal to the contactPerson.ContactPersonID before he Added event fires.
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            RelatedBusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;
            AddressTestBO addressFromEvent = null;
            Guid?         addressContactPersonIDFromEvent = null;

            addresses.BusinessObjectAdded += delegate(object sender, BOEventArgs <AddressTestBO> e)
            {
                addressFromEvent = e.BusinessObject;
                addressContactPersonIDFromEvent = addressFromEvent.ContactPersonID;
            };
            //---------------Assert Precondition----------------
            Assert.IsNull(addressFromEvent);
            Assert.IsNull(addressContactPersonIDFromEvent);
            //---------------Execute Test ----------------------
            AddressTestBO address = addresses.CreateBusinessObject();

            //---------------Test Result -----------------------
            Assert.IsNotNull(addressFromEvent);
            Assert.IsNotNull(addressContactPersonIDFromEvent, "Adress.ContactPersonID should have been set before the Added event was called");
            Assert.AreEqual(contactPersonTestBO.ContactPersonID, addressContactPersonIDFromEvent);
            Assert.AreSame(address, addressFromEvent);
            Assert.AreEqual(contactPersonTestBO.ContactPersonID, address.ContactPersonID);
            Assert.IsTrue(address.Status.IsNew);
            Assert.AreEqual(1, addresses.CreatedBusinessObjects.Count);
        }
예제 #6
0
        public void TestTypeOfMultipleCollection()
        {
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            new AddressTestBO();

            ContactPersonTestBO cp = new ContactPersonTestBO();

            Assert.AreSame(typeof(RelatedBusinessObjectCollection <AddressTestBO>), cp.Addresses.GetType());
        }
예제 #7
0
        public void TestReloadingRelationship()
        {
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            new AddressTestBO();

            ContactPersonTestBO       cp        = new ContactPersonTestBO();
            IBusinessObjectCollection addresses = cp.Addresses;

            Assert.AreSame(addresses, cp.Addresses);
        }
예제 #8
0
        public void TestRemoveRelatedObject_SetsRemovedBO()
        {
            //-----Create Test pack---------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPersonNoAddresses();
            RelatedBusinessObjectCollection <AddressTestBO> addresses1 = contactPersonTestBO.Addresses;
            AddressTestBO address = addresses1.CreateBusinessObject();

            address.Save();

            //-----Run tests----------------------------
            RelatedBusinessObjectCollection <AddressTestBO> addresses = addresses1;

            addresses.Remove(address);

            ////-----Test results-------------------------
            Assert.AreSame(contactPersonTestBO, address.Relationships.GetSingle <ContactPersonTestBO>("ContactPersonTestBO").RemovedBO);
        }
예제 #9
0
        public void Test_CreateBusinessObject_ForeignKeySetUp()
        {
            //---------------Set up test pack-------------------
            //The Foreign Key (address.ContactPersonId) should be set up to be
            // equal to the contactPerson.ContactPersonID
            //---------------Assert Precondition----------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            //MultipleRelationship rel = (MultipleRelationship)bo.Relationships["MyMultipleRelationship"];
            //RelatedBusinessObjectCollection<MyRelatedBo> col = new RelatedBusinessObjectCollection<MyRelatedBo>(rel);
            //---------------Execute Test ----------------------
            AddressTestBO address = contactPersonTestBO.Addresses.CreateBusinessObject();

            //---------------Test Result -----------------------
            Assert.AreEqual(contactPersonTestBO.ContactPersonID, address.ContactPersonID);
            Assert.IsTrue(address.Status.IsNew);
            Assert.AreEqual(1, contactPersonTestBO.Addresses.CreatedBusinessObjects.Count);
        }
예제 #10
0
        public void Test_BusinessObject()
        {
            //---------------Set up test pack-------------------
            IEditableGridControl editableGrid = GetControlFactory().CreateEditableGridControl();

            const string propName            = "Addresses";
            EditableGridControlMapper mapper = new EditableGridControlMapper(editableGrid, propName, false, GetControlFactory());

            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            RelatedBusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;

            //---------------Assert PreConditions---------------
            Assert.IsNull(mapper.BusinessObject);

            //---------------Execute Test ----------------------
            mapper.BusinessObject = contactPersonTestBO;
            //---------------Test Result -----------------------
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
            Assert.AreSame(addresses, editableGrid.BusinessObjectCollection);
        }
예제 #11
0
        public void Test_Refresh_PreservesCreateBusObjectCollection()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO bo = new ContactPersonTestBO();
            RelatedBusinessObjectCollection <AddressTestBO> addresses = bo.Addresses;

            addresses.CreateBusinessObject();

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, addresses.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, addresses.Count);
            Assert.AreEqual(0, addresses.PersistedBusinessObjects.Count);

            //---------------Execute Test ----------------------
            addresses.Refresh();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, addresses.CreatedBusinessObjects.Count);
            Assert.AreEqual(1, addresses.Count);
            Assert.AreEqual(0, addresses.PersistedBusinessObjects.Count);
        }
        public void Test_BusinessObject_WhenNull()
        {
            //---------------Set up test pack-------------------
            var readOnlyGrid = GetControlFactory().CreateReadOnlyGrid();

            const string propName = "Addresses";
            var          mapper   = CreateReadOnlyGridMapper(readOnlyGrid, propName);

            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();

            mapper.BusinessObject = contactPersonTestBO;
            RelatedBusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;

            //---------------Assert PreConditions---------------
            Assert.AreSame(contactPersonTestBO, mapper.BusinessObject);
            Assert.AreSame(addresses, readOnlyGrid.BusinessObjectCollection);
            //---------------Execute Test ----------------------
            mapper.BusinessObject = null;
            //---------------Test Result -----------------------
            Assert.IsNull(mapper.BusinessObject);
            Assert.AreSame(null, readOnlyGrid.BusinessObjectCollection);
        }
예제 #13
0
        public void Test_CreateBusinessObject_ForeignKeySetUp_PropertyUpdatedEventNotFired()
        {
            //---------------Set up test pack-------------------
            //The Foreign Key (address.ContactPersonId) should be set up to be
            // equal to the contactPerson.ContactPersonID before he Added event fires.
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO();
            RelatedBusinessObjectCollection <AddressTestBO> addresses = contactPersonTestBO.Addresses;
            bool propetyUpdatedEventFired = false;

            addresses.BusinessObjectPropertyUpdated += delegate {
                propetyUpdatedEventFired = true;
            };
            //---------------Assert Precondition----------------
            Assert.IsFalse(propetyUpdatedEventFired);
            Assert.AreEqual(0, addresses.CreatedBusinessObjects.Count);
            //---------------Execute Test ----------------------
            AddressTestBO address = addresses.CreateBusinessObject();

            //---------------Test Result -----------------------
            Assert.IsFalse(propetyUpdatedEventFired);
            Assert.AreEqual(1, addresses.CreatedBusinessObjects.Count);
        }
        public void ShouldGetValuesFromRelatedObjects_WhenFieldsAreFromOtherClasses()
        {
            //---------------Set up test pack-------------------
            ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated();
            var addClassDef = AddressTestBO.LoadDefaultClassDef();

            var cp1         = CreateContactPersonWithAddress();
            var selectQuery = QueryBuilder.CreateSelectQuery(addClassDef);

            selectQuery.Fields.Clear();
            const string propertyName = "ContactPersonTestBO.Surname";

            selectQuery.Fields.Add(propertyName, QueryBuilder.CreateQueryField(addClassDef, propertyName));
            //---------------Execute Test ----------------------
            var resultSet = _queryResultLoader.GetResultSet(selectQuery);
            //---------------Test Result -----------------------
            var fields = resultSet.Fields.ToList();
            var rows   = resultSet.Rows.ToList();

            Assert.AreEqual(1, fields.Count);
            Assert.AreEqual(1, rows.Count);
            Assert.AreEqual(propertyName, fields[0].PropertyName);
            Assert.AreEqual(cp1.Surname, rows[0].RawValues[0]);
        }