Inheritance: System.Attribute
Exemplo n.º 1
0
        public Test Decorate(Test test, MemberInfo member)
        {
            NUnitTestMethod testMethod = test as NUnitTestMethod;

            if (testMethod != null && testMethod.RunState == RunState.Runnable)
            {
                List <Attribute> ignoreAttributes = new List <Attribute>();
                Attribute[]      ignoreAttr       = Reflect.GetAttributes(member, IgnoreBrowserAttributeTypeFullName, true);
                if (ignoreAttr != null)
                {
                    ignoreAttributes.AddRange(ignoreAttr);
                }

                Attribute[] ignoreClassAttributes = Reflect.GetAttributes(member.DeclaringType, IgnoreBrowserAttributeTypeFullName, true);
                if (ignoreClassAttributes != null)
                {
                    ignoreAttributes.AddRange(ignoreClassAttributes);
                }

                foreach (Attribute attr in ignoreAttributes)
                {
                    IgnoreBrowserAttribute browserToIgnoreAttr = attr as IgnoreBrowserAttribute;
                    if (browserToIgnoreAttr != null && IgnoreTestForBrowser(browserToIgnoreAttr.Value))
                    {
                        string ignoreReason = "Ignoring browser " + EnvironmentManager.Instance.Browser.ToString() + ".";
                        if (!string.IsNullOrEmpty(browserToIgnoreAttr.Reason))
                        {
                            ignoreReason = ignoreReason + " " + browserToIgnoreAttr.Reason;
                        }

                        test.RunState     = RunState.Ignored;
                        test.IgnoreReason = ignoreReason;
                    }
                }


                if (test.RunState == RunState.Runnable)
                {
                    NeedsFreshDriverAttribute needsDriverAttr = Reflect.GetAttribute(member, NeedsFreshDriverAttributeTypeFullName, false) as NeedsFreshDriverAttribute;
                    if (needsDriverAttr != null)
                    {
                        test = new WebDriverTestMethod(testMethod, needsDriverAttr.BeforeTest, needsDriverAttr.AfterTest);
                    }
                }
            }

            return(test);
        }
        public void ApplyToTest(Test test)
        {
            if (test.RunState != RunState.NotRunnable)
            {
                List <Attribute> ignoreAttributes = new List <Attribute>();
                if (test.IsSuite)
                {
                    Attribute[] ignoreClassAttributes = test.TypeInfo.GetCustomAttributes <IgnoreBrowserAttribute>(true);
                    if (ignoreClassAttributes.Length > 0)
                    {
                        ignoreAttributes.AddRange(ignoreClassAttributes);
                    }
                }
                else
                {
                    IgnoreBrowserAttribute[] ignoreMethodAttributes = test.Method.GetCustomAttributes <IgnoreBrowserAttribute>(true);
                    if (ignoreMethodAttributes.Length > 0)
                    {
                        ignoreAttributes.AddRange(ignoreMethodAttributes);
                    }
                }

                foreach (Attribute attr in ignoreAttributes)
                {
                    IgnoreBrowserAttribute browserToIgnoreAttr = attr as IgnoreBrowserAttribute;
                    if (browserToIgnoreAttr != null && IgnoreTestForBrowser(browserToIgnoreAttr.Value))
                    {
                        string ignoreReason = "Ignoring browser " + EnvironmentManager.Instance.Browser.ToString() + ".";
                        if (!string.IsNullOrEmpty(browserToIgnoreAttr.Reason))
                        {
                            ignoreReason = ignoreReason + " " + browserToIgnoreAttr.Reason;
                        }

                        test.RunState = RunState.Ignored;
                        test.Properties.Set(PropertyNames.SkipReason, browserToIgnoreAttr.Reason);
                    }
                }
            }
        }