Beispiel #1
0
        private ContainerRowModel CreateTypeTree(System.Type type)
        {
            var children = new List <RowModel>();

            object[]      attrs;
            Attribute     attr;
            BindingFlags  flags    = BindingFlags.Static | BindingFlags.Public;
            Lazy <object> instance = null;

            if (IsConstructable(type))
            {
                flags   |= BindingFlags.Instance;
                instance = new Lazy <object>(() => Activator.CreateInstance(type), LazyThreadSafetyMode.ExecutionAndPublication);
            }

            foreach (MethodInfo method in type.GetMethods(flags).Where(m => IsTestMethod(m, true, true, true)))
            {
                // Create a row for this method
                attrs = method.GetCustomAttributes(true);
                attr  = FindAttribute(attrs, "TestAttribute") ?? FindAttribute(attrs, "BenchmarkAttribute");
                var  eea       = FindAttribute(attrs, "ExpectedExceptionAttribute");
                bool isTestSet = method.IsStatic && MayBeTestSuite(method.ReturnType) && IsTestMethod(method, true, true, false);
                var  utt       = new UnitTestTask(method, instance, attr, eea, isTestSet);
                var  row       = new TaskRowModel(method.Name, TestNodeType.Test, utt, true);

                if (IsTestMethod(method, false, false, true)) // benchmark?
                {
                    row.BasePriority--;                       // Give benchmarks low priority by default
                }
                children.Add(row);
            }

            foreach (Type nested in type.GetNestedTypes().Where(IsTestFixtureOrSuite))
            {
                children.Add(CreateTypeTree(nested));
            }

            // Create a row for this type
            var result = new ContainerRowModel(type.Name, TestNodeType.TestFixture, children);

            result.SetSummary(type.FullName);
            attrs = type.GetCustomAttributes(true);
            attr  = FindAttribute(attrs, "TestFixtureAttribute");
            string description = GetPropertyValue <string>(attr, "Description", null);

            if (description != null)
            {
                result.SetSummary(string.Format("{0} ({1})", description, type.FullName));
            }
            return(result);
        }
Beispiel #2
0
		private ContainerRowModel CreateTypeTree(System.Type type)
		{
			var children = new List<RowModel>();
			object[] attrs;
			Attribute attr;
			BindingFlags flags = BindingFlags.Static | BindingFlags.Public;
			Lazy<object> instance = null;
			if (IsConstructable(type)) {
				flags |= BindingFlags.Instance;
				instance = new Lazy<object>(() => Activator.CreateInstance(type), LazyThreadSafetyMode.ExecutionAndPublication);
			}

			foreach (MethodInfo method in type.GetMethods(flags).Where(m => IsTestMethod(m, true, true, true)))
			{
				// Create a row for this method
				attrs = method.GetCustomAttributes(true);
				attr = FindAttribute(attrs, "TestAttribute") ?? FindAttribute(attrs, "BenchmarkAttribute");
				var eea = FindAttribute(attrs, "ExpectedExceptionAttribute");
				bool isTestSet = method.IsStatic && MayBeTestSuite(method.ReturnType) && IsTestMethod(method, true, true, false);
				var utt = new UnitTestTask(method, instance, attr, eea, isTestSet);
				var row = new TaskRowModel(method.Name, TestNodeType.Test, utt, true);
				
				if (IsTestMethod(method, false, false, true)) // benchmark?
					row.BasePriority--; // Give benchmarks low priority by default

				children.Add(row);
			}

			foreach (Type nested in type.GetNestedTypes().Where(IsTestFixtureOrSuite))
				children.Add(CreateTypeTree(nested));
			
			// Create a row for this type
			var result = new ContainerRowModel(type.Name, TestNodeType.TestFixture, children);
			result.SetSummary(type.FullName);
			attrs = type.GetCustomAttributes(true);
			attr = FindAttribute(attrs, "TestFixtureAttribute");
			string description = GetPropertyValue<string>(attr, "Description", null);
			if (description != null)
				result.SetSummary(string.Format("{0} ({1})", description, type.FullName));
			return result;
		}