Exemplo n.º 1
0
        public async void TestMainWindowThenModalBox()
        {
            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
                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 modal window
                var modalWindowInfo   = WindowManager.ModalWindows[0];
                var modalWindowClosed = WindowManagerHelper.NextModalWindowClosed(modalWindow);
                dispatcher.Invoke(() => modalWindow.Close());
                await WindowManagerHelper.TaskWithTimeout(modalWindowClosed);

                dispatcher.Invoke(() =>
                {
                    WindowManagerHelper.AssertWindowClosed(modalWindowInfo);
                    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 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.º 3
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.º 4
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();
        }