public void ControlShouldFireShownEventWhenVisibleChanged(IControlTypeInfo <Control> controlType) { int shownCount = 0; int?initialShownCount = null; Form(form => { var ctl = controlType.CreateControl(); ctl.Shown += (sender2, e2) => { shownCount++; Application.Instance.AsyncInvoke(() => { if (form.Loaded) { form.Close(); } }); }; ctl.Visible = false; Assert.AreEqual(0, shownCount); form.Content = TableLayout.AutoSized(ctl); Assert.AreEqual(0, shownCount); form.Shown += (sender, e) => Application.Instance.AsyncInvoke(() => { initialShownCount = shownCount; ctl.Visible = true; }); }); Assert.AreEqual(0, initialShownCount, "#1"); // should not be initially called Assert.AreEqual(1, shownCount, "#2"); }
public void ControlEventsShouldBeHandled(IControlTypeInfo <Control> controlType) { TestBase.Invoke(() => { var control = controlType.CreateControl(); try { control.SizeChanged += Control_EventHandler; control.EnabledChanged += Control_EventHandler; control.GotFocus += Control_EventHandler; control.LostFocus += Control_EventHandler; control.KeyDown += Control_EventHandler; control.KeyUp += Control_EventHandler; control.MouseUp += Control_EventHandler; control.MouseDown += Control_EventHandler; control.MouseEnter += Control_EventHandler; control.MouseLeave += Control_EventHandler; control.MouseDoubleClick += Control_EventHandler; control.MouseWheel += Control_EventHandler; //control.Shown += Control_EventHandler; //control.TextInput += Control_EventHandler; } catch (Exception ex) { throw new InvalidOperationException($"Control {control.GetType().Name}:", ex); } }); }
public void DefaultValuesShouldBeCorrect(IControlTypeInfo <Control> controlType) { TestProperties(f => controlType.CreateControl(), c => c.Enabled, c => c.ToolTip, c => c.TabIndex ); }
public void EnabledShouldTriggerChangedEventsOnChildren(IControlTypeInfo <Control> controlInfo) { Invoke(() => { int enabledChanged = 0; var panel = new Panel(); var control = controlInfo.CreateControl(); control.EnabledChanged += (sender, e) => enabledChanged++; // if it's already enabled, it shouldn't fire a changed event when we set it. var expectedCount = control.Enabled ? 0 : 1; control.Enabled = true; Assert.IsTrue(control.Enabled, "#1.1"); Assert.AreEqual(expectedCount, enabledChanged, "#1.2"); // test setting to false without container, should trigger event control.Enabled = false; Assert.IsFalse(control.Enabled, "#1.3"); Assert.AreEqual(++expectedCount, enabledChanged, "#1.4"); // set back to true, should trigger event control.Enabled = true; Assert.IsTrue(control.Enabled, "#1.5"); Assert.AreEqual(++expectedCount, enabledChanged, "#1.6"); panel.Content = new TableLayout { Rows = { control } }; panel.AttachNative(); // set panel to enabled (which it should already be at), so no change event panel.Enabled = true; Assert.IsTrue(control.Enabled, "#2.1"); Assert.AreEqual(expectedCount, enabledChanged, "#2.2"); // shouldn't have changed // change panel to disabled, which should now trigger the event panel.Enabled = false; Assert.IsFalse(control.Enabled, "#3.1"); Assert.AreEqual(++expectedCount, enabledChanged, "#3.2"); // set control to enabled, which should still stay false and not trigger the event control.Enabled = true; Assert.IsFalse(control.Enabled, "#4.1"); Assert.AreEqual(expectedCount, enabledChanged, "#4.2"); // set to same value again, should not fire changed event panel.Enabled = false; Assert.IsFalse(control.Enabled, "#5.1"); Assert.AreEqual(expectedCount, enabledChanged, "#5.2"); // remove from parent, should trigger changed event panel.Content = null; Assert.IsTrue(control.Enabled, "#6.1"); Assert.AreEqual(++expectedCount, enabledChanged, "#6.2"); }); }
public void ControlsShouldHavePreferredSize(IControlTypeInfo <Control> info) { var control = info.CreatePopulatedControl(); var size = control.GetPreferredSize(); Console.WriteLine($"PreferredSize for {info.Type}: {size}"); Assert.Greater(size.Width, 0, "#1.1 - Preferred width should be greater than zero"); Assert.Greater(size.Height, 0, "#1.2 - Preferred height should be greater than zero"); var padding = new Padding(10); var container = new Panel { Content = control, Padding = padding }; var containerSize = container.GetPreferredSize(); Assert.That(containerSize.Width, Is.EqualTo(size.Width + padding.Horizontal).Within(0.1), "#2.1 - panel with padding should have correct width"); Assert.That(containerSize.Height, Is.EqualTo(size.Height + padding.Vertical).Within(0.1), "#2.2 - panel with padding should have correct height"); }
public void AllControlsShouldExpandWidth(IControlTypeInfo <Control> info) { ManualForm("Control and blue background should expand to width of scrollable", form => { var control = info.CreateControl(); info.PopulateControl(control); control.BackgroundColor = Colors.Blue; return(new Scrollable { Size = new Size(300, 200), Content = control, ExpandContentWidth = true, ExpandContentHeight = false }); }); }
public void ControlsShouldReturnAFont(IControlTypeInfo <Control> info) { Invoke(() => { var control = info.CreateControl(); if (control is CommonControl commonControl) { Assert.IsNotNull(commonControl.Font); } else if (control is GroupBox groupBox) { Assert.IsNotNull(groupBox.Font); } else { Assert.Pass("Control does not have a font property"); } }); }
public void ControlsShouldNotHaveIntrinsicPadding(IControlTypeInfo <Control> info) { ManualForm("Controls should be touching horizontally and vertically,\nwithout being clipped.", form => { return(new TableLayout { Rows = { new TableRow(new TableCell(info.CreatePopulatedControl(), true), new TableCell(info.CreatePopulatedControl(), true)), new TableRow(new Panel { Content = info.CreatePopulatedControl() }, info.CreatePopulatedControl()), new TableRow(info.CreatePopulatedControl(), new Drawable { Content = info.CreatePopulatedControl() }), null } }); }); }
public void ControlShouldFireShownEventWhenAddedDynamically(IControlTypeInfo <Control> controlType) { Exception exception = null; int shownCount = 0; Form(form => { form.Shown += (sender, e) => Application.Instance.AsyncInvoke(() => { try { var ctl = controlType.CreateControl(); ctl.Shown += (sender2, e2) => { shownCount++; Application.Instance.AsyncInvoke(() => { if (form.Loaded) { form.Close(); } }); }; form.Content = TableLayout.AutoSized(ctl); } catch (Exception ex) { exception = ex; } }); }); if (exception != null) { ExceptionDispatchInfo.Capture(exception).Throw(); } Assert.AreEqual(1, shownCount); }
public void ControlShouldFireShownEvent(IControlTypeInfo <Control> controlType) { int shownCount = 0; int visualControlShownCount = 0; int expectedVisualShown = 0; Form(form => { var ctl = controlType.CreateControl(); // themed controls have visual controls! foreach (var visualControl in ctl.VisualControls) { expectedVisualShown++; visualControl.Shown += (sender, e) => { visualControlShownCount++; }; } ctl.Shown += (sender, e) => { shownCount++; Application.Instance.AsyncInvoke(() => { if (form.Loaded) { form.Close(); } }); }; form.Content = TableLayout.AutoSized(ctl); Assert.AreEqual(0, shownCount); }); Assert.AreEqual(1, shownCount); Assert.AreEqual(expectedVisualShown, visualControlShownCount, "Visual controls didn't get Shown event triggered"); }
public void EnabledShouldAffectChildControls(IContainerTypeInfo <Container> containerType, IControlTypeInfo <Control> controlType) { Invoke(() => { var enabledChild = controlType.CreateControl(); var disabledChild = controlType.CreateControl(); var neutralChild = controlType.CreateControl(); var childPanel = new TableLayout { Rows = { enabledChild, disabledChild, neutralChild } }; var container = containerType.CreateControl(childPanel); // load the control container.AttachNative(); var neutralEnabled = neutralChild.Enabled; // disabled child should always be disabled disabledChild.Enabled = false; enabledChild.Enabled = true; // default values Assert.IsTrue(container.Enabled, "#1.1"); Assert.IsTrue(enabledChild.Enabled, "#1.2"); Assert.IsFalse(disabledChild.Enabled, "#1.3"); Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#1.4"); // setting container to disabled container.Enabled = false; Assert.IsFalse(container.Enabled, "#2.1"); Assert.IsFalse(enabledChild.Enabled, "#2.2"); Assert.IsFalse(disabledChild.Enabled, "#2.3"); Assert.IsFalse(neutralChild.Enabled, "#2.4"); // set child to enabled when parent is disabled, should still stay disabled enabledChild.Enabled = true; Assert.IsFalse(container.Enabled, "#3.1"); Assert.IsFalse(enabledChild.Enabled, "#3.2"); Assert.IsFalse(disabledChild.Enabled, "#3.3"); Assert.IsFalse(neutralChild.Enabled, "#3.4"); // set container back to enabled container.Enabled = true; Assert.IsTrue(container.Enabled, "#4.1"); Assert.IsTrue(enabledChild.Enabled, "#4.2"); Assert.IsFalse(disabledChild.Enabled, "#4.3"); Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#4.4"); }); }
public void EnabledShouldAffectChildControlsWhenDynamicallyAdded(IContainerTypeInfo <Container> containerType, IControlTypeInfo <Control> controlType) { Invoke(() => { var enabledChild = controlType.CreateControl(); var disabledChild = controlType.CreateControl(); var neutralChild = controlType.CreateControl(); var childPanel = new Panel(); void addControls() => childPanel.Content = new TableLayout { Rows = { enabledChild, disabledChild, neutralChild } }; void removeControls() => childPanel.Content = null; var container = containerType.CreateControl(childPanel); // load the control (for virtual containers like Stack/Dynamic layouts) container.AttachNative(); var neutralEnabled = neutralChild.Enabled; // disabled child should always be disabled disabledChild.Enabled = false; enabledChild.Enabled = true; // default values Assert.IsTrue(container.Enabled, "#1.1"); Assert.IsTrue(enabledChild.Enabled, "#1.2"); Assert.IsFalse(disabledChild.Enabled, "#1.3"); Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#1.4"); addControls(); // default values after added to the container Assert.IsTrue(container.Enabled, "#2.1"); Assert.IsTrue(enabledChild.Enabled, "#2.2"); Assert.IsFalse(disabledChild.Enabled, "#2.3"); Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#2.4"); removeControls(); // setting container to disabled container.Enabled = false; // default values after removed from the container (and container set to disabled) Assert.IsTrue(enabledChild.Enabled, "#3.1"); Assert.IsFalse(disabledChild.Enabled, "#3.2"); Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#3.3"); addControls(); // values after adding back to the container Assert.IsFalse(container.Enabled, "#4.1"); Assert.IsFalse(enabledChild.Enabled, "#4.2"); Assert.IsFalse(disabledChild.Enabled, "#4.3"); Assert.IsFalse(neutralChild.Enabled, "#4.4"); // set child to enabled when parent is disabled, should still stay disabled enabledChild.Enabled = true; Assert.IsFalse(container.Enabled, "#5.1"); Assert.IsFalse(enabledChild.Enabled, "#5.2"); Assert.IsFalse(disabledChild.Enabled, "#5.3"); Assert.IsFalse(neutralChild.Enabled, "#5.4"); removeControls(); // default values after removed from the container (again) Assert.IsTrue(enabledChild.Enabled, "#6.1"); Assert.IsFalse(disabledChild.Enabled, "#6.2"); Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#6.3"); // set container back to enabled container.Enabled = true; addControls(); Assert.IsTrue(container.Enabled, "#7.1"); Assert.IsTrue(enabledChild.Enabled, "#7.2"); Assert.IsFalse(disabledChild.Enabled, "#7.3"); Assert.AreEqual(neutralEnabled, neutralChild.Enabled, "#7.4"); }); }