Exemplo n.º 1
0
        private static void TestExit_TestLogic()
        {
            MainGameLogic.ThrowErrorInsteadOfMessageBox = true;
            Dispatcher MainDispatcher = Dispatcher.CurrentDispatcher;

            App _App = new App();

            _App.InitializeComponent();


            Task.Run(() => {
                Thread.Sleep(500);

                MainDispatcher.Invoke(() => {
                    MainMenu mm = UIAutomationHelper.FindVisualChild <MainMenu>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                    (x) => {
                        return(x.GetType() == typeof(MainMenu));
                    }
                                                                                    ));
                    Button b = UIAutomationHelper.FindVisualChild <Button>(mm, (Func <FrameworkElement, bool>)(
                                                                               (x) => {
                        return(x.Name == "Exit");
                    }
                                                                               ));

                    UIAutomationHelper.Click(mm, "Exit_Click", b);
                });

                Thread.Sleep(100);

                MainDispatcher.Invoke(() => {
                    bool works = false;
                    try {
                        _App.MainWindow.Focus();
                    } catch {
                        works = true;
                    }
                    AppDomain.CurrentDomain.SetData("AssertIsTrue", works);
                });

                Thread.Sleep(1000);

                MainDispatcher.Invoke(() => {
                    _App.Shutdown();
                });
            });
            _App.Run(new MainWindow());
        }
Exemplo n.º 2
0
        private static void TestGameOver_NewGame_TestLogic()
        {
            Dispatcher MainDispatcher = Dispatcher.CurrentDispatcher;

            App _App = new App();

            _App.InitializeComponent();

            Task.Run(() => {
                Thread.Sleep(500);

                MainDispatcher.Invoke(() => {
                    TextBox t1 = UIAutomationHelper.FindVisualChild <TextBox>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                  (x) => {
                        return(x.Name == "Player1Name");
                    }
                                                                                  ));
                    t1.Text    = "P1";
                    TextBox t2 = UIAutomationHelper.FindVisualChild <TextBox>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                  (x) => {
                        return(x.Name == "Player2Name");
                    }
                                                                                  ));
                    t2.Text = "P2";
                });

                Thread.Sleep(100);

                MainDispatcher.Invoke(() => {
                    MainMenu mm = UIAutomationHelper.FindVisualChild <MainMenu>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                    (x) => {
                        return(x.GetType() == typeof(MainMenu));
                    }
                                                                                    ));

                    Button b = UIAutomationHelper.FindVisualChild <Button>(mm, (Func <FrameworkElement, bool>)(
                                                                               (x) => {
                        return(x.Name == "NewGameButton");
                    }
                                                                               ));

                    UIAutomationHelper.Click(mm, "NewGameButton_Click", b);
                });

                Thread.Sleep(100);

                MainDispatcher.Invoke(() => {
                    GameScreen gs = UIAutomationHelper.FindVisualChild <GameScreen>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                        (x) => {
                        return(x.GetType() == typeof(GameScreen));
                    }
                                                                                        ));
                    UniformGrid ug = UIAutomationHelper.FindVisualChild <UniformGrid>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                          (x) => {
                        return(x.Name == "GameGrid");
                    }
                                                                                          ));
                    int rows    = ug.Rows;
                    int columns = ug.Columns;

                    //+ columns * rows
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[0 * rows + 0]); //white

                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[0 * rows + 1]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[1 * rows + 1]); //white --usedForNextCapture
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[0 * rows + 2]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[0 * rows + 3]); //white-capture

                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[1 * rows + 2]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[2 * rows + 0]); //white --usedForNextCapture
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[1 * rows + 3]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[1 * rows + 4]); //white-capture

                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[2 * rows + 1]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[3 * rows + 1]); //white --usedForNextCapture
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[2 * rows + 2]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[2 * rows + 3]); //white-capture

                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[3 * rows + 2]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[4 * rows + 0]); //white --usedForNextCapture
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[3 * rows + 3]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[3 * rows + 4]); //white-capture

                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[4 * rows + 1]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[5 * rows + 1]); //white --waste
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[4 * rows + 2]); //black
                    UIAutomationHelper.Click(gs, "StoneOnMouseLeftButtonDown", ug.Children[4 * rows + 3]); //white-capture
                });

                Thread.Sleep(100);

                MainDispatcher.Invoke(() => {
                    GameOverScreen mm = UIAutomationHelper.FindVisualChild <GameOverScreen>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                                (x) => {
                        return(x.GetType() == typeof(GameOverScreen));
                    }
                                                                                                ));

                    Button b = UIAutomationHelper.FindVisualChild <Button>(mm, (Func <FrameworkElement, bool>)(
                                                                               (x) => {
                        return(x.Name == "NewGameButton");
                    }
                                                                               ));

                    UIAutomationHelper.Click(mm, "NewGameButton_Click", b);
                });

                Thread.Sleep(100);

                MainDispatcher.Invoke(() => {
                    MainMenu mm = UIAutomationHelper.FindVisualChild <MainMenu>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                    (x) => {
                        return(x.GetType() == typeof(MainMenu));
                    }
                                                                                    ));

                    AppDomain.CurrentDomain.SetData("AssertTrue", mm != null);
                });

                MainDispatcher.Invoke(() => {
                    _App.MainWindow.Focus();
                });

                Thread.Sleep(1000);

                MainDispatcher.Invoke(() => {
                    _App.Shutdown();
                });
            });
            _App.Run(new MainWindow());
        }
Exemplo n.º 3
0
        private static void TestGameStart_WithPlayerNames_WithDefaultSize_TestLogic()
        {
            MainGameLogic.ThrowErrorInsteadOfMessageBox = true;
            bool works = true;
            App  _App  = null;

            try {
                Dispatcher MainDispatcher = Dispatcher.CurrentDispatcher;

                _App = new App();
                _App.InitializeComponent();


                Task.Run(() => {
                    Thread.Sleep(500);

                    MainDispatcher.Invoke(() => {
                        TextBox t1 = UIAutomationHelper.FindVisualChild <TextBox>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                      (x) => {
                            return(x.Name == "Player1Name");
                        }
                                                                                      ));
                        t1.Text    = "P1";
                        TextBox t2 = UIAutomationHelper.FindVisualChild <TextBox>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                      (x) => {
                            return(x.Name == "Player2Name");
                        }
                                                                                      ));
                        t2.Text = "P2";
                    });

                    Thread.Sleep(100);

                    MainDispatcher.Invoke(() => {
                        MainMenu mm = UIAutomationHelper.FindVisualChild <MainMenu>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                        (x) => {
                            return(x.GetType() == typeof(MainMenu));
                        }
                                                                                        ));

                        Button b = UIAutomationHelper.FindVisualChild <Button>(mm, (Func <FrameworkElement, bool>)(
                                                                                   (x) => {
                            return(x.Name == "NewGameButton");
                        }
                                                                                   ));

                        UIAutomationHelper.Click(mm, "NewGameButton_Click", b);
                    });
                    MainDispatcher.Invoke(() => {
                        _App.MainWindow.Focus();
                    });

                    Thread.Sleep(1000);

                    MainDispatcher.Invoke(() => {
                        _App.Shutdown();
                    });
                });
                _App.Run(new MainWindow());
            } catch {
                works = false;
            } finally {
                _App?.Shutdown();
            }
            AppDomain.CurrentDomain.SetData("AssertIsTrue", works);
        }
Exemplo n.º 4
0
        private static void TestPlayerNamesPersistOnGameStart_TestLogic()
        {
            MainGameLogic.ThrowErrorInsteadOfMessageBox = true;
            bool works = true;
            App  _App  = null;

            try {
                Dispatcher MainDispatcher = Dispatcher.CurrentDispatcher;

                _App = new App();
                _App.InitializeComponent();


                Task.Run(() => {
                    Thread.Sleep(500);

                    MainDispatcher.Invoke(() => {
                        TextBox t1 = UIAutomationHelper.FindVisualChild <TextBox>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                      (x) => {
                            return(x.Name == "Player1Name");
                        }
                                                                                      ));
                        t1.Text    = "P1";
                        TextBox t2 = UIAutomationHelper.FindVisualChild <TextBox>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                      (x) => {
                            return(x.Name == "Player2Name");
                        }
                                                                                      ));
                        t2.Text = "P2";
                    });

                    Thread.Sleep(100);

                    MainDispatcher.Invoke(() => {
                        MainMenu mm = UIAutomationHelper.FindVisualChild <MainMenu>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                        (x) => {
                            return(x.GetType() == typeof(MainMenu));
                        }
                                                                                        ));

                        Button b = UIAutomationHelper.FindVisualChild <Button>(mm, (Func <FrameworkElement, bool>)(
                                                                                   (x) => {
                            return(x.Name == "NewGameButton");
                        }
                                                                                   ));

                        UIAutomationHelper.Click(mm, "NewGameButton_Click", b);
                    });

                    Thread.Sleep(100);

                    MainDispatcher.Invoke(() => {
                        GameScreen gs = UIAutomationHelper.FindVisualChild <GameScreen>(_App.MainWindow, (Func <FrameworkElement, bool>)(
                                                                                            (x) => {
                            return(x.GetType() == typeof(GameScreen));
                        }
                                                                                            ));

                        PlayerStatsUC p1 = UIAutomationHelper.FindVisualChild <PlayerStatsUC>(gs, (Func <FrameworkElement, bool>)(
                                                                                                  (x) => {
                            return(x.Name == "Player1Status");
                        }
                                                                                                  ));
                        PlayerStatsUC p2 = UIAutomationHelper.FindVisualChild <PlayerStatsUC>(gs, (Func <FrameworkElement, bool>)(
                                                                                                  (x) => {
                            return(x.Name == "Player2Status");
                        }
                                                                                                  ));

                        Label p1l = UIAutomationHelper.FindVisualChild <Label>(p1, (Func <FrameworkElement, bool>)(
                                                                                   (x) => {
                            return(x.Name == "MainLabel");
                        }
                                                                                   ));
                        Label p2l = UIAutomationHelper.FindVisualChild <Label>(p2, (Func <FrameworkElement, bool>)(
                                                                                   (x) => {
                            return(x.Name == "MainLabel");
                        }
                                                                                   ));

                        bool shouldBeTrue =
                            (p1l.Content as string).Contains("P1") &&
                            (p2l.Content as string).Contains("P2");
                        AppDomain.CurrentDomain.SetData("AssertTrue", shouldBeTrue);
                    });

                    Thread.Sleep(100);

                    MainDispatcher.Invoke(() => {
                        _App.MainWindow.Focus();
                    });

                    Thread.Sleep(1000);

                    MainDispatcher.Invoke(() => {
                        _App.Shutdown();
                    });
                });
                _App.Run(new MainWindow());
            } catch {
                works = false;
            } finally {
                _App?.Shutdown();
            }
            AppDomain.CurrentDomain.SetData("AssertIsTrue", works);
        }