private void ShowTopLevel(Control control, object[] propertyObjects, bool modal, Action <Form> shownAction) { //if (TestContext.CurrentContext.Test.Properties["_CATEGORIES"]) ThrowIfPropertyObjectsContainsActionDueToLikelyMisuse(propertyObjects); GuiTestHelper.Initialize(); formShown = shownAction; if (control.TopLevelControl == control) { ShowTopLevelControl(control, modal); } else { ShowControlInTestForm(control, modal, propertyObjects); } // clear all controls shown as non-modal after modal control closes if (!modal) { string testName = TestContext.CurrentContext.Test.FullName; if (string.IsNullOrEmpty(nonModalControlsTestName)) { nonModalControlsTestName = testName; } else { if (nonModalControlsTestName != testName) { string errorMessage = $"Did you forget to call WindowsFormsTestHelper.CloseAll() at the end of the following test: {nonModalControlsTestName}?"; nonModalControlsTestName = testName; // reset for the next test throw new InvalidOperationException(errorMessage); } } nonModalControls.Add(this); } else { CloseAll(); Dispose(); control.Dispose(); } }
private void ShowTopLevel(Control control, object[] propertyObjects, bool modal, Action onShownAction) { ThrowIfPropertyObjectsContainsActionDueToLikelyMisuse(propertyObjects); GuiTestHelper.Initialize(); shownAction = onShownAction; if (control is Window) { ShowTopLevelControl(control, modal); } else { ShowControlInTestForm(modal); } // clear all controls shown as non-modal after modal control closes if (!modal) { throw new NotImplementedException(); } WindowsFormsTestHelper.CloseAll(); // just in case, since we have mixed WPF / WF app Close(); if (window != null) { window.Closed += WindowOnClosed; window.Close(); window.Close(); while (window.IsVisible) { Application.DoEvents(); Application.DoEvents(); window.Close(); } window.Closed -= WindowOnClosed; window = null; } }
private void WaitOrExit(Control control, bool modal) { // wait until control is shown while (!wasShown && GuiTestHelper.Exception == null) { Application.DoEvents(); } // is shown, not trigger action try { Application.DoEvents(); if (formShown != null && wasShown) { var form = control as Form; formShown(form ?? this); } } finally { formShown = null; } // if not on build server - wait until control is closed if (!GuiTestHelper.IsBuildServer && modal) { while (control.Visible) { Application.DoEvents(); } } if (GuiTestHelper.Exception != null) { GuiTestHelper.RethrowUnhandledException(); } }