예제 #1
0
        /// <summary>
        /// Detects all test methods of all types
        /// (Test, Before, After, etc.) in given class
        /// </summary>
        /// <param name="classToTest">Class with tests</param>
        /// <returns>Container with all test methods</returns>
        private TestMethodsContainer FindTestMethodsInClass(Type classToTest)
        {
            var result = new TestMethodsContainer();

            foreach (var method in classToTest.GetMethods())
            {
                if (method.GetCustomAttribute(typeof(TestAttribute)) != null)
                {
                    result.TestMethods.Add(method);
                }
                else if (method.GetCustomAttribute(typeof(AfterAttribute)) != null)
                {
                    result.AfterMethods.Add(method);
                }
                else if (method.GetCustomAttribute(typeof(BeforeAttribute)) != null)
                {
                    result.BeforeMethods.Add(method);
                }
                else if (method.GetCustomAttribute(typeof(AfterClassAttribute)) != null)
                {
                    result.AfterClassMethods.Add(method);
                }
                else if (method.GetCustomAttribute(typeof(BeforeClassAttribute)) != null)
                {
                    result.BeforeClassMethods.Add(method);
                }
            }

            return(result);
        }
예제 #2
0
 /// <summary>
 /// Reports that all tests in class failed and generates full report
 /// </summary>
 /// <param name="container">Container with all test methods</param>
 /// <param name="message">Custom message</param>
 /// <returns>Testing reports</returns>
 private void ReportAllTestsFailed(
     ConcurrentQueue <TestResult> outContainer,
     TestMethodsContainer container,
     string message)
 {
     foreach (var test in container.TestMethods)
     {
         outContainer.Enqueue(this.ReportTestFailed(test, message));
     }
 }