public void Test_SetBusinessObjectCollection_NullCol_ThenNonNullEnablesButtons()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            AddControlToForm(editableGridControl);
            editableGridControl.AllowUsersToAddBO = true;
            editableGridControl.SetBusinessObjectCollection(col);
            Assert.IsTrue(editableGridControl.Grid.AllowUserToAddRows);
            editableGridControl.SetBusinessObjectCollection(null);
            //----------------Assert Preconditions --------------
            Assert.IsFalse(editableGridControl.Buttons.Enabled);
            Assert.IsFalse(editableGridControl.FilterControl.Enabled);
            Assert.AreEqual(0, editableGridControl.Grid.Rows.Count);
            Assert.IsFalse(editableGridControl.Grid.AllowUserToAddRows);
            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(col);
            //---------------Verify Result ---------------------
            Assert.IsTrue(editableGridControl.Buttons.Enabled);
            Assert.IsTrue(editableGridControl.FilterControl.Enabled);
            Assert.AreEqual(5, editableGridControl.Grid.Rows.Count);
            Assert.IsTrue(editableGridControl.Grid.AllowUserToAddRows);
        }
        public void Test_SetBusinessObjectCollection_Null_ClearsTheGrid()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            AddControlToForm(editableGridControl);
            editableGridControl.Grid.Columns.Add("TestProp", "TestProp");

            editableGridControl.SetBusinessObjectCollection(col);

            //----------------Assert Preconditions --------------

            Assert.IsTrue(editableGridControl.Grid.Rows.Count > 0, "There should be items in teh grid b4 clearing");
            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(null);
            //---------------Verify Result ---------------------
            Assert.AreEqual(0, editableGridControl.Grid.Rows.Count,
                            "There should be no items in the grid  after setting to null");

            Assert.IsFalse(editableGridControl.Buttons.Enabled);
            Assert.IsFalse(editableGridControl.FilterControl.Enabled);
            Assert.IsFalse(editableGridControl.Grid.AllowUserToAddRows);
        }
示例#3
0
        /// <summary>
        /// Creates a panel with a grid containing the business object
        /// information
        /// </summary>
        /// <param name="formGrid">The grid to fill</param>
        /// <returns>Returns the object containing the panel</returns>
        private PanelFactoryInfo CreatePanelWithGrid(IUIFormGrid formGrid)
        {
            IEditableGridControl myGrid = _controlFactory.CreateEditableGridControl();

            BusinessObject  bo              = _currentBusinessObject;
            ClassDef        classDef        = bo.ClassDef;
            DataSetProvider dataSetProvider = myGrid.Grid.DataSetProvider as DataSetProvider;

            if (dataSetProvider != null)
            {
                dataSetProvider.ObjectInitialiser =
                    new RelationshipObjectInitialiser(bo, (RelationshipDef)classDef.GetRelationship(formGrid.RelationshipName),
                                                      formGrid.CorrespondingRelationshipName);
            }
            IBusinessObjectCollection collection =
                bo.Relationships.GetRelatedCollection(formGrid.RelationshipName);

            myGrid.SetBusinessObjectCollection(collection);

            myGrid.Dock = DockStyle.Fill;
            IPanel panel = _controlFactory.CreatePanel(formGrid.RelationshipName, _controlFactory);

            panel.Controls.Add(myGrid);

            PanelFactoryInfo panelFactoryInfo = new PanelFactoryInfo(panel);

            panelFactoryInfo.FormGrids.Add(formGrid.RelationshipName, myGrid);
            return(panelFactoryInfo);
        }
        public void Test_SetBusinessObjectCollection_IncorrectClassDef()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            //Gizmox.WebGUI.Forms.Form frm = new Gizmox.WebGUI.Forms.Form();
            //frm.Controls.Add((Gizmox.WebGUI.Forms.Control)readOnlyGridControl);
            AddControlToForm(editableGridControl);
            //---------------Execute Test ----------------------
            editableGridControl.Initialise(Sample.CreateClassDefVWG());
            try
            {
                editableGridControl.SetBusinessObjectCollection(col);
                Assert.Fail(
                    "You cannot call set collection for a collection that has a different class def than is initialised");
                ////---------------Test Result -----------------------
            }
            catch (ArgumentException ex)
            {
                StringAssert.Contains(
                    "You cannot call set collection for a collection that has a different class def than is initialised",
                    ex.Message);
            }
        }
        protected IEditableGridControl GetGridWith_5_Rows(out BusinessObjectCollection <MyBO> col)
        {
            LoadMyBoDefaultClassDef();
            col = CreateCollectionWith_4_Objects();
            IEditableGridControl gridControl = CreateEditableGridControl();

            SetupGridColumnsForMyBo(gridControl.Grid);
            gridControl.SetBusinessObjectCollection(col);
            return(GetControlledLifetimeFor(gridControl));
        }
        public void Test_GetBusinessObjectCollection_AfterChanged()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col  = CreateCollectionWith_4_Objects();
            BusinessObjectCollection <MyBO> col2 = new BusinessObjectCollection <MyBO>();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            AddControlToForm(editableGridControl);

            editableGridControl.Grid.Columns.Add("TestProp", "TestProp");
            editableGridControl.SetBusinessObjectCollection(col);
            //---------------Assert Preconditions --------------
            Assert.AreSame(col, editableGridControl.GetBusinessObjectCollection());
            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(col2);
            IBusinessObjectCollection returnedBusinessObjectCollection =
                editableGridControl.GetBusinessObjectCollection();

            //---------------Test Result -----------------------
            Assert.AreSame(col2, returnedBusinessObjectCollection);
        }
        public void Test_SetBusinessObjectCollection_InitialisesGridIfNotPreviouslyInitialised()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(col);
            ////---------------Test Result -----------------------
            Assert.AreEqual("default", editableGridControl.UiDefName);
            Assert.AreEqual(col.ClassDef, editableGridControl.ClassDef);
        }
        public void Test_SetBusinessObjectCollection_NotInitialiseGrid_IfPreviouslyInitialised()
        {
            //Verify that setting the collection for a grid that is already initialised
            //does not cause it to be reinitialised.
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            IClassDef classDef = LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col      = CreateCollectionWith_4_Objects();
            const string         alternateUIDefName  = "Alternate";
            IEditableGridControl editableGridControl = CreateEditableGridControl();

            editableGridControl.Initialise(classDef, alternateUIDefName);
            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(col);
            ////---------------Test Result -----------------------
            Assert.AreEqual(alternateUIDefName, editableGridControl.UiDefName);
        }
        public void Test_SetBusinessObjectCollection_Empty_HasOnlyOneRow()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO>();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            AddControlToForm(editableGridControl);

            //----------------Assert Preconditions --------------


            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(col);
            //---------------Verify Result ---------------------
            Assert.AreEqual(1, editableGridControl.Grid.Rows.Count,
                            "There should be one item in the grid  after setting to empty collection");
            Assert.IsTrue(editableGridControl.Grid.AllowUserToAddRows);
        }
        public void Test_SetBusinessObjectCollection_NumberOfGridRows_Correct()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            AddControlToForm(editableGridControl);
            IEditableGrid editableGrid = editableGridControl.Grid;

            editableGrid.Columns.Add("TestProp", "TestProp");

            //--------------Assert PreConditions----------------
            Assert.AreEqual(1, editableGrid.Rows.Count);

            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(col);
            ////---------------Test Result -----------------------
            Assert.AreEqual(col.Count + 1, editableGrid.Rows.Count, "The number of items in the grid plus the null item");
        }
        public void Test_SetBusinessObjectCollection_WhenAllowAddFalse_ShouldNotChangeAllowAdd()
        {
            //---------------Set up test pack-------------------
            LoadMyBoDefaultClassDef();
            BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects();
            IEditableGridControl            editableGridControl = CreateEditableGridControl();

            AddControlToForm(editableGridControl);
            IEditableGrid editableGrid = editableGridControl.Grid;

            editableGrid.Columns.Add("TestProp", "TestProp");
            editableGridControl.AllowUsersToAddBO = false;
            //--------------Assert PreConditions----------------
            Assert.AreEqual(0, editableGrid.Rows.Count);
            Assert.IsFalse(editableGrid.AllowUserToAddRows);
            //---------------Execute Test ----------------------
            editableGridControl.SetBusinessObjectCollection(col);
            ////---------------Test Result -----------------------
            Assert.IsFalse(editableGrid.AllowUserToAddRows);
            Assert.IsFalse(editableGridControl.AllowUsersToAddBO);
            Assert.AreEqual(col.Count, editableGrid.Rows.Count, "The number of items in the col");
        }