GetAttributes() public static method

Given a test method, returns the attributes (if any) that are of the decoratingAttribute parameter's type.
public static GetAttributes ( ITestMethod method, Type decoratingAttribute, bool inherit ) : ICollection
method ITestMethod ITestMethod instance.
decoratingAttribute System.Type Attribute of interest.
inherit bool Whether to inherit attributes.
return ICollection
        /// <summary>
        /// First invoke, plan for the method's execution.
        /// </summary>
        protected override void FirstInvoke()
        {
            // [Ignore]
            if (Provider.HasCapability(UnitTestProviderCapabilities.MethodCanIgnore) && _testMethod.Ignore)
            {
                LogWriter.Ignore(TestGranularity.TestScenario, _testMethod.Name);
                return;
            }

            _testMethod.DecorateInstance(_instance);

            _testMethod.WriteLine += (object sender, StringEventArgs e) => OnWriteLine(e);

            // Log Start
            LogStartMessage();

            // [Bug] attributes that are not fixed modify test method logic
            ICollection <Attribute> bugs = ReflectionUtility.GetAttributes(_testMethod, typeof(BugAttribute), false);

            if (bugs != null && bugs.Count > 0)
            {
                foreach (Attribute attribute in bugs)
                {
                    BugAttribute bug = attribute as BugAttribute;
                    if (!bug.Fixed)
                    {
                        _bugAttributePresent = true;
                        LogWriter.KnownIssue(bug.Description);
                    }
                }
            }

            // [TestInitialize]
            if (_testClass.TestInitializeMethod != null)
            {
                EnqueueMethodDispatcher(_testClass.TestInitializeMethod);
            }

            // Track the approximate starting time - actual start time is >= 1 dispatcher interval
            EnqueueQuick(() => _started = DateTime.Now);

            // [TestMethod] - actual test scenario
            _mainTestMethodContainer = new UnitTestMethodContainer(TestHarness, _instance, _testMethod.Method, _testMethod, TestGranularity.TestScenario);
            _mainTestMethodContainer.UnhandledException += new EventHandler <UnhandledExceptionEventArgs>(UnhandledMethodException);
            _mainTestMethodContainer.Complete           += new EventHandler(CompleteMethod);
            Enqueue(_mainTestMethodContainer);

            // [TestCleanup]
            if (_testClass.TestCleanupMethod != null)
            {
                EnqueueMethodDispatcher(_testClass.TestCleanupMethod);
            }

            // Log End
            EnqueueQuick(LogEndMessage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reflect, read and prepare the tags for the class metadata. Performs
        /// the work if this is the first time the metadata has been seen.
        /// </summary>
        /// <param name="test">The reflection object for the test class.</param>
        private void CreateClassTags(Type test)
        {
            // 1. Full class name
            _classTags.Add(test.FullName);

            // 2. Class name
            _classTags.Add(test.Name);

            // 3. All [Tag] attributes on the type
            foreach (Attribute attribute in ReflectionUtility.GetAttributes(test, TagType))
            {
                _classTags.Add(attribute);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reflect, read and prepare the tags for the method metadata. Performs
        /// the work if this is the first time the metadata has been seen.
        /// </summary>
        /// <param name="method">The method metadata.</param>
        private void CreateMethodTags(ITestMethod method)
        {
            MethodInfo m = method.Method;

            // 1. All the tags from the class
            Tags tags = new Tags(_classTags);

            // 2. Method.Name
            tags.Add(m.Name);

            // 3. Type.FullName + Method.Name
            tags.Add(m.ReflectedType.FullName + "." + m.Name);

            // 4. Type.Name + Method.Name
            tags.Add(m.ReflectedType.Name + "." + m.Name);

            // 5. Implicit Inherited tag
            if (m.ReflectedType != m.DeclaringType)
            {
                tags.Add("Inherited");
            }

            // 6. All [Tag] attributes on the method
            foreach (Attribute attribute in ReflectionUtility.GetAttributes(method, TagType, false))
            {
                tags.Add(attribute);
            }

            // 7. Add priority as a tag
            if (method.Priority != null)
            {
                tags.Add(PriorityTagPrefix + method.Priority.ToString());
            }

            _methodTags.Add(method, tags);

            foreach (string tag in tags)
            {
                List <ITestMethod> methods;
                if (!_tagsToMethods.TryGetValue(tag, out methods))
                {
                    methods             = new List <ITestMethod>();
                    _tagsToMethods[tag] = methods;
                }
                methods.Add(method);
            }
        }