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();
        }
        public void TestAddRow_UpdatesCollection()
        {
            BusinessObjectCollection <MyBO> col = null;
            IDataSetProvider dataSetProvider    = GetDataSetProviderWithCollection(ref col);
            BOMapper         mapper             = new BOMapper(col.ClassDef.CreateNewBusinessObject());
            DataTable        table = dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid);
            MyBO             boNew = new MyBO();

            boNew.SetPropertyValue("TestProp", "bo3prop1");
            boNew.SetPropertyValue("TestProp2", "s2");
            //---------------Assert Precondition----------------
            Assert.AreEqual(4, table.Rows.Count);
            Assert.AreEqual(4, col.Count);
            Assert.AreEqual(4, col.CreatedBusinessObjects.Count);
            //---------------Execute Test ----------------------
            table.Rows.Add(new object[] { null, "bo3prop1", "bo3prop2" });
            //---------------Test Result -----------------------
            Assert.AreEqual(5, col.Count);
            Assert.AreEqual(5, col.CreatedBusinessObjects.Count);
            Assert.AreEqual(5, table.Rows.Count);
        }
        public void Test_EditDataTable_ToDBNull_EditsBo()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col = null;
            IDataSetProvider dataSetProvider    = GetDataSetProviderWithCollection(ref col);
            BOMapper         mapper             = new BOMapper(col.ClassDef.CreateNewBusinessObject());
            DataTable        table = dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid);
            MyBO             bo1   = col[0];
//            const string updatedvalue = "UpdatedValue";
            const string columnName         = "TestProp";
            object       origionalPropValue = bo1.GetPropertyValue(columnName);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(4, table.Rows.Count);
            Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]);
            Assert.AreEqual(origionalPropValue, table.Rows[0][columnName]);
            //---------------Execute Test ----------------------
            table.Rows[0][columnName] = DBNull.Value;
            //---------------Test Result -----------------------
            Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]);
            Assert.AreEqual(DBNull.Value, table.Rows[0][columnName]);
            Assert.AreEqual(null, bo1.GetPropertyValue(columnName));
        }