예제 #1
0
        public async void TestMainWindowThenMessageBox()
        {
            LoggerResult loggerResult;
            const string messageBoxName = nameof(TestMainWindowThenMessageBox);
            var          dispatcher     = await WindowManagerHelper.CreateUIThread();

            using (WindowManagerHelper.InitWindowManager(dispatcher, out loggerResult))
            {
                var window = dispatcher.Invoke(() => new StandardWindow());

                // Open the main window
                var shown = WindowManagerHelper.NextMainWindowChanged(window);
                dispatcher.Invoke(() => WindowManager.ShowMainWindow(window));
                await WindowManagerHelper.TaskWithTimeout(shown);

                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowsStatus(window);
                });

                // Open a message box
                var messageBoxOpened = WindowManagerHelper.NextMessageBoxOpened();
                dispatcher.InvokeAsync(() => MessageBox.Show("Test", messageBoxName));
                await WindowManagerHelper.TaskWithTimeout(messageBoxOpened);

                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowsStatus(window, null);
                });

                // Close the message box
                var messageBoxInfo   = WindowManager.ModalWindows[0];
                var messageBoxClosed = WindowManagerHelper.NextMessageBoxClosed();
                WindowManagerHelper.KillWindow(messageBoxInfo.Hwnd);
                await WindowManagerHelper.TaskWithTimeout(messageBoxClosed);

                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowClosed(messageBoxInfo);
                    WindowManagerHelper.AssertWindowsStatus(window);
                });

                // Close the main window
                var mainWindow = WindowManager.MainWindow;
                var hidden     = WindowManagerHelper.NextMainWindowChanged(null);
                dispatcher.Invoke(() => window.Close());
                await WindowManagerHelper.TaskWithTimeout(hidden);

                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowClosed(mainWindow);
                    WindowManagerHelper.AssertWindowsStatus(null);
                });
            }
            Assert.AreEqual(false, loggerResult.HasErrors);
            dispatcher.InvokeShutdown();
        }