Пример #1
0
        public void GetProperty_DecoratedWithMatchedPropertyInterceptionAspectThatHasNoAdvices_ThrowsAdviceNotFoundException()
        {
            var contractProperty = GetProperty("GetAccessorProperty");
            var implProperty     = GetProperty("GetAccessorProperty", typeof(Subject));
            var aspect           = new PropertyInterceptionAspectAttribute(typeof(NoAdviceAspect));

            AspectTypeValidator.ValidatePropertyAspect(aspect, contractProperty, implProperty);
        }
Пример #2
0
        public void GetProperty_DecoratedWithMatchedPropertyInterceptionAspectWithNewMethodOfOnSetValueThatHasMoreThenOneArgument_ThrowsAspectTypeMismatchException()
        {
            var contractProperty = GetProperty("GetAccessorProperty");
            var implProperty     = GetProperty("GetAccessorProperty", typeof(Subject));
            var aspect           = new PropertyInterceptionAspectAttribute(typeof(PropertyInterceptionAspectWithNewMethodOfOnSetValueThatHasMoreThenOneArgument));

            AspectTypeValidator.ValidatePropertyAspect(aspect, contractProperty, implProperty);
        }
Пример #3
0
        public void SetPropertyOfContractType_DerivedByAnInterfaceTypeThatExposesBothPropertiesAndDecoratedWithMatchedPropertyInterceptionAspect_ThrowsPropertyAccessorsMismatchException()
        {
            var contractProperty = GetProperty("SetAccessorProperty");
            var implProperty     = GetProperty("SetAccessorProperty", typeof(ISubjectExtended));
            var aspect           = new PropertyInterceptionAspectAttribute(typeof(PropertyInterceptionAspect));

            AspectTypeValidator.ValidatePropertyAspect(aspect, contractProperty, implProperty);
        }
Пример #4
0
        public void SetPropertyOfContractType_ImplementedByATypeThatExposesBothPropertiesAndDecoratedWithMatchedPropertyInterceptionAspect_ReturnsNoErrorFromValidation()
        {
            var contractProperty = GetProperty("SetAccessorProperty");
            var implProperty     = GetProperty("SetAccessorProperty", typeof(Subject));
            var aspect           = new PropertyInterceptionAspectAttribute(typeof(PropertyInterceptionAspect));

            AspectTypeValidator.ValidatePropertyAspect(aspect, contractProperty, implProperty);
        }
Пример #5
0
        public void GetProperty_DecoratedWithAspectThatIsNotCompatibleWithPropertyInterceptionAspect_ThrowsAspectAnnotationException()
        {
            var contractProperty = GetProperty("StringProperty");
            var implProperty     = GetProperty("StringProperty", typeof(Subject));
            var aspect           = new PropertyInterceptionAspectAttribute(typeof(FunctionInterceptionAspect));

            AspectTypeValidator.ValidatePropertyAspect(aspect, contractProperty, implProperty);
        }
Пример #6
0
        public void GetProperty_DecoratedWithPropertyInterceptionAspectThatHasDifferentPropertyType_ThrowsAspectTypeMismatchException()
        {
            var contractProperty = GetProperty("StringProperty");
            var implProperty     = GetProperty("StringProperty", typeof(Subject));
            var aspect           = new PropertyInterceptionAspectAttribute(typeof(PropertyInterceptionAspectWithInt32PropertyType));

            AspectTypeValidator.ValidatePropertyAspect(aspect, contractProperty, implProperty);
        }
Пример #7
0
        public void PropertyWithBothAccessors_DecoratedWithMatchedPropertyInterceptionAspect_ReturnsNoErrorFromValidation()
        {
            var contractProperty = GetProperty("BothAccessorsProperty");
            var implProperty     = GetProperty("BothAccessorsProperty", typeof(Subject));
            var aspect           = new PropertyInterceptionAspectAttribute(typeof(PropertyInterceptionAspect));

            AspectTypeValidator.ValidatePropertyAspect(aspect, contractProperty, implProperty);
        }
        private void CollectPropertyInterceptionAspectDefinition(IAspectPropertyMap propertyMap, PropertyInfo target, Type aspectDeclaringType, PropertyInterceptionAspectAttribute aspectAttribute)
        {
            var contract                    = propertyMap.ContractMember;
            var propertyGetMethod           = target.GetGetMethod();
            var propertySetMethod           = target.GetSetMethod();
            var contractGetMethodHasCode    = contract.GetGetMethod().GetHashCode();
            var contractSetMethodHasCode    = contract.GetSetMethod().GetHashCode();
            var aspectDefinition            = new PropertyInterceptionAspectsDefinition(aspectAttribute, aspectAttribute.AspectType, contract, target);
            var bindingTypeReflectorBuilder = new FullPropertyBindingTypeReflectorBuilder(aspectDefinition);

            var getPropertyAspect = new GetPropertyFragmentInterceptionAspect {
                AspectType       = aspectAttribute.AspectType,
                AspectPriority   = aspectAttribute.AspectPriority,
                LifetimeStrategy = aspectAttribute.LifetimeStrategy
            };

            var setPropertyAspect = new SetPropertyFragmentInterceptionAspect {
                AspectType       = aspectAttribute.AspectType,
                AspectPriority   = aspectAttribute.AspectPriority,
                LifetimeStrategy = aspectAttribute.LifetimeStrategy
            };

            AddOrUpdate(contractGetMethodHasCode, propertyMap.Target, contract, propertyGetMethod, new[] { new GetPropertyFragmentInterceptionAspectDefinition(bindingTypeReflectorBuilder, getPropertyAspect, aspectDeclaringType, contract, target) });
            AddOrUpdate(contractSetMethodHasCode, propertyMap.Target, contract, propertySetMethod, new[] { new SetPropertyFragmentInterceptionAspectDefinition(bindingTypeReflectorBuilder, setPropertyAspect, aspectDeclaringType, contract, target) });
        }