Пример #1
0
        public void LoadTest(Type testType = null, Action onCompletion = null, bool isDynamicLoad = false)
        {
            if (testType == null && TestTypes.Count > 0)
            {
                testType = TestTypes[0];
            }

            config.Set(TestBrowserSetting.LastTest, testType?.Name ?? string.Empty);

            var lastTest = CurrentTest;

            if (testType == null)
            {
                return;
            }

            var newTest = (TestCase)Activator.CreateInstance(testType);

            var dropdown = toolbar.AssemblyDropdown;

            const string dynamic = "dynamic";

            dropdown.RemoveDropdownItem(dropdown.Items.LastOrDefault(i => i.Value.FullName.Contains(dynamic)).Value);

            // if we are a dynamically compiled type (via DynamicClassCompiler) we should update the dropdown accordingly.
            if (isDynamicLoad)
            {
                dropdown.AddDropdownItem($"{dynamic} ({testType.Name})", testType.Assembly);
            }
            else
            {
                TestTypes.RemoveAll(t => t.Assembly.FullName.Contains(dynamic));
            }

            dropdown.Current.Value = testType.Assembly;

            CurrentTest = newTest;

            updateButtons();

            testContentContainer.Add(new ErrorCatchingDelayedLoadWrapper(CurrentTest, isDynamicLoad)
            {
                OnCaughtError = compileFailed
            });

            newTest.OnLoadComplete = d => Schedule(() =>
            {
                if (lastTest?.Parent != null)
                {
                    testContentContainer.Remove(lastTest.Parent);
                    lastTest.Clear();
                    lastTest.Dispose();
                }

                if (CurrentTest != newTest)
                {
                    // There could have been multiple loads fired after us. In such a case we want to silently remove ourselves.
                    testContentContainer.Remove(newTest.Parent);
                    return;
                }

                updateButtons();

                var methods = testType.GetMethods();

                var setUpMethods = methods.Where(m => m.GetCustomAttributes(typeof(SetUpAttribute), false).Length > 0);

                foreach (var m in methods.Where(m => m.Name != "TestConstructor" && m.GetCustomAttributes(typeof(TestAttribute), false).Length > 0))
                {
                    var step         = CurrentTest.AddStep($"Setup: {m.Name}", () => setUpMethods.ForEach(s => s.Invoke(CurrentTest, null)));
                    step.LightColour = Color4.Teal;
                    m.Invoke(CurrentTest, null);
                }

                backgroundCompiler.Checkpoint(CurrentTest);
                runTests(onCompletion);
                updateButtons();
            });
        }
Пример #2
0
        public void LoadTest(Type testType = null, Action onCompletion = null)
        {
            if (testType == null && TestTypes.Count > 0)
            {
                testType = TestTypes[0];
            }

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

            var lastTest = CurrentTest;

            CurrentTest = null;

            if (testType != null)
            {
                var dropdown = toolbar.AssemblyDropdown;

                dropdown.RemoveDropdownItem(dropdown.Items.LastOrDefault(i => i.Value.FullName.Contains("DotNetCompiler")).Value);

                // if we are a dynamically compiled type (via DynamicClassCompiler) we should update the dropdown accordingly.
                if (testType.Assembly.FullName.Contains("DotNetCompiler"))
                {
                    dropdown.AddDropdownItem($"dynamic ({testType.Name})", testType.Assembly);
                }

                dropdown.Current.Value = testType.Assembly;

                var newTest = (TestCase)Activator.CreateInstance(testType);

                CurrentTest = newTest;

                updateButtons();

                testContentContainer.Add(new DelayedLoadWrapper(CurrentTest, 0));

                newTest.OnLoadComplete = d =>
                {
                    if (lastTest?.Parent != null)
                    {
                        testContentContainer.Remove(lastTest.Parent);
                        lastTest.Clear();
                    }

                    if (CurrentTest != newTest)
                    {
                        // There could have been multiple loads fired after us. In such a case we want to silently remove ourselves.
                        testContentContainer.Remove(newTest.Parent);
                        return;
                    }

                    updateButtons();

                    var methods = testType.GetMethods();

                    var setUpMethod = methods.FirstOrDefault(m => m.GetCustomAttributes(typeof(SetUpAttribute), false).Length > 0);

                    foreach (var m in methods.Where(m => m.Name != "TestConstructor" && m.GetCustomAttributes(typeof(TestAttribute), false).Length > 0))
                    {
                        var step = CurrentTest.AddStep(m.Name, () => { setUpMethod?.Invoke(CurrentTest, null); });
                        step.BackgroundColour = Color4.Teal;
                        m.Invoke(CurrentTest, null);
                    }

                    backgroundCompiler.Checkpoint(CurrentTest);
                    runTests(onCompletion);
                    updateButtons();
                };
            }
        }
 /// <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) => runner.RunTestBlocking(test);