Esempio n. 1
0
        /// <summary>
        /// Modify a newly constructed test by applying any of NUnit's common
        /// attributes, based on an input array of attributes. This method checks
        /// for all attributes, relying on the fact that specific attributes can only
        /// occur on those constructs on which they are allowed.
        /// </summary>
        /// <param name="attributes">An array of attributes possibly including NUnit attributes
        /// <param name="test">The test to which the attributes apply</param>
        public static void ApplyCommonAttributes(Attribute[] attributes, Test test)
        {
            foreach (Attribute attribute in attributes)
            {
                Type attributeType = attribute.GetType();
                string attributeName = attributeType.FullName;
                bool isValid = test.RunState != RunState.NotRunnable;

                switch (attributeName)
                {
                    case TestFixtureAttribute:
                    case TestAttribute:
                        if ( test.Description == null )
                            test.Description = GetDescription( attribute );
                        break;
                    case DescriptionAttribute:
                        test.Description = GetDescription( attribute );
                        break;
                    case PlatformAttribute:
                        PlatformHelper pHelper = new PlatformHelper();
                        if (isValid && !pHelper.IsPlatformSupported(attribute))
                        {
                            test.RunState = RunState.Skipped;
                            test.IgnoreReason = GetIgnoreReason(attribute);
                            if ( test.IgnoreReason == null )
                                test.IgnoreReason = pHelper.Reason;
                        }
                        break;
                    case CultureAttribute:
                        CultureDetector cultureDetector = new CultureDetector();
                        if (isValid && !cultureDetector.IsCultureSupported(attribute))
                        {
                            test.RunState = RunState.Skipped;
                            test.IgnoreReason = cultureDetector.Reason;
                        }
                        break;
                    case RequiredAddinAttribute:
                        string required = (string)Reflect.GetPropertyValue(attribute, PropertyNames.RequiredAddin);
                        if (!IsAddinAvailable(required))
                        {
                            test.RunState = RunState.NotRunnable;
                            test.IgnoreReason = string.Format("Required addin {0} not available", required);
                        }
                        break;
                    case "System.STAThreadAttribute":
                        test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.STA);
                        break;
                    case "System.MTAThreadAttribute":
                        test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.MTA);
                        break;
                    default:
                        if ( Reflect.InheritsFrom( attributeType, CategoryAttribute ) )
                        {
                            string categoryName = (string)Reflect.GetPropertyValue(attribute, PropertyNames.CategoryName);
                            test.Categories.Add(categoryName);

                            if (categoryName.IndexOfAny(new char[] { ',', '!', '+', '-' }) >= 0)
                            {
                                test.RunState = RunState.NotRunnable;
                                test.IgnoreReason = "Category name must not contain ',', '!', '+' or '-'";
                            }
                        }
                        else if ( Reflect.InheritsFrom( attributeType, PropertyAttribute ) )
                        {
                            IDictionary props = (IDictionary)Reflect.GetPropertyValue( attribute, PropertyNames.Properties );
                            if ( props != null )
                                foreach( DictionaryEntry entry in props )
                                    test.Properties.Add(entry.Key, entry.Value);
                        }
                        else if ( Reflect.InheritsFrom( attributeType, ExplicitAttribute ) )
                         {
                             if (isValid)
                             {
                                 test.RunState = RunState.Explicit;
                                 test.IgnoreReason = GetIgnoreReason(attribute);
                             }
                         }
                         else if ( Reflect.InheritsFrom( attributeType, IgnoreAttribute ) )
                         {
                             if (isValid)
                             {
                                 test.RunState = RunState.Ignored;
                                 test.IgnoreReason = GetIgnoreReason(attribute);
                             }
                         }
                        break;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Modify a newly constructed test by applying any of NUnit's common
        /// attributes, based on an input array of attributes. This method checks
        /// for all attributes, relying on the fact that specific attributes can only
        /// occur on those constructs on which they are allowed.
        /// </summary>
        /// <param name="attributes">An array of attributes possibly including NUnit attributes
        /// <param name="test">The test to which the attributes apply</param>
        public static void ApplyCommonAttributes(Attribute[] attributes, Test test)
        {
            foreach (Attribute attribute in attributes)
            {
                Type   attributeType = attribute.GetType();
                string attributeName = attributeType.FullName;
                bool   isValid       = test.RunState != RunState.NotRunnable;

                switch (attributeName)
                {
                case TestFixtureAttribute:
                case TestAttribute:
                    if (test.Description == null)
                    {
                        test.Description = GetDescription(attribute);
                    }
                    break;

                case DescriptionAttribute:
                    test.Description = GetDescription(attribute);
                    break;

                case PlatformAttribute:
                    PlatformHelper pHelper = new PlatformHelper();
                    if (isValid && !pHelper.IsPlatformSupported(attribute))
                    {
                        test.RunState     = RunState.Skipped;
                        test.IgnoreReason = GetIgnoreReason(attribute);
                        if (test.IgnoreReason == null)
                        {
                            test.IgnoreReason = pHelper.Reason;
                        }
                    }
                    break;

                case CultureAttribute:
                    CultureDetector cultureDetector = new CultureDetector();
                    if (isValid && !cultureDetector.IsCultureSupported(attribute))
                    {
                        test.RunState     = RunState.Skipped;
                        test.IgnoreReason = cultureDetector.Reason;
                    }
                    break;

                case RequiredAddinAttribute:
                    string required = (string)Reflect.GetPropertyValue(attribute, PropertyNames.RequiredAddin);
                    if (!IsAddinAvailable(required))
                    {
                        test.RunState     = RunState.NotRunnable;
                        test.IgnoreReason = string.Format("Required addin {0} not available", required);
                    }
                    break;

                case STAThreadAttribute:
                    test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.STA);
                    break;

                case MTAThreadAttribute:
                    test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.MTA);
                    break;

                default:
                    if (Reflect.InheritsFrom(attributeType, CategoryAttribute))
                    {
                        string categoryName = (string)Reflect.GetPropertyValue(attribute, PropertyNames.CategoryName);
                        test.Categories.Add(categoryName);

                        if (!IsValidCategoryName(categoryName))
                        {
                            test.RunState     = RunState.NotRunnable;
                            test.IgnoreReason = "Category name must not contain ',', '!', '+' or '-'";
                        }
                    }
                    else if (Reflect.InheritsFrom(attributeType, PropertyAttribute))
                    {
                        object      propObject = Reflect.GetPropertyValue(attribute, PropertyNames.Properties);
                        IDictionary props      = propObject as IDictionary;
                        if (props != null)
                        {
                            foreach (DictionaryEntry entry in props)
                            {
                                test.Properties.Add(entry.Key, entry.Value);
                            }
                        }
                        else
                        {
                            // In case we are running NUnitLite tests
                            IEnumerable entries = propObject as IEnumerable;
                            if (entries != null)
                            {
                                foreach (object entry in entries)
                                {
                                    object key   = Reflect.GetPropertyValue(entry, "Name");
                                    object value = Reflect.GetPropertyValue(entry, "Value");
                                    test.Properties.Add(key, value);
                                }
                            }
                        }
                    }
                    else if (Reflect.InheritsFrom(attributeType, ExplicitAttribute))
                    {
                        if (isValid)
                        {
                            test.RunState     = RunState.Explicit;
                            test.IgnoreReason = GetIgnoreReason(attribute);
                        }
                    }
                    else if (Reflect.InheritsFrom(attributeType, IgnoreAttribute))
                    {
                        if (isValid)
                        {
                            test.RunState     = RunState.Ignored;
                            test.IgnoreReason = GetIgnoreReason(attribute);
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Modify a newly constructed test by applying any of NUnit's common
        /// attributes, based on an input array of attributes. This method checks
        /// for all attributes, relying on the fact that specific attributes can only
        /// occur on those constructs on which they are allowed.
        /// </summary>
        /// <param name="attributes">An array of attributes possibly including NUnit attributes
        /// <param name="test">The test to which the attributes apply</param>
        public static void ApplyCommonAttributes(Attribute[] attributes, Test test)
        {
            foreach (Attribute attribute in attributes)
            {
                Type   attributeType = attribute.GetType();
                string attributeName = attributeType.FullName;
                bool   isValid       = test.RunState != RunState.NotRunnable;

                switch (attributeName)
                {
                case TestFixtureAttribute:
                case TestAttribute:
                    if (test.Description == null)
                    {
                        test.Description = GetDescription(attribute);
                    }
                    break;

                case DescriptionAttribute:
                    test.Description = GetDescription(attribute);
                    break;

                case ExplicitAttribute:
                    if (isValid)
                    {
                        test.RunState     = RunState.Explicit;
                        test.IgnoreReason = GetIgnoreReason(attribute);
                    }
                    break;

                case IgnoreAttribute:
                    if (isValid)
                    {
                        test.RunState     = RunState.Ignored;
                        test.IgnoreReason = GetIgnoreReason(attribute);
                    }
                    break;

                case PlatformAttribute:
                    PlatformHelper pHelper = new PlatformHelper();
                    if (isValid && !pHelper.IsPlatformSupported(attribute))
                    {
                        test.RunState     = RunState.Skipped;
                        test.IgnoreReason = GetIgnoreReason(attribute);
                        if (test.IgnoreReason == null)
                        {
                            test.IgnoreReason = pHelper.Reason;
                        }
                    }
                    break;

                case CultureAttribute:
                    CultureDetector cultureDetector = new CultureDetector();
                    if (isValid && !cultureDetector.IsCultureSupported(attribute))
                    {
                        test.RunState     = RunState.Skipped;
                        test.IgnoreReason = cultureDetector.Reason;
                    }
                    break;

                case RequiredAddinAttribute:
                    string required = (string)Reflect.GetPropertyValue(attribute, PropertyNames.RequiredAddin);
                    if (!IsAddinAvailable(required))
                    {
                        test.RunState     = RunState.NotRunnable;
                        test.IgnoreReason = string.Format("Required addin {0} not available", required);
                    }
                    break;

                case "System.STAThreadAttribute":
                    test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.STA);
                    break;

                case "System.MTAThreadAttribute":
                    test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.MTA);
                    break;

                default:
                    if (Reflect.InheritsFrom(attributeType, CategoryAttribute))
                    {
                        string categoryName = (string)Reflect.GetPropertyValue(attribute, PropertyNames.CategoryName);
                        test.Categories.Add(categoryName);

                        if (categoryName.IndexOfAny(new char[] { ',', '!', '+', '-' }) >= 0)
                        {
                            test.RunState     = RunState.NotRunnable;
                            test.IgnoreReason = "Category name must not contain ',', '!', '+' or '-'";
                        }
                    }
                    else if (Reflect.InheritsFrom(attributeType, PropertyAttribute))
                    {
                        IDictionary props = (IDictionary)Reflect.GetPropertyValue(attribute, PropertyNames.Properties);
                        if (props != null)
                        {
                            foreach (DictionaryEntry entry in props)
                            {
                                test.Properties.Add(entry.Key, entry.Value);
                            }
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Modify a newly constructed test by applying any of NUnit's common
        /// attributes, based on an input array of attributes. This method checks
        /// for all attributes, relying on the fact that specific attributes can only
        /// occur on those constructs on which they are allowed.
        /// </summary>
        /// <param name="attributes">An array of attributes possibly including NUnit attributes
        /// <param name="test">The test to which the attributes apply</param>
        public static void ApplyCommonAttributes(Attribute[] attributes, Test test)
        {
            IList          categories = new ArrayList();
            ListDictionary properties = new ListDictionary();

            foreach (Attribute attribute in attributes)
            {
                Type   attributeType = attribute.GetType();
                string attributeName = attributeType.FullName;
                bool   isValid       = test.RunState != RunState.NotRunnable;

                switch (attributeName)
                {
                case TestFixtureAttribute:
                case TestAttribute:
                    if (test.Description == null)
                    {
                        test.Description = GetDescription(attribute);
                    }
                    break;

                case DescriptionAttribute:
                    test.Description = GetDescription(attribute);
                    break;

                case ExplicitAttribute:
                    if (isValid)
                    {
                        test.RunState     = RunState.Explicit;
                        test.IgnoreReason = GetIgnoreReason(attribute);
                    }
                    break;

                case IgnoreAttribute:
                    if (isValid)
                    {
                        test.RunState     = RunState.Ignored;
                        test.IgnoreReason = GetIgnoreReason(attribute);
                    }
                    break;

                case PlatformAttribute:
                    PlatformHelper pHelper = new PlatformHelper();
                    if (isValid && !pHelper.IsPlatformSupported(attribute))
                    {
                        test.RunState     = RunState.Skipped;
                        test.IgnoreReason = GetIgnoreReason(attribute);
                        if (test.IgnoreReason == null)
                        {
                            test.IgnoreReason = pHelper.Reason;
                        }
                    }
                    break;

                case CultureAttribute:
                    CultureDetector cultureDetector = new CultureDetector();
                    if (isValid && !cultureDetector.IsCultureSupported(attribute))
                    {
                        test.RunState     = RunState.Skipped;
                        test.IgnoreReason = cultureDetector.Reason;
                    }
                    break;

                default:
                    if (Reflect.InheritsFrom(attributeType, CategoryAttribute))
                    {
                        categories.Add(Reflect.GetPropertyValue(attribute, "Name"));
                    }
                    else if (Reflect.InheritsFrom(attributeType, PropertyAttribute))
                    {
                        string name = (string)Reflect.GetPropertyValue(attribute, "Name");
                        if (name != null && name != string.Empty)
                        {
                            object val = Reflect.GetPropertyValue(attribute, "Value");
                            properties[name] = val;
                        }
                    }
                    break;
                }
            }

            test.Categories = categories;
            test.Properties = properties;
        }
Esempio n. 5
0
        /// <summary>
        /// Modify a newly constructed test by applying any of NUnit's common
        /// attributes, based on an input array of attributes. This method checks
        /// for all attributes, relying on the fact that specific attributes can only
        /// occur on those constructs on which they are allowed.
        /// </summary>
        /// <param name="attributes">An array of attributes possibly including NUnit attributes
        /// <param name="test">The test to which the attributes apply</param>
        public static void ApplyCommonAttributes(Attribute[] attributes, Test test)
        {
			IList categories = new ArrayList();
			ListDictionary properties = new ListDictionary();

            foreach (Attribute attribute in attributes)
            {
				Type attributeType = attribute.GetType();
				string attributeName = attributeType.FullName;
                bool isValid = test.RunState != RunState.NotRunnable;

                switch (attributeName)
                {
					case TestFixtureAttribute:
					case TestAttribute:
						if ( test.Description == null )
							test.Description = GetDescription( attribute );
						break;
					case DescriptionAttribute:
						test.Description = GetDescription( attribute );
						break;
					case ExplicitAttribute:
                        if (isValid)
                        {
                            test.RunState = RunState.Explicit;
                            test.IgnoreReason = GetIgnoreReason(attribute);
                        }
                        break;
                    case IgnoreAttribute:
                        if (isValid)
                        {
                            test.RunState = RunState.Ignored;
                            test.IgnoreReason = GetIgnoreReason(attribute);
                        }
                        break;
                    case PlatformAttribute:
                        PlatformHelper pHelper = new PlatformHelper();
                        if (isValid && !pHelper.IsPlatformSupported(attribute))
                        {
                            test.RunState = RunState.Skipped;
                            test.IgnoreReason = GetIgnoreReason(attribute);
							if ( test.IgnoreReason == null )
								test.IgnoreReason = pHelper.Reason;
                        }
                        break;
					case CultureAttribute:
						CultureDetector cultureDetector = new CultureDetector();
						if (isValid && !cultureDetector.IsCultureSupported(attribute))
						{
							test.RunState = RunState.Skipped;
							test.IgnoreReason = cultureDetector.Reason;
						}
						break;
					default:
						if ( Reflect.InheritsFrom( attributeType, CategoryAttribute ) )
						{	
							categories.Add( Reflect.GetPropertyValue( attribute, "Name" ) );
						}
						else if ( Reflect.InheritsFrom( attributeType, PropertyAttribute ) )
						{
							string name = (string)Reflect.GetPropertyValue( attribute, "Name" );
							if ( name != null && name != string.Empty )
							{
								object val = Reflect.GetPropertyValue( attribute, "Value" );
								properties[name] = val;
							}
						}
						break;
                }
            }

			test.Categories = categories;
			test.Properties = properties;
        }