Ejemplo n.º 1
0
        public void LoadTest(Type testType = null, Action onCompletion = null)
        {
            runAllComplete();

            if (testType == null && TestTypes.Count > 0)
            {
                testType = TestTypes[0];
            }

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

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

            if (testType != null)
            {
                assemblyDropdown.RemoveDropdownItem(assemblyDropdown.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"))
                {
                    assemblyDropdown.AddDropdownItem($"dynamic ({testType.Name})", testType.Assembly);
                }

                assemblyDropdown.Current.Value = testType.Assembly;

                testContentContainer.Add(CurrentTest = (TestCase)Activator.CreateInstance(testType));
                if (!interactive)
                {
                    CurrentTest.OnLoadComplete = d => ((TestCase)d).RunAllSteps(onCompletion);
                }

                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);

                CurrentTest.RunFirstStep();
            }

            updateButtons();
        }
Ejemplo n.º 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(DynamicClassCompiler.DYNAMIC_ASSEMBLY_NAME)).Value);

                // if we are a dynamically compiled type (via DynamicClassCompiler) we should update the dropdown accordingly.
                if (testType.Assembly.FullName.Contains(DynamicClassCompiler.DYNAMIC_ASSEMBLY_NAME))
                {
                    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();
                };
            }
        }
Ejemplo n.º 3
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);

            const string dynamic = "dynamic";

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

            Assembly.Value = testType.Assembly;

            CurrentTest = newTest;

            updateButtons();

            CurrentFrame.Value = 0;
            if (RecordState.Value == Testing.RecordState.Stopped)
            {
                RecordState.Value = Testing.RecordState.Normal;
            }

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

            newTest.OnLoadComplete = d => Schedule(() =>
            {
                if (lastTest?.Parent != null)
                {
                    testContentContainer.Remove(lastTest.Parent);
                    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"))
                {
                    if (m.GetCustomAttributes(typeof(TestAttribute), false).Any())
                    {
                        var step         = CurrentTest.AddStep($"Setup: {m.Name}", () => setUpMethods.ForEach(s => s.Invoke(CurrentTest, null)));
                        step.LightColour = Color4.Teal;
                        m.Invoke(CurrentTest, null);
                    }

                    foreach (var tc in m.GetCustomAttributes(typeof(TestCaseAttribute), false).OfType <TestCaseAttribute>())
                    {
                        var step         = CurrentTest.AddStep($"Setup: {m.Name}({string.Join(", ", tc.Arguments)})", () => setUpMethods.ForEach(s => s.Invoke(CurrentTest, null)));
                        step.LightColour = Color4.Teal;
                        m.Invoke(CurrentTest, tc.Arguments);
                    }
                }

                backgroundCompiler?.Checkpoint(CurrentTest);
                runTests(onCompletion);
                updateButtons();
            });
        }