Пример #1
0
        public void TestClickMenuItemTwiceOnlyLeavesSameControlDocked()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

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

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

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

            formsMenuItem.PerformClick();

            //-------------Assert Preconditions -------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl, (IFormHabanero)habaneroMenu.Form);

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl, (IFormHabanero)habaneroMenu.Form);
        }
Пример #2
0
        public void TestClickSecondItemDocksNewControlInForm()
        {
            //---------------Set up test pack-------------------

            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem1            = submenu.AddMenuItem(TestUtil.GetRandomString());
            IFormControl      expectedFormControl1 = CreateFormControlStub();

            menuItem1.FormControlCreator += (() => expectedFormControl1);
            HabaneroMenu.Item menuItem2            = submenu.AddMenuItem(TestUtil.GetRandomString());
            IFormControl      expectedFormControl2 = CreateFormControlStub();

            menuItem2.FormControlCreator += (() => expectedFormControl2);

            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            menu.DockInForm(habaneroMenu.Form);
            IMenuItem formsMenuItem1 = menu.MenuItems[0].MenuItems[0];
            IMenuItem formsMenuItem2 = menu.MenuItems[0].MenuItems[1];

            formsMenuItem1.PerformClick();

            //-------------Assert Preconditions -------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl1, (IFormHabanero)habaneroMenu.Form);

            //---------------Execute Test ----------------------
            formsMenuItem2.PerformClick();

            //---------------Test Result -----------------------
            AssertControlDockedInForm((IControlHabanero)expectedFormControl2, (IFormHabanero)habaneroMenu.Form);
        }
Пример #3
0
        public void TestHandlesError_FromControlManagerCreator()
        {
            //---------------Set up test pack-------------------
            MockExceptionNotifier exceptionNotifier = new MockExceptionNotifier();

            GlobalRegistry.UIExceptionNotifier = exceptionNotifier;
            Exception    exception    = new Exception();
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());
            menuItem.ControlManagerCreator += delegate
            {
                throw exception;
            };
            IMenuBuilder      menuBuilder   = CreateMenuBuilder();
            IMainMenuHabanero menu          = menuBuilder.BuildMainMenu(habaneroMenu);
            IMenuItem         formsMenuItem = menu.MenuItems[0].MenuItems[0];

            menu.DockInForm(habaneroMenu.Form);

            //-------------Assert Preconditions -------------
            Assert.IsNull(exceptionNotifier.Exception);
            Assert.IsNull(exceptionNotifier.FurtherMessage);
            Assert.IsNull(exceptionNotifier.Title);

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.AreEqual(exception, exceptionNotifier.Exception);
            Assert.IsNull(null, exceptionNotifier.FurtherMessage);
            Assert.IsNull(null, exceptionNotifier.Title);
        }
Пример #4
0
        public virtual void Test_Click_WhenFormControlCreatorSet_ShouldCallSetFormOnFormControl()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

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

            bool               creatorCalled              = false;
            IFormControlStub   formControlStub            = CreateFormControlStub();
            FormControlCreator formControlCreatorDelegate = delegate
            {
                creatorCalled = true;
                return(formControlStub);
            };

            menuItem.FormControlCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

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

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(creatorCalled);
            Assert.IsFalse(formControlStub.SetFormCalled);
            Assert.IsNull(formControlStub.SetFormArgument);
            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(creatorCalled);
            Assert.IsTrue(formControlStub.SetFormCalled);
            Assert.IsNotNull(formControlStub.SetFormArgument);
        }
Пример #5
0
        public void TestControlManagerCreatorCalledIfSet()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem   = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool                  called = false;
            IControlFactory       controlFactoryPassedToCreator = null;
            ControlManagerCreator formControlCreatorDelegate    = delegate(IControlFactory controlFactory)
            {
                called = true;
                controlFactoryPassedToCreator = controlFactory;
                return(new ControlManagerStub(controlFactory));
            };

            menuItem.ControlManagerCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

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

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(called);
            Assert.AreSame(habaneroMenu.ControlFactory, controlFactoryPassedToCreator);
        }
