Exemple #1
0
        public void TestComboBoxClick_DoesNotEditWhenIndicesAreNegetive()
        {
            //---------------Set up test pack-------------------
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
            BusinessObjectCollection <MyBO> col;
            IEditableGrid editableGrid = GetGridWith_5_Rows(out col);

            AddComboBoxColumnWithValues(editableGrid);
            ((EditableGridWin)editableGrid).CellClick -= ((EditableGridWin)editableGrid).CellClickHandler;
            IFormHabanero formWin = AddControlToForm(editableGrid);

            formWin.Show();
            editableGrid.CurrentCell = editableGrid.Rows[0].Cells[1];

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, editableGrid.CurrentCell.RowIndex);
            Assert.AreEqual(1, editableGrid.CurrentCell.ColumnIndex);
            System.Windows.Forms.DataGridViewColumn column =
                ((DataGridViewColumnWin)editableGrid.Columns[2]).DataGridViewColumn;
            Assert.IsInstanceOf(typeof(System.Windows.Forms.DataGridViewComboBoxColumn), column);

            //---------------Execute Test ----------------------
            bool setToEditMode = ((EditableGridWin)editableGrid).CheckIfComboBoxShouldSetToEditMode(-1, -1);

            //---------------Test Result -----------------------
            Assert.IsFalse(setToEditMode);
        }
Exemple #2
0
        public void TestConfirmDeletion_NoDeletionWhenAllowUserToDeleteRowsIsFalse()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IEditableGrid editableGrid = GetGridWith_5_Rows(out col);

            editableGrid.ConfirmDeletion       = true;
            editableGrid.AllowUserToDeleteRows = false;

            bool confirmationDelegateCalled = false;

            editableGrid.CheckUserConfirmsDeletionDelegate -= editableGrid.CheckUserWantsToDelete;
            editableGrid.CheckUserConfirmsDeletionDelegate += delegate
            {
                confirmationDelegateCalled = true;
                return(false);
            };

            IFormHabanero formWin = AddControlToForm(editableGrid);

            formWin.Show();
            //---------------Assert Precondition----------------
            Assert.IsTrue(editableGrid.ConfirmDeletion);
            Assert.IsFalse(editableGrid.AllowUserToDeleteRows);
            //---------------Execute Test ----------------------
            SimulateDeleteKeyPress(editableGrid);

            //---------------Test Result -----------------------
            Assert.IsFalse(confirmationDelegateCalled);
        }
Exemple #3
0
        public void TestDeleteKeyBehaviours_DeletesNoCells_WhenNoneSelected_WhenUserConfirmsDeletion()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IEditableGrid editableGrid = GetGridWith_5_Rows(out col);

            editableGrid.ConfirmDeletion = true;

            bool confirmationDelegateCalled = false;

            editableGrid.CheckUserConfirmsDeletionDelegate -= editableGrid.CheckUserWantsToDelete;
            editableGrid.CheckUserConfirmsDeletionDelegate += delegate
            {
                confirmationDelegateCalled = true;
                return(true);
            };
            IFormHabanero formWin = AddControlToForm(editableGrid);

            formWin.Show();
            foreach (IDataGridViewCell Cell in editableGrid.SelectedCells)
            {
                Cell.Selected = false;
            }
            //---------------Assert Precondition----------------
            Assert.AreEqual(5, editableGrid.Rows.Count);
            Assert.AreEqual(0, editableGrid.SelectedCells.Count);
            //---------------Execute Test ----------------------

            SimulateDeleteKeyPress(editableGrid);

            //---------------Test Result -----------------------
            Assert.IsTrue(confirmationDelegateCalled);
            Assert.AreEqual(5, editableGrid.Rows.Count);
        }
Exemple #4
0
        public void TestDeleteKeyBehaviours_NoDeleteWhen_SelectedRowsNotZero()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IEditableGrid editableGrid = GetGridWith_5_Rows(out col);

            editableGrid.ConfirmDeletion = true;

            bool confirmationDelegateCalled = false;

            editableGrid.CheckUserConfirmsDeletionDelegate -= editableGrid.CheckUserWantsToDelete;
            editableGrid.CheckUserConfirmsDeletionDelegate += delegate
            {
                confirmationDelegateCalled = true;
                return(true);
            };
            IFormHabanero formWin = AddControlToForm(editableGrid);

            formWin.Show();
            editableGrid.Rows[1].Selected = true;

            //editableGrid.MultiSelect = false;
            //((EditableGridWin)editableGrid).SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            //editableGrid.CurrentCell = editableGrid.Rows[0].Cells[0];

            //---------------Assert Precondition----------------
            Assert.AreEqual(1, editableGrid.SelectedRows.Count);
            //---------------Execute Test ----------------------
            SimulateDeleteKeyPress(editableGrid);

            //---------------Test Result -----------------------
            Assert.IsFalse(confirmationDelegateCalled);
        }
        public void TestCloseFormAndClickCreatesNewForm()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu  habaneroMenu = CreateHabaneroMenuFullySetup();
            IFormHabanero frm          = (IFormHabanero)habaneroMenu.Form;

            frm.Show();
            HabaneroMenu submenu = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());


            menuItem.FormControlCreator += (() => new FormControlStubWin());
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem = menu.MenuItems[0].MenuItems[0];

            formsMenuItem.PerformClick();
            System.Windows.Forms.Form    winForm             = (System.Windows.Forms.Form)frm;
            System.Windows.Forms.Form    childForm           = winForm.MdiChildren[0];
            System.Windows.Forms.Control expectedFormControl = childForm.Controls[0];
            //---------------Execute Test ----------------------

            childForm.Close();
            formsMenuItem.PerformClick();
            //---------------Test Result -----------------------

            Assert.AreEqual(1, winForm.MdiChildren.Length);
            childForm = winForm.MdiChildren[0];
            Assert.AreEqual(1, childForm.Controls.Count);
            Assert.IsInstanceOf(typeof(FormControlStubWin), winForm.MdiChildren[0].Controls[0]);
            Assert.AreNotSame(expectedFormControl, winForm.MdiChildren[0].Controls[0]);
        }
