Exemplo n.º 1
0
        protected virtual void                      DetermineFilters()
        {
            //Override if you don't want filtering, or want to provider your own mechanism
            try
            {
                //	/Filter
                if (TestInput.Filter != null)
                {
                    this.TestSpec.ApplyFilter(this, this.FilterScope(TestInput.Filter));
                }

                // /MaxPriority
                string maxprifilter = "//TestVariation[@Priority<='{0}']";
                if (TestInput.MaxPriority != null)
                {
                    this.TestSpec.ApplyFilter(this, String.Format(maxprifilter, TestInput.MaxPriority));
                }

                // Module [TestFilter(...)]
                if (this.Filter != null)
                {
                    this.TestSpec.ApplyFilter(this, this.FilterScope(this.Filter));
                }

                // TestCase [TestFilter(...)]
                foreach (TestItem testcase in this.Children)
                {
                    if (testcase.Filter != null)
                    {
                        this.TestSpec.ApplyFilter(testcase, this.FilterScope(testcase.Filter));
                    }
                }
            }
            catch (Exception e)
            {
                //Make this easier to debug
                TestLog.WriteLineIgnore(e.ToString());
                throw e;
            }
        }
Exemplo n.º 2
0
        protected virtual void                      DetermineIncludes()
        {
            try
            {
                //[TestInclude] attributes
                foreach (TestIncludeAttribute attr in this.GetType().GetCustomAttributes(typeof(TestIncludeAttribute), false /*inhert*/))
                {
                    //Files (either specified or search pattern)
                    string[] filenames = new string[] { attr.File };
                    if (attr.Files != null)
                    {
                        filenames = Directory.GetFiles(".", attr.Files);
                    }

                    //Loop through the files
                    foreach (string filename in filenames)
                    {
                        try
                        {
                            //Note: Prevent recursion - (ie: ignore this assembly)
                            Assembly assembly = Assembly.LoadFrom(filename);
                            if (assembly == Assembly.GetAssembly(this.GetType()))
                            {
                                continue;
                            }

                            //Find the TestModule(s) (from the specified assembly)
                            foreach (Type type in assembly.GetTypes())
                            {
                                //Were only interested in objects that inherit from TestModule
                                if (type.IsSubclassOf(typeof(TestModule)))
                                {
                                    //Create this module (call the constructor with no arguments)
                                    TestModule testmodule = (TestModule)Activator.CreateInstance(type);

                                    //Filter the module (as specified)
                                    if (attr.Filter != null)
                                    {
                                        testmodule.TestSpec.ApplyFilter(testmodule, attr.Filter);
                                    }

                                    //Add the children
                                    if (testmodule.Children.Count > 0)
                                    {
                                        //Determine what prefix to use (to distinguish testcases)
                                        string prefix = testmodule.Name;
                                        if (attr.Name != null)
                                        {
                                            prefix = attr.Name;
                                        }

                                        //Add all the testcases
                                        //TODO: What about ModuleInit/Terminate for this group?
                                        _includes.Add(testmodule);
                                        foreach (TestItem testcase in testmodule.Children)
                                        {
                                            if (prefix != null && prefix.Length > 0)
                                            {
                                                testcase.Name = (prefix + "." + testcase.Name);
                                            }
                                            Children.Add(testcase);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            //We might not be able to load all assemblies in the directory (ie: *.dll)
                            //so simply move onto the next assembly...
                            TestLog.WriteLineIgnore(e.ToString());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //Make this easier to debug
                TestLog.WriteLineIgnore(e.ToString());
                throw e;
            }
        }