Пример #6
0
        public void TestFormControlCreatorCalledOnClickIfSet()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            HabaneroMenu.Item menuItem = submenu.AddMenuItem(TestUtil.GetRandomString());
            bool called = false;
            FormControlCreator formControlCreatorDelegate = delegate
            {
                called = true;
                return(CreateFormControlStub());
            };

            menuItem.FormControlCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

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

            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(called);
        }
Пример #7
0
        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]);
        }
Пример #8
0
        public void Test_DockInForm()
        {
            //---------------Set up test pack-------------------
            IFormHabanero     formHabanero = GetControlFactory().CreateForm();
            IMainMenuHabanero mainMenu     = CreateControl();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, formHabanero.Controls.Count);
            //---------------Execute Test ----------------------
            mainMenu.DockInForm(formHabanero);
            //---------------Test Result -----------------------
            Assert.AreEqual(1, formHabanero.Controls.Count);
        }
Пример #9
0
        public void Test_DockInForm_WithWidth_ShouldSetCollapsibleMenuWidth()
        {
            //---------------Set up test pack-------------------
            IFormHabanero formHabanero = GetControlFactory().CreateForm();

            formHabanero.MinimumSize = new Size(RandomValueGen.GetRandomInt(250, 300), 100);
            IMainMenuHabanero mainMenu = CreateControl();
            int menuWidth = RandomValueGen.GetRandomInt(100, 200);

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, formHabanero.Controls.Count);
            //---------------Execute Test ----------------------
            mainMenu.DockInForm(formHabanero, menuWidth);
            //---------------Test Result -----------------------
            var collapsiblePanelGroupControl = TestUtil.AssertIsInstanceOf <ICollapsiblePanelGroupControl>(mainMenu);

            Assert.AreEqual(menuWidth, collapsiblePanelGroupControl.Width);
        }
Пример #10
0
        public void TestDockMenuInForm()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            submenu.AddMenuItem(TestUtil.GetRandomString());
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IFormHabanero     form        = (IFormHabanero)habaneroMenu.Form;
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            //-------------Assert Preconditions -------------
            Assert.IsFalse(IsMenuDocked(menu, form));
            //---------------Execute Test ----------------------
            menu.DockInForm(form);
            //---------------Test Result -----------------------
            Assert.IsTrue(IsMenuDocked(menu, form));
        }
Пример #11
0
        public void Test_DockInForm()
        {
            //---------------Set up test pack-------------------
            IFormHabanero     formHabanero = GetControlFactory().CreateForm();
            IMainMenuHabanero mainMenu     = CreateControl();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, formHabanero.Controls.Count);
            //---------------Execute Test ----------------------
            try
            {
                mainMenu.DockInForm(formHabanero);
            }
            catch (Exception ex)
            {
                //---------------Test Result -----------------------
                Assert.IsInstanceOf <NotImplementedException>(ex);
                StringAssert.Contains("Context menu's cannot be docked", ex.Message);
            }
        }
