コード例 #1
0
        public override void Test_ApplyChangesToBusinessObject_WhenNewItemIsSelected_WhenSet_WhenRelationshipIsLevelsDeep_ShouldUpdateRelatedBusinessObjectWithSelectedValue()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
            OrganisationTestBO.LoadDefaultClassDef();
            AddressTestBO.LoadDefaultClassDef();

            const string relationshipName = "ContactPersonTestBO.Organisation";
            var          mapper           = GetMapperBoColHasOneItem(relationshipName);
            var          cmbox            = mapper.Control;
            var          boCol            = (BusinessObjectCollection <OrganisationTestBO>)mapper.BusinessObjectCollection;
            var          person           = new ContactPersonTestBO {
                Organisation = boCol[0]
            };
            var addressTestBO = new AddressTestBO {
                ContactPersonTestBO = person
            };

            var newOrganisation = new OrganisationTestBO();

            newOrganisation.Save();
            mapper.BusinessObject = addressTestBO;
            //---------------Assert Precondition----------------
            Assert.AreSame(addressTestBO, mapper.BusinessObject);
            Assert.AreSame(person.Organisation, cmbox.SelectedItem);
            Assert.AreNotSame(person.Organisation, newOrganisation);
            //---------------Execute Test ----------------------
            cmbox.SelectedItem = newOrganisation;
            Assert.AreSame(newOrganisation, cmbox.SelectedItem, "Selected Item should be set.");
            mapper.ApplyChangesToBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreSame(newOrganisation, cmbox.SelectedItem);
            Assert.AreSame(newOrganisation, person.Organisation);
        }
コード例 #2
0
        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]);
        }