Exemple #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);
        }
        public void Test_EditDataTable_WhenMultipleLevelProp_ShouldEditRelatedBO()
        {
            //---------------Set up test pack-------------------
            RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier();

            GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;
            AddressTestBO.LoadDefaultClassDef();
            ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <AddressTestBO> addresses = new BusinessObjectCollection <AddressTestBO>();

            addresses.Add(new AddressTestBO {
                ContactPersonTestBO = new ContactPersonTestBO()
            });
            addresses.Add(new AddressTestBO {
                ContactPersonTestBO = new ContactPersonTestBO()
            });
            addresses.Add(new AddressTestBO {
                ContactPersonTestBO = new ContactPersonTestBO()
            });

            OrganisationTestBO organisation = new OrganisationTestBO();

            UIGrid       uiGrid       = new UIGrid();
            const string propertyName = "ContactPersonTestBO.OrganisationID";

            uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));

            IDataSetProvider dataSetProvider = CreateDataSetProvider(addresses);
            DataTable        table           = dataSetProvider.GetDataTable(uiGrid);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(3, table.Rows.Count);
            Assert.AreEqual(DBNull.Value, table.Rows[0][propertyName]);
            //---------------Execute Test ----------------------
            table.Rows[0][propertyName] = organisation.OrganisationID;
            //---------------Test Result -----------------------
            Assert.AreEqual(organisation.OrganisationID, table.Rows[0][propertyName]);
            Assert.AreEqual(organisation.OrganisationID, addresses[0].ContactPersonTestBO.OrganisationID);
            recordingExceptionNotifier.RethrowRecordedException();
        }
        public void Test_EditDataTable_WhenVirtualProp_ShouldEditRelatedVirtualProp()
        {
            //---------------Set up test pack-------------------
            RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier();

            GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;
            AddressTestBO.LoadDefaultClassDef();
            var contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();

            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection <ContactPersonTestBO> contactPersonTestBOS = new BusinessObjectCollection <ContactPersonTestBO>();

            contactPersonTestBOS.Add(new ContactPersonTestBO(), new ContactPersonTestBO(), new ContactPersonTestBO());

            OrganisationTestBO organisation = new OrganisationTestBO();

            UIGrid uiGrid = new UIGrid();

            new UIDef("fdafdas", new UIForm(), uiGrid)
            {
                ClassDef = contactPersonClassDef
            };
            const string propertyName = "-Organisation-";

            uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));

            IDataSetProvider dataSetProvider = CreateDataSetProvider(contactPersonTestBOS);
            DataTable        table           = dataSetProvider.GetDataTable(uiGrid);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(3, table.Rows.Count);
            Assert.AreEqual(DBNull.Value, table.Rows[0][propertyName]);
            Assert.AreEqual(null, contactPersonTestBOS[0].Organisation);
            //---------------Execute Test ----------------------
            table.Rows[0][propertyName] = organisation;
            //---------------Test Result -----------------------
            Assert.AreSame(organisation, table.Rows[0][propertyName]);
            Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation);
            recordingExceptionNotifier.RethrowRecordedException();
        }