Пример #12
0
        public void Test_DockInForm_WithWidth_WhenResized_ShouldHaveFixedCollapsibleMenuWidth_BUGFIX_1510()
        {
            //---------------Set up test pack-------------------
            IFormHabanero formHabanero = GetControlFactory().CreateForm();

            formHabanero.MinimumSize = new Size(RandomValueGen.GetRandomInt(250, 300), 100);
            IMainMenuHabanero mainMenu = CreateControl();
            int menuWidth = RandomValueGen.GetRandomInt(100, 200);

            mainMenu.DockInForm(formHabanero, menuWidth);
            var collapsiblePanelGroupControl = (ICollapsiblePanelGroupControl)mainMenu;

            //---------------Assert Precondition----------------
            Assert.AreEqual(menuWidth, collapsiblePanelGroupControl.Width);
            //---------------Execute Test ----------------------
            //Increase the form width by 2 to force a resize
            formHabanero.Width *= 2;
            //---------------Test Result -----------------------
            Assert.AreEqual(menuWidth, collapsiblePanelGroupControl.Width);
        }
        public void TestDockMenuInForm()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            submenu.AddMenuItem(TestUtil.GetRandomString());
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IControlHabanero  form        = habaneroMenu.Form;
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            //-------------Assert Preconditions -------------
            Assert.IsFalse(IsMenuDocked(menu, form));
            //---------------Execute Test ----------------------
            menu.DockInForm(form);
            //---------------Test Result -----------------------
            Assert.IsTrue(IsMenuDocked(menu, form));
            IControlHabanero control = form.Controls[0];

            Assert.IsInstanceOf(typeof(ISplitContainer), control);
        }
        public virtual void Test_DockMenuInForm_ShouldSetUpSplitterPanels()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            submenu.AddMenuItem(TestUtil.GetRandomString());
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IControlHabanero  form        = habaneroMenu.Form;
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            form.Size = new Size(460, 900);
            //-------------Assert Preconditions -------------
            Assert.IsFalse(IsMenuDocked(menu, form));
            //---------------Execute Test ----------------------
            menu.DockInForm(form);
            //---------------Test Result -----------------------
            IControlHabanero control = form.Controls[0];

            Assert.IsInstanceOf(typeof(ISplitContainer), control);
            Gizmox.WebGUI.Forms.SplitContainer splitContainerVWG = (Gizmox.WebGUI.Forms.SplitContainer)control;
            Gizmox.WebGUI.Forms.SplitterPanel  panel1            = splitContainerVWG.Panel1;
            Assert.AreEqual(250, panel1.Width);
            Assert.AreEqual(1, panel1.Controls.Count);
            IControlHabanero menuControl = (IControlHabanero)panel1.Controls[0];

            Assert.IsInstanceOf(typeof(ICollapsiblePanelGroupControl), menuControl);
            panel1.Size = new Size(121, 333);
            Assert.AreEqual(panel1.Width, menuControl.Width);

            Gizmox.WebGUI.Forms.SplitterPanel panel2 = splitContainerVWG.Panel2;
            Assert.AreEqual(1, panel2.Controls.Count);
            IControlHabanero editorControl = (IControlHabanero)panel2.Controls[0];

            Assert.IsInstanceOf(typeof(MainEditorPanelVWG), editorControl);
            panel2.Size = new Size(321, 514);
            Assert.AreEqual(panel2.Width, editorControl.Width);
            Assert.AreEqual(panel2.Height, editorControl.Height);
        }
        public void Test_DockMenuInForm_FormNull_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

            submenu.AddMenuItem(TestUtil.GetRandomString());
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

            //-------------Assert Preconditions -------------
            //---------------Execute Test ----------------------
            try
            {
                menu.DockInForm(null);
                Assert.Fail("expected ArgumentNullException");
            }
            //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("Value cannot be null", ex.Message);
                StringAssert.Contains("form", ex.ParamName);
            }
        }
Пример #16
0
        public override void Test_Click_WhenFormControlCreatorSet_ShouldCallSetFormOnFormControl()
        {
            //---------------Set up test pack-------------------
            HabaneroMenu habaneroMenu = CreateHabaneroMenuFullySetup();
            HabaneroMenu submenu      = habaneroMenu.AddSubMenu(TestUtil.GetRandomString());

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

            bool               creatorCalled              = false;
            IFormControlStub   formControlStub            = CreateFormControlStub();
            FormControlCreator formControlCreatorDelegate = delegate
            {
                creatorCalled = true;
                return(formControlStub);
            };

            menuItem.FormControlCreator += formControlCreatorDelegate;
            IMenuBuilder      menuBuilder = CreateMenuBuilder();
            IMainMenuHabanero menu        = menuBuilder.BuildMainMenu(habaneroMenu);

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

            //--------------- Test Preconditions ----------------
            Assert.IsFalse(creatorCalled);
            Assert.IsFalse(formControlStub.SetFormCalled);
            Assert.IsNull(formControlStub.SetFormArgument);
            //---------------Execute Test ----------------------
            formsMenuItem.PerformClick();

            //---------------Test Result -----------------------
            Assert.IsTrue(creatorCalled);
            Assert.IsTrue(formControlStub.SetFormCalled);
            //The MenuBuilderVWG sites the control on a UserControl instead of a form (VWG does not support MDI Children), so this next assert would fail.
            //Assert.IsNotNull(formControlStub.SetFormArgument);
        }