Exemple #6
0
        public void TestDeleteKeyBehaviours_DeletesSelectedCells_OneRow_WithoutConfirmsDeletion()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IEditableGrid editableGrid = GetGridWith_5_Rows(out col);

            editableGrid.ConfirmDeletion = false;

            bool confirmationDelegateCalled = false;

            editableGrid.CheckUserConfirmsDeletionDelegate -= editableGrid.CheckUserWantsToDelete;
            editableGrid.CheckUserConfirmsDeletionDelegate += delegate
            {
                confirmationDelegateCalled = true;
                return(true);
            };
            IFormHabanero formWin = AddControlToForm(editableGrid);

            formWin.Show();
            //---------------Assert Precondition----------------
            Assert.AreEqual(5, editableGrid.Rows.Count);
            //---------------Execute Test ----------------------
            editableGrid.Rows[0].Cells[0].Selected = true;
            SimulateDeleteKeyPress(editableGrid);

            //---------------Test Result -----------------------
            Assert.IsFalse(confirmationDelegateCalled);
            Assert.AreEqual(4, editableGrid.Rows.Count);
        }
 protected override IStaticDataEditor CreateEditorOnForm(out IFormHabanero frm)
 {
     frm = GetControlFactory().CreateForm();
     IStaticDataEditor editor = GetControlFactory().CreateStaticDataEditor();
     frm.Controls.Add(editor);
     frm.Show();
     return editor;
 }
Exemple #8
0
        protected override IStaticDataEditor CreateEditorOnForm(out IFormHabanero frm)
        {
            frm = GetControlFactory().CreateForm();
            IStaticDataEditor editor = GetControlFactory().CreateStaticDataEditor();

            frm.Controls.Add(editor);
            frm.Show();
            return(editor);
        }
Exemple #9
0
        public void TestComboBoxClick_DoesNotAffectOtherColumnType()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IEditableGrid editableGrid = GetGridWith_5_Rows(out col);

            ((EditableGridWin)editableGrid).CellClick -= ((EditableGridWin)editableGrid).CellClickHandler;
            IFormHabanero formWin = AddControlToForm(editableGrid);

            formWin.Show();
            //---------------Assert Precondition----------------
            Assert.IsNotInstanceOf(typeof(IDataGridViewComboBoxColumn), editableGrid.Columns[0]);
            //---------------Execute Test ----------------------
            bool setToEditMode = ((EditableGridWin)editableGrid).CheckIfComboBoxShouldSetToEditMode(0, 0);

            //---------------Test Result -----------------------
            Assert.IsFalse(setToEditMode);
        }
        /// <summary>
        /// Sets the current control to the one with the specified heading
        /// </summary>
        /// <param name="heading">The heading</param>
        /// <returns>Returns the relevant IFormControl object</returns>
        public IFormControl SetCurrentControl(String heading)
        {
            if (_formsbyHeading == null)
            {
                _formsbyHeading = new Hashtable();
                _formsbyForm    = new Hashtable();
            }
            if (_formsbyHeading.Contains(heading))
            {
                IFormHabanero frm = (IFormHabanero)_formsbyHeading[heading];
                if (_fontSize != 0.0f)
                {
                    frm.Font = new Font(frm.Font.FontFamily, _fontSize);
                }
                frm.Show();
                frm.Refresh();
                frm.Focus();
                frm.PerformLayout();
                return((IFormControl)frm.Controls[0]);
            }
            IFormControl formCtl = GetFormControl(heading);

            IFormHabanero newMdiForm = _controlFactory.CreateForm();

            newMdiForm.Width       = 800;
            newMdiForm.Height      = 600;
            newMdiForm.MdiParent   = _parentForm;
            newMdiForm.WindowState = FormWindowState.Maximized;

            //IControlHabanero ctl = formCtl;

            newMdiForm.Text = heading;
            newMdiForm.Controls.Clear();
            BorderLayoutManager layoutManager = _controlFactory.CreateBorderLayoutManager(newMdiForm);

            layoutManager.AddControl((IControlHabanero)formCtl, BorderLayoutManager.Position.Centre);
            newMdiForm.Show();
            _formsbyHeading.Add(heading, newMdiForm);
            _formsbyForm.Add(newMdiForm, heading);
            formCtl.SetForm(newMdiForm);
            newMdiForm.Closed += MdiFormClosed;

            return(formCtl);
        }
 private bool ReshowForm()
 {
     if (_createdForm != null)
     {
         try
         {
             _createdForm.Show();
             _createdForm.Refresh();
             _createdForm.Focus();
             _createdForm.PerformLayout();
         }
         catch (Win32Exception)
         {
             //note_: it will throw this error in testing.
         }
         catch (ObjectDisposedException)
         {
             //the window has been disposed, we need to create a new one
         }
         return(true);
     }
     return(false);
 }
Exemple #12
0
        public void TestDeleteKeyBehaviours_ClearsContentsSuccessfully()
        {
            //---------------Set up test pack-------------------
            BusinessObjectCollection <MyBO> col;
            IEditableGrid editableGrid = GetGridWith_5_Rows(out col);

            editableGrid.ConfirmDeletion    = true;
            editableGrid.DeleteKeyBehaviour = DeleteKeyBehaviours.ClearContents;

            bool confirmationDelegateCalled = false;

            editableGrid.CheckUserConfirmsDeletionDelegate -= editableGrid.CheckUserWantsToDelete;
            editableGrid.CheckUserConfirmsDeletionDelegate += delegate
            {
                confirmationDelegateCalled = true;
                return(true);
            };
            IFormHabanero formWin = AddControlToForm(editableGrid);

            formWin.Show();

            editableGrid.Rows[0].Cells[0].Selected = true;
            editableGrid.Rows[1].Cells[0].Selected = true;
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, editableGrid.SelectedCells.Count);
            Assert.AreEqual("b", editableGrid.Rows[0].Cells[0].Value);
            Assert.AreEqual("d", editableGrid.Rows[1].Cells[0].Value);
            Assert.AreEqual("c", editableGrid.Rows[2].Cells[0].Value);
            //---------------Execute Test ----------------------
            SimulateDeleteKeyPress(editableGrid);

            //---------------Test Result -----------------------
            Assert.IsFalse(confirmationDelegateCalled);
            Assert.IsInstanceOf(typeof(DBNull), editableGrid.Rows[0].Cells[0].Value);
            Assert.IsInstanceOf(typeof(DBNull), editableGrid.Rows[1].Cells[0].Value);
            Assert.AreEqual("c", editableGrid.Rows[2].Cells[0].Value);
        }
        public void DoClick()
        {
            try
            {
                if (_habaneroMenuItem.CustomHandler != null)
                {
                    _habaneroMenuItem.CustomHandler(this, new EventArgs());
                }
                else
                {
                    if (ReshowForm())
                    {
                        return;
                    }
                    if (_habaneroMenuItem.Form == null || _habaneroMenuItem.Form.Controls.Count <= 0)
                    {
                        return;
                    }
                    _createdForm             = _habaneroMenuItem.ControlFactory.CreateForm();
                    _createdForm.Width       = 800;
                    _createdForm.Height      = 600;
                    _createdForm.MdiParent   = (IFormHabanero)_habaneroMenuItem.Form;
                    _createdForm.WindowState = Habanero.Faces.Base.FormWindowState.Maximized;
                    _createdForm.Text        = _habaneroMenuItem.Name;
                    //Deerasha 2009/11/26: Line below prevents the std VS icon from appearing on form's upper right
                    ((Form)_createdForm).ShowIcon = false;
                    _createdForm.Controls.Clear();

                    BorderLayoutManager layoutManager = _habaneroMenuItem.ControlFactory.CreateBorderLayoutManager
                                                            (_createdForm);

                    IControlHabanero control;
                    if (_habaneroMenuItem.FormControlCreator != null)
                    {
                        _formControl = _habaneroMenuItem.FormControlCreator();
                        _formControl.SetForm(_createdForm);
                        control = (IControlHabanero)_formControl;
                    }
                    else if (_habaneroMenuItem.ControlManagerCreator != null)
                    {
                        _controlManager = _habaneroMenuItem.ControlManagerCreator(_habaneroMenuItem.ControlFactory);
                        control         = _controlManager.Control;
                    }
                    else
                    {
                        throw new Exception
                                  ("Please set up the MenuItem with at least one Creational or custom handling delegate");
                    }
                    layoutManager.AddControl(control, BorderLayoutManager.Position.Centre);
                    _createdForm.Show();
                    _createdForm.Closed += delegate
                    {
                        _createdForm    = null;
                        _formControl    = null;
                        _controlManager = null;
                    };
                }
            }
            catch (Exception ex)
            {
                GlobalRegistry.UIExceptionNotifier.Notify(ex, null, null);
            }
        }
Exemple #14
0
 protected virtual void ShowFormIfNecessary(IFormHabanero form)
 {
     form.Show();
 }
 protected virtual void ShowFormIfNecessary(IFormHabanero form)
 {
     form.Show();
 }