예제 #1
0
        private void Initialize()
        {
            try
            {
                Reflect.CheckFixtureType(fixtureType);

                IList categories = Reflect.GetCategories(fixtureType);
                CategoryManager.Add(categories);
                this.Categories = categories;

                this.fixtureSetUp    = Reflect.GetFixtureSetUpMethod(fixtureType);
                this.fixtureTearDown = Reflect.GetFixtureTearDownMethod(fixtureType);

                this.IsExplicit = Reflect.HasExplicitAttribute(fixtureType);

                if (Reflect.HasIgnoreAttribute(fixtureType))
                {
                    this.ShouldRun    = false;
                    this.IgnoreReason = Reflect.GetIgnoreReason(fixtureType);
                }

                this.Description = Reflect.GetDescription(fixtureType);

                MethodInfo [] methods = fixtureType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
                foreach (MethodInfo method in methods)
                {
                    TestCase testCase = TestCaseBuilder.Make(fixtureType, method);
                    if (testCase != null)
                    {
                        testCase.AssemblyKey = this.AssemblyKey;
                        this.Add(testCase);
                    }
                }

                if (this.CountTestCases() == 0)
                {
                    this.ShouldRun    = false;
                    this.IgnoreReason = this.Name + " does not have any tests";
                }
            }
            catch (InvalidTestFixtureException exception)
            {
                this.ShouldRun    = false;
                this.IgnoreReason = exception.Message;
            }
        }
예제 #2
0
        /// <summary>
        /// Make a test case from a given fixture type and method
        /// </summary>
        /// <param name="fixtureType">The fixture type</param>
        /// <param name="method">MethodInfo for the particular method</param>
        /// <returns>A test case or null</returns>
        public static TestCase Make(Type fixtureType, MethodInfo method)
        {
            TestCase testCase = null;

            if (Reflect.HasTestAttribute(method) || Reflect.IsObsoleteTestMethod(method))
            {
                if (Reflect.IsTestMethodSignatureCorrect(method))
                {
                    ITestBuilder builder = GetBuilder(method);
                    testCase = builder.Make(fixtureType, method);

                    if (Reflect.HasIgnoreAttribute(method))
                    {
                        testCase.ShouldRun    = false;
                        testCase.IgnoreReason = Reflect.GetIgnoreReason(method);
                    }

                    if (Reflect.HasCategoryAttribute(method))
                    {
                        IList categories = Reflect.GetCategories(method);
                        CategoryManager.Add(categories);
                        testCase.Categories = categories;
                    }

                    testCase.IsExplicit = Reflect.HasExplicitAttribute(method);

                    testCase.Description = Reflect.GetDescription(method);
                }
                else
                {
                    testCase = new NotRunnableTestCase(method);
                }
            }

            return(testCase);
        }