Exemple #1
0
        //assemblyString = CalculatorDemoTests
        static UtItem WalkThroughProject(string assemblyString)
        {
            var projectUtItem = new UtItem();

            projectUtItem.ItemType = ItemType.TestProject;
            Assembly assembly = Assembly.LoadFrom(assemblyString);

            projectUtItem.DisplayName = assembly.GetName().Name;
            Type[] typearr = assembly.GetTypes();

            var typearr1       = typearr[0].GetCustomAttributes();
            var allTestClasses = typearr.ToList().Where(t => t.GetCustomAttributes().Any(a => a.GetType().ToString().Equals("Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute"))).ToList();

            allTestClasses.ForEach(testClass =>
            {
                var testClassItem = new UtItem {
                    DisplayName = testClass.Name, ItemType = ItemType.TestClass, TestClass = testClass
                };
                var testMethods = WalkThroughTestClass(testClass);
                testMethods.ForEach(x => testClassItem.Children.Add(x));
                projectUtItem.Children.Add(testClassItem);
            });

            return(projectUtItem);
        }
Exemple #2
0
        private static List <UtItem> WalkThroughTestClass(Type testClass)
        {
            var testMethods = new List <UtItem>();

            MethodInfo[] methodInfos = testClass.GetMethods();

            foreach (var methodInfo in methodInfos)
            {
                var attributes = methodInfo.GetCustomAttributes();

                var  enumerable       = attributes as Attribute[] ?? attributes.ToArray();
                bool isTestCaseMethod = enumerable.OfType <TestMethodAttribute>().Any();

                foreach (var attribute in enumerable)
                {
                    var type = attribute.GetType();
                    if (type.ToString().Equals("Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute"))
                    {
                        if (isTestCaseMethod)
                        {
                            continue;
                        }

                        var testMethod = new UtItem
                        {
                            DisplayName = methodInfo.Name,
                            ItemType    = ItemType.TestMethod,
                            TestClass   = testClass,
                            TestMethod  = methodInfo
                        };

                        testMethods.Add(testMethod);
                        continue;
                    }

                    if (type.ToString().Equals("Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute"))
                    {
                        var TestMethodAttribute = attribute as TestMethodAttribute;
                        if (TestMethodAttribute == null) //# To avoid resharper warning
                        {
                            break;
                        }
                        var testCaseMethod = new UtItem
                        {
                            ItemType   = ItemType.TestCaseMethod,
                            TestClass  = testClass,
                            TestMethod = methodInfo,
                            //SetUpMethod = setupMethod,
                            //TearDownMethod = tearDownMethod
                        };

                        //testCaseMethod.DisplayName = BuildTestCaseMethodDisplayName( methodInfo.Name, TestMethodAttribute );
                        //testCaseMethod.Arguments = TestMethodAttribute.Arguments;

                        testMethods.Add(testCaseMethod);
                    }
                }
            }
            return(testMethods);
        }
Exemple #3
0
        public static UtItem BuildTree(string solutionName, List <string> utAssemblies)
        {
            var root = new UtItem {
                DisplayName = solutionName
            };

            foreach (var assemblyString in utAssemblies)
            {
                root.Children.Add(WalkThroughProject(assemblyString));
            }
            return(root);
        }