Esempio n. 1
0
        public void AddAssembly(string name, Assembly assembly)
        {
            const string dynamic_assembly_identifier = "dynamic";

            assemblyDropdown.RemoveDropdownItem(assemblyDropdown.Items.LastOrDefault(i => i.Key.Contains(dynamic_assembly_identifier)).Value);
            assemblyDropdown.AddDropdownItem(name, assembly);
        }
Esempio n. 2
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();
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new TestBrowser that displays the TestCases of every assembly that start with either "osu" or the specified namespace (if it isn't null)
        /// </summary>
        /// <param name="assemblyNamespace">Assembly prefix which is used to match assemblies whose tests should be displayed</param>
        public TestBrowser(string assemblyNamespace = null)
        {
            assemblyDropdown = new BasicDropdown <Assembly>
            {
                Width = 400,
            };

            assemblyDropdown.Current.ValueChanged += updateList;

            var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
            var loadedPaths      = loadedAssemblies.Where(a => !a.IsDynamic).Select(a => a.Location).ToArray();

            var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*Test*.dll");
            var toLoad          = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();

            toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));

            //we want to build the lists here because we're interested in the assembly we were *created* on.
            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies().Where(n => n.FullName.StartsWith("osu") || assemblyNamespace != null && n.FullName.StartsWith(assemblyNamespace)))
            {
                var tests = asm.GetLoadableTypes().Where(t => t.IsSubclassOf(typeof(TestCase)) && !t.IsAbstract).ToList();

                if (!tests.Any())
                {
                    continue;
                }

                assemblyDropdown.AddDropdownItem(asm.GetName().Name, asm);
                foreach (Type type in tests)
                {
                    TestTypes.Add(type);
                }
            }

            TestTypes.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal));
        }