Exemplo n.º 1
0
        public async Task TestOpenCloseWindow()
        {
            LoggerResult loggerResult;
            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));

                // 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();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
 public async Task TestInitDistroy()
 {
     LoggerResult loggerResult;
     var dispatcher = await WindowManagerHelper.CreateUIThread();
     using (WindowManagerHelper.InitWindowManager(dispatcher, out loggerResult))
     {
     }
     dispatcher.InvokeShutdown();
 }
Exemplo n.º 4
0
        public async void TestMainWindowThenModalBoxClosedBeforeShown()
        {
            LoggerResult loggerResult;
            const string messageBoxName = nameof(TestMainWindowThenModalBox);
            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 modal window and close it before it has a chance to be shown
                var modalWindow = dispatcher.Invoke(() => new StandardWindow {
                    Title = messageBoxName
                });
                var modalWindowOpened = WindowManagerHelper.NextModalWindowOpened(modalWindow);
                var modalWindowClosed = WindowManagerHelper.NextModalWindowClosed(modalWindow);
                dispatcher.Invoke(() =>
                {
                    WindowManager.ShowModal(modalWindow);
                    modalWindow.Close();
                });

                await WindowManagerHelper.TaskWithTimeout(modalWindowClosed);

                // The window never shown, this task should not be completed.
                Assert.False(modalWindowOpened.IsCompleted);
                dispatcher.Invoke(() => 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();
        }
Exemplo n.º 5
0
        public async void TestMainWindowThenModalBoxCloseMain()
        {
            LoggerResult loggerResult;
            const string messageBoxName = nameof(TestMainWindowThenModalBoxCloseMain);
            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 modal window
                var modalWindow = dispatcher.Invoke(() => new StandardWindow {
                    Title = messageBoxName
                });
                var modalWindowOpened = WindowManagerHelper.NextModalWindowOpened(modalWindow);
                dispatcher.InvokeAsync(() => WindowManager.ShowModal(modalWindow));
                await WindowManagerHelper.TaskWithTimeout(modalWindowOpened);

                dispatcher.Invoke(() => WindowManagerHelper.AssertWindowsStatus(window, modalWindow));

                // Close the main window - this should also close the modal window
                var mainWindow        = WindowManager.MainWindow;
                var modalWindowInfo   = WindowManager.ModalWindows[0];
                var hidden            = WindowManagerHelper.NextMainWindowChanged(null);
                var modalWindowClosed = WindowManagerHelper.NextModalWindowClosed(modalWindow);
                dispatcher.Invoke(() => window.Close());
                await WindowManagerHelper.TaskWithTimeout(Task.WhenAll(hidden, modalWindowClosed));

                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowClosed(mainWindow);
                    WindowManagerHelper.AssertWindowClosed(modalWindowInfo);
                    WindowManagerHelper.AssertWindowsStatus(null);
                });
            }
            Assert.AreEqual(false, loggerResult.HasErrors);
            dispatcher.InvokeShutdown();
        }
Exemplo n.º 6
0
        public async void TestModalBoxThenCloseThenModalBox()
        {
            LoggerResult loggerResult;
            const string messageBoxName = nameof(TestMainWindowThenModalBox);
            var          dispatcher     = await WindowManagerHelper.CreateUIThread();

            using (WindowManagerHelper.InitWindowManager(dispatcher, out loggerResult))
            {
                // Open a modal window
                var modalWindow1 = dispatcher.Invoke(() => new StandardWindow {
                    Title = messageBoxName
                });
                var modalWindowOpened1 = WindowManagerHelper.NextModalWindowOpened(modalWindow1);
                dispatcher.InvokeAsync(() => WindowManager.ShowModal(modalWindow1));
                await WindowManagerHelper.TaskWithTimeout(modalWindowOpened1);

                dispatcher.Invoke(() => WindowManagerHelper.AssertWindowsStatus(null, modalWindow1));

                // Close the modal window and open another one immediately
                var modalWindow2 = dispatcher.Invoke(() => new StandardWindow {
                    Title = messageBoxName
                });
                //var hidden = WindowManagerHelper.NextMainWindowChanged();
                var modalWindowOpened2 = WindowManagerHelper.NextModalWindowOpened(modalWindow2);
                dispatcher.Invoke(() =>
                {
                    modalWindow1.Close();
                    // Since we're in the same frame the dispatcher thread didn't had the opportunity to execute the WindowHidden method of WindowManager yet.
                    // We ensure that showing the next window does not throw.
                    Assert.DoesNotThrow(() => WindowManager.ShowModal(modalWindow2));
                });

                // Then we verify that the second window is properly initialized
                await WindowManagerHelper.TaskWithTimeout(modalWindowOpened2);

                dispatcher.Invoke(() => WindowManagerHelper.AssertWindowsStatus(null, modalWindow2));

                // Close the modal window
                dispatcher.Invoke(() => modalWindow2.Close());
            }
            Assert.AreEqual(false, loggerResult.HasErrors);
            dispatcher.InvokeShutdown();
        }
Exemplo n.º 7
0
        public async Task TestSameModalTwice()
        {
            LoggerResult loggerResult;
            const string messageBoxName = nameof(TestMainWindowThenModalBoxCloseMain);
            var dispatcher = await WindowManagerHelper.CreateUIThread();
            using (WindowManagerHelper.InitWindowManager(dispatcher, out loggerResult))
            {
                // Open a modal window
                var modalWindow = dispatcher.Invoke(() => new StandardWindow { Title = messageBoxName });
                var modalWindowOpened = WindowManagerHelper.NextModalWindowOpened(modalWindow);
                dispatcher.InvokeAsync(() => WindowManager.ShowModal(modalWindow));
                await WindowManagerHelper.TaskWithTimeout(modalWindowOpened);
                dispatcher.Invoke(() => WindowManagerHelper.AssertWindowsStatus(null, modalWindow));

                // Try to open it again without having closed it
                Assert.Throws<InvalidOperationException>(() => dispatcher.Invoke(() => WindowManager.ShowModal(modalWindow)));
            }
            Assert.AreEqual(false, loggerResult.HasErrors);
            dispatcher.InvokeShutdown();
        }
Exemplo n.º 8
0
        public async Task TestMainWindowThenModalBoxThenBackgroundModal()
        {
            LoggerResult loggerResult;
            const string messageBoxName = nameof(TestMainWindowThenModalBoxThenBackgroundModal);
            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 first modal window
                var modalWindow1 = dispatcher.Invoke(() => new StandardWindow { Title = messageBoxName });
                var modalWindow1Opened = WindowManagerHelper.NextModalWindowOpened(modalWindow1);
                dispatcher.InvokeAsync(() => WindowManager.ShowModal(modalWindow1));
                await WindowManagerHelper.TaskWithTimeout(modalWindow1Opened);
                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowsStatus(window, modalWindow1);
                });

                // Open a second modal window in background
                var modalWindow2 = dispatcher.Invoke(() => new StandardWindow { Title = messageBoxName });
                var modalWindow2Opened = WindowManagerHelper.NextModalWindowOpened(modalWindow2);
                dispatcher.InvokeAsync(() => WindowManager.ShowModal(modalWindow2, WindowOwner.MainWindow));
                await WindowManagerHelper.TaskWithTimeout(modalWindow2Opened);
                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowsStatus(window, modalWindow2, modalWindow1);
                });

                // Close the first modal window
                var modalWindow1Info = WindowManager.ModalWindows[1];
                var modalWindow1Closed = WindowManagerHelper.NextModalWindowClosed(modalWindow1);
                dispatcher.Invoke(() => modalWindow1.Close());
                await WindowManagerHelper.TaskWithTimeout(modalWindow1Closed);
                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowClosed(modalWindow1Info);
                    WindowManagerHelper.AssertWindowsStatus(window, modalWindow2);
                });

                // Close the second modal window
                var modalWindow2Info = WindowManager.ModalWindows[0];
                var modalWindow2Closed = WindowManagerHelper.NextModalWindowClosed(modalWindow2);
                dispatcher.Invoke(() => modalWindow2.Close());
                await WindowManagerHelper.TaskWithTimeout(modalWindow2Closed);
                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowClosed(modalWindow2Info);
                    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();
        }