Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DisableEnumValuesAttribute"/> class with a number of enum values to disable.
        /// </summary>
        /// <param name="disabledEnumValues">The disabled enum values.</param>
        public DisableEnumValuesAttribute(params object[] disabledEnumValues)
        {
            ArgumentUtility.CheckNotNull("disabledEnumValues", disabledEnumValues);
            ArgumentUtility.CheckItemsType("disabledEnumValues", disabledEnumValues, typeof(Enum));

            _filter = new ConstantEnumerationValueFilter(disabledEnumValues.Cast <Enum>().ToArray());
        }
Ejemplo n.º 2
0
        public override void SetUp()
        {
            base.SetUp();

            ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope();

            _filter = new AccessControlEntryPropertiesEnumerationValueFilter();
        }
        public ExtensibleEnumerationProperty(Parameters parameters)
            : base(parameters)
        {
            _definition = ExtensibleEnumUtility.GetDefinition(PropertyType);

            var filterProvider = new EnumValueFilterProvider <DisableExtensibleEnumValuesAttribute> (
                PropertyInfo,
                t => _definition.GetCustomAttributes <DisableExtensibleEnumValuesAttribute> ());

            _enumerationValueFilter = filterProvider.GetEnumerationValueFilter();
        }
        public void SetUp()
        {
            _businessObjectStub = MockRepository.GenerateStub <IBusinessObject>();
            _propertyStub       = MockRepository.GenerateStub <IBusinessObjectEnumerationProperty>();

            _value1 = new EnumerationValueInfo("Value1", "ID1", "Value 1", true);

            _trueFilterStub = MockRepository.GenerateStub <IEnumerationValueFilter>();
            _trueFilterStub.Stub(stub => stub.IsEnabled(_value1, _businessObjectStub, _propertyStub)).Return(true);

            _falseFilterStub = MockRepository.GenerateStub <IEnumerationValueFilter>();
            _falseFilterStub.Stub(stub => stub.IsEnabled(_value1, _businessObjectStub, _propertyStub)).Return(false);
        }
        private ExtensibleEnumerationProperty CreatePropertyWithSpecificFilter(IEnumerationValueFilter filterMock)
        {
            var attribute = new DisableExtensibleEnumValuesAttribute("x");

            PrivateInvoke.SetNonPublicField(attribute, "_filter", filterMock);

            var propertyInfoStub = MockRepository.GenerateStub <IPropertyInformation> ();

            propertyInfoStub.Stub(stub => stub.PropertyType).Return(typeof(ExtensibleEnumWithResources));
            propertyInfoStub.Stub(stub => stub.GetIndexParameters()).Return(new ParameterInfo[0]);
            propertyInfoStub
            .Stub(stub => stub.GetCustomAttribute <DisableExtensibleEnumValuesAttribute> (true))
            .Return(attribute);

            return(new ExtensibleEnumerationProperty(GetPropertyParameters(propertyInfoStub, _businessObjectProvider)));
        }
Ejemplo n.º 6
0
        /// <exception cref="InvalidOperationException">
        /// The enum type has an UndefinedEnumValueAttribute with a value that does not match the enum's type.
        /// <para>- or -</para>
        /// <para>The property is nullable and the property's type defines an UndefinedEnumValueAttribute</para>
        /// </exception>
        public EnumerationProperty(Parameters parameters)
            : base(parameters)
        {
            if (AttributeUtility.IsDefined <FlagsAttribute> (parameters.UnderlyingType, false))
            {
                throw new InvalidOperationException(
                          string.Format(
                              "The property '{0}' defined on type '{1}' is a flags-enum, which is not supported.",
                              Identifier,
                              PropertyInfo.DeclaringType));
            }
            _undefinedValue = GetUndefinedValue();

            var filterProvider = new EnumValueFilterProvider <DisableEnumValuesAttribute> (
                PropertyInfo,
                t => AttributeUtility.GetCustomAttributes <DisableEnumValuesAttribute> (t, true));

            _enumerationValueFilter = filterProvider.GetEnumerationValueFilter();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DisableExtensibleEnumValuesAttribute"/> class with a number of enum ids to disable.
        /// </summary>
        /// <param name="ids">The ids to disable.</param>
        public DisableExtensibleEnumValuesAttribute(params string[] ids)
        {
            ArgumentUtility.CheckNotNullOrEmpty("ids", ids);

            _filter = new DisabledIdentifiersEnumerationFilter(ids);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DisableExtensibleEnumValuesAttribute"/> class with a custom filter type.
 /// </summary>
 /// <param name="filterType">The type of the filter to use, must implement <see cref="IEnumerationValueFilter"/>.</param>
 public DisableExtensibleEnumValuesAttribute(Type filterType)
 {
     ArgumentUtility.CheckNotNullAndTypeIsAssignableFrom("filterType", filterType, typeof(IEnumerationValueFilter));
     _filter = (IEnumerationValueFilter)Activator.CreateInstance(filterType);
 }
 private void CheckConstantEnumerationValueFilter(IEnumerationValueFilter filter, params Enum[] expectedDisabledEnumValues)
 {
     Assert.That(filter, Is.TypeOf(typeof(ConstantEnumerationValueFilter)));
     Assert.That(((ConstantEnumerationValueFilter)filter).DisabledEnumValues, Is.EqualTo(expectedDisabledEnumValues));
 }