Esempio n. 1
0
            protected override void LoadComplete()
            {
                base.LoadComplete();

                host.MaximumDrawHz     = int.MaxValue;
                host.MaximumUpdateHz   = int.MaxValue;
                host.MaximumInactiveHz = int.MaxValue;

                Add(test);

                Console.WriteLine($@"{(int)Time.Current}: Running {test} visual test cases...");

                // Nunit will run the tests in the TestCase with the same TestCase instance so the TestCase
                // needs to be removed before the host is exited, otherwise it will end up disposed

                test.RunAllSteps(() =>
                {
                    Scheduler.AddDelayed(() =>
                    {
                        Remove(test);
                        host.Exit();
                    }, time_between_tests);
                }, e =>
                {
                    // Other tests may run even if this one failed, so the TestCase still needs to be removed
                    Remove(test);
                    throw new Exception("The test case threw an exception while running", e);
                });
            }
            /// <summary>
            /// Blocks execution until a provided <see cref="TestCase"/> runs to completion.
            /// </summary>
            /// <param name="test">The <see cref="TestCase"/> to run.</param>
            public void RunTestBlocking(TestCase test)
            {
                Trace.Assert(host != null, $"Ensure this runner has been loaded before calling {nameof(RunTestBlocking)}");

                bool completed = false;
                ExceptionDispatchInfo exception = null;

                void complete()
                {
                    // We want to remove the TestCase from the hierarchy on completion as under nUnit, it may have operations run on it from a different thread.
                    // This is because nUnit will reuse the same class multiple times, running a different [Test] method each time, while the GameHost
                    // is run from its own asynchronous thread.
                    Remove(test);
                    completed = true;
                }

                Schedule(() =>
                {
                    Add(test);

                    Console.WriteLine($@"{(int)Time.Current}: Running {test} visual test cases...");

                    // Nunit will run the tests in the TestCase with the same TestCase instance so the TestCase
                    // needs to be removed before the host is exited, otherwise it will end up disposed

                    test.RunAllSteps(() =>
                    {
                        Scheduler.AddDelayed(complete, time_between_tests);
                    }, e =>
                    {
                        if (e is DependencyInjectionException die)
                        {
                            exception = die.DispatchInfo;
                        }
                        else
                        {
                            exception = ExceptionDispatchInfo.Capture(e);
                        }
                        complete();
                    });
                });

                while (!completed && host.ExecutionState == ExecutionState.Running)
                {
                    Thread.Sleep(10);
                }

                exception?.Throw();
            }
Esempio n. 3
0
            protected override void LoadComplete()
            {
                base.LoadComplete();

                host.MaximumDrawHz     = int.MaxValue;
                host.MaximumUpdateHz   = int.MaxValue;
                host.MaximumInactiveHz = int.MaxValue;

                Add(test);

                Console.WriteLine($@"{(int)Time.Current}: Running {test} visual test cases...");

                test.RunAllSteps(() =>
                {
                    Scheduler.AddDelayed(host.Exit, time_between_tests);
                });
            }
            /// <summary>
            /// Blocks execution until a provided <see cref="TestCase"/> runs to completion.
            /// </summary>
            /// <param name="test">The <see cref="TestCase"/> to run.</param>
            public void RunTestBlocking(TestCase test)
            {
                bool completed = false;

                void complete()
                {
                    // We want to remove the TestCase from the hierarchy on completion as under nUnit, it may have operations run on it from a different thread.
                    // This is because nUnit will reuse the same class multiple times, running a different [Test] method each time, while the GameHost
                    // is run from its own asynchronous thread.
                    Remove(test);
                    completed = true;
                }

                Schedule(() =>
                {
                    Add(test);

                    Console.WriteLine($@"{(int)Time.Current}: Running {test} visual test cases...");

                    // Nunit will run the tests in the TestCase with the same TestCase instance so the TestCase
                    // needs to be removed before the host is exited, otherwise it will end up disposed

                    test.RunAllSteps(() =>
                    {
                        Scheduler.AddDelayed(complete, time_between_tests);
                    }, e =>
                    {
                        complete();
                        throw new Exception("The test case threw an exception while running", e);
                    });
                });

                while (!completed)
                {
                    Thread.Sleep(10);
                }
            }
Esempio n. 5
0
        public void LoadTest(TestCase testCase = null, Action onCompletion = null)
        {
            if (testCase == null && Tests.Count > 0)
            {
                testCase = Tests[0];
            }

            config.Set(TestBrowserSetting.LastTest, testCase?.Name);

            if (CurrentTest != null)
            {
                testContentContainer.Remove(CurrentTest);
                CurrentTest.Clear();

                var button = getButtonFor(CurrentTest);
                if (button != null)
                {
                    button.Current = false;
                }

                CurrentTest = null;
            }

            if (testCase != null)
            {
                testContentContainer.Add(CurrentTest = testCase);
                testCase.Reset();
                testCase.RunAllSteps(onCompletion);

                var button = getButtonFor(CurrentTest);
                if (button != null)
                {
                    button.Current = true;
                }
            }
        }