Ejemplo n.º 1
0
		private static PropertyFilterAttribute [] CreateAllAttributeOptions()
		{
			// This iterates over all possible combinations 
			PropertyFilterAttribute [] opts = new PropertyFilterAttribute [16];
			for (int i = 0; i < 16; i++) {
				// Note: This is certainly not an ideal technique for this, but it saves space
				opts [i] = new PropertyFilterAttribute ((PropertyFilterOptions)i);
			}
			return opts;
		}
Ejemplo n.º 2
0
        /// <summary>
        ///     Match determines if one attribute "matches" another.  For
        ///     attributes that store flags, a match may be different from
        ///     an equals.  For example, a filter of SetValid matches a
        ///     filter of All, because All is a merge of all filter values.
        /// </summary>
        public override bool Match(object value)
        {
            PropertyFilterAttribute a = value as PropertyFilterAttribute;

            if (a == null)
            {
                return(false);
            }
            return((_filter & a._filter) == _filter);
        }
Ejemplo n.º 3
0
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        ///     Override of Object.Equals that returns true if the filters
        ///     contained in both attributes match.
        /// </summary>
        public override bool Equals(object value)
        {
            PropertyFilterAttribute a = value as PropertyFilterAttribute;

            if (a != null && a._filter.Equals(_filter))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
		public void PropertyFilterAttributeOptionsNoneTest()
		{
			PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.None);

			bool [] matches = new bool [] {
				true, true, true, true, true, true, true, true,
				true, true, true, true, true, true, true, true,
			};

			ValidateFilterValues (all, matches, (int)PropertyFilterOptions.None, "None");
		}
Ejemplo n.º 5
0
		private static void ValidateFilterValues(PropertyFilterAttribute test, bool[] matchResults, int equalsResult, string message)
		{
			for (int i = 0; i < 16; i++) {
				Assert.AreEqual(matchResults[i], test.Match(AllAttributeOptions[i]),
						message + " - Match - Iteration " + i + ": " + 
						Enum.GetName(typeof(PropertyFilterOptions), (PropertyFilterOptions)i));
				Assert.AreEqual (equalsResult == i, test.Equals (AllAttributeOptions [i]),
						message + " - Equals - Iteration " + i + ": " +
						Enum.GetName (typeof (PropertyFilterOptions), (PropertyFilterOptions)i));
			}
		}
Ejemplo n.º 6
0
		public void PropertyFilterAttributeOptionsInvalidTest()
		{
			PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid);

			bool [] matches = new bool [] {
				false, true, false, true, false, true, false, true,
				false, true, false, true, false, true, false, true,
			};

			ValidateFilterValues (all, matches, (int)PropertyFilterOptions.Invalid, "Invalid");
		}
Ejemplo n.º 7
0
		public void PropertyFilterAttributeOptionsSetValuesUnsetValuesValidTest()
		{
			PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid);

			bool [] matches = new bool [] {
				false, false, false, false, false, false, false, false,
				false, false, false, false, false, false, true, true,
			};

			ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid), "SetValues|UnsetValues|Valid");
		}
Ejemplo n.º 8
0
		public void PropertyFilterAttributeOptionsInvalidSetValuesUnsetValuesTest()
		{
			PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues);

			bool [] matches = new bool [] {
				false, false, false, false, false, false, false, true,
				false, false, false, false, false, false, false, true,
			};

			ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues), "Invalid|SetValues|UnsetValues");
		}
Ejemplo n.º 9
0
		public void PropertyFilterAttributeOptionsSetValuesTest()
		{
			PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues);

			bool [] matches = new bool [] {
				false, false, true, true, false, false, true, true,
				false, false, true, true, false, false, true, true,
			};

			ValidateFilterValues (all, matches, (int)PropertyFilterOptions.SetValues, "SetValues");
		}