/// <summary>
        /// Checks if the given <see cref="PropertyInfo"/> on the given <see cref="ClassDefinition"/> is a mixed property.
        /// </summary>
        /// <param name="propertyInfo">The <see cref="IPropertyInformation"/> to analyze.</param>
        /// <param name="classDefinition">The <see cref="ClassDefinition"/> of the given <see cref="IPropertyInformation"/></param>
        /// <returns><see langword="true" /> if the given <see cref="PropertyInfo"/> is a mixed property.</returns>
        public static bool IsMixedProperty(IPropertyInformation propertyInfo, ClassDefinition classDefinition)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);
            ArgumentUtility.CheckNotNull("classDefinition", classDefinition);

            return(classDefinition.GetPersistentMixin(propertyInfo.DeclaringType.ConvertToRuntimeType()) != null);
        }
        public void SetValue_WithExceptionHandledByPropertyAccessStrategy_ThrowsBusinessObjectPropertyAccessException()
        {
            var bindablePropertyWriteAccessStrategyStub = MockRepository.GenerateStub <IBindablePropertyWriteAccessStrategy>();

            IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SimpleReferenceType>), "ThrowingProperty");
            PropertyBase         propertyBase = new StubPropertyBase(
                CreateParameters(
                    propertyInfo: propertyInfo,
                    underlyingType: propertyInfo.PropertyType,
                    concreteType: propertyInfo.PropertyType,
                    listInfo: null,
                    bindablePropertyWriteAccessStrategy: bindablePropertyWriteAccessStrategyStub));

            var instance = ObjectFactory.Create <ClassWithReferenceType <SimpleReferenceType> > (ParamList.Empty);

            var originalException = new Exception("The Exception");
            var expectedException = new BusinessObjectPropertyAccessException("The Message", null);

            bindablePropertyWriteAccessStrategyStub
            .Stub(
                mock => mock.IsPropertyAccessException(
                    Arg.Is((IBusinessObject)instance),
                    Arg.Is(propertyBase),
                    Arg.Is(originalException),
                    out Arg <BusinessObjectPropertyAccessException> .Out(expectedException).Dummy))
            .Return(true);

            instance.PrepareException(originalException);

            var actualException =
                Assert.Throws <BusinessObjectPropertyAccessException> (() => propertyBase.SetValue((IBusinessObject)instance, new SimpleReferenceType()));

            Assert.That(actualException, Is.SameAs(expectedException));
        }
Ejemplo n.º 3
0
 public void SetUp()
 {
     _domainModelConstraintProvider         = new DomainModelConstraintProvider();
     _propertyInformationStub               = MockRepository.GenerateStub <IPropertyInformation>();
     _nullablePropertyAttributeStub         = MockRepository.GenerateStub <INullablePropertyAttribute>();
     _lengthConstraintPropertyAttributeStub = MockRepository.GenerateStub <ILengthConstrainedPropertyAttribute>();
 }
        public void GetPropertyDisplayName_WithTwoMixins_WithDependency_IntegrationTest()
        {
            using (MixinConfiguration.BuildFromActive()
                   .ForClass <SimpleBusinessObjectClass>()
                   .AddMixin <MixinAddingResources>()
                   .AddMixin <MixinAddingResources2>().WithDependency <MixinAddingResources>()
                   .EnterScope())
            {
                IPropertyInformation propertyInformation = GetPropertyInfo(typeof(SimpleBusinessObjectClass), "String");
                Assert.That(
                    _globalizationService.GetPropertyDisplayName(propertyInformation, TypeAdapter.Create(typeof(MixinAddingResources2))),
                    Is.EqualTo("Resource from mixin2"));
            }

            using (MixinConfiguration.BuildFromActive()
                   .ForClass <SimpleBusinessObjectClass>()
                   .AddMixin <MixinAddingResources>().WithDependency <MixinAddingResources2>()
                   .AddMixin <MixinAddingResources2>()
                   .EnterScope())
            {
                IPropertyInformation propertyInformation = GetPropertyInfo(typeof(SimpleBusinessObjectClass), "String");
                Assert.That(
                    _globalizationService.GetPropertyDisplayName(propertyInformation, TypeAdapter.Create(typeof(MixinAddingResources))),
                    Is.EqualTo("Resource from mixin"));
            }
        }
Ejemplo n.º 5
0
        private static List <Tuple <IPropertyInformation, T> > GetMatchingDefinitions <T> (
            IPropertyInformation propertyInformation,
            ClassDefinition classDefinition,
            Func <string, T> definitionGetter) where T : class
        {
            IEnumerable <IPropertyInformation> propertyImplementationCandidates;

            if (propertyInformation.DeclaringType.IsInterface)
            {
                var implementingTypes = GetImplementingTypes(classDefinition, propertyInformation);
                propertyImplementationCandidates = implementingTypes
                                                   .Select(propertyInformation.FindInterfaceImplementation)
                                                   .Where(pi => pi != null);
            }
            else
            {
                propertyImplementationCandidates = new[] { propertyInformation };
            }

            return((from pi in propertyImplementationCandidates
                    let propertyIdentifier = MappingConfiguration.Current.NameResolver.GetPropertyName(pi)
                                             let definition = definitionGetter(propertyIdentifier)
                                                              where definition != null
                                                              select Tuple.Create(pi, definition))
                   .Distinct(new DelegateBasedEqualityComparer <Tuple <IPropertyInformation, T> > (
                                 (x, y) => object.Equals(x.Item1, y.Item1),
                                 x => x.Item1.GetHashCode()))
                   .ToList());
        }
        public void GetDisplayName_WithGlobalizationSerivce()
        {
            var mockMemberInformationGlobalizationService = _mockRepository.StrictMock <IMemberInformationGlobalizationService>();
            IPropertyInformation propertyInfo             = GetPropertyInfo(typeof(SimpleBusinessObjectClass), "String");
            PropertyBase         property = new StubPropertyBase(
                CreateParameters(
                    propertyInfo: propertyInfo,
                    underlyingType: typeof(string),
                    concreteType: typeof(string),
                    listInfo: null,
                    isRequired: false,
                    isReadOnly: false,
                    bindableObjectGlobalizationService: new BindableObjectGlobalizationService(
                        MockRepository.GenerateStub <IGlobalizationService>(),
                        mockMemberInformationGlobalizationService,
                        MockRepository.GenerateStub <IEnumerationGlobalizationService>(),
                        MockRepository.GenerateStub <IExtensibleEnumGlobalizationService>())));

            property.SetReflectedClass(_bindableObjectClass);

            Expect.Call(
                mockMemberInformationGlobalizationService.TryGetPropertyDisplayName(
                    Arg.Is(propertyInfo),
                    Arg <ITypeInformation> .Matches(c => c.ConvertToRuntimeType() == _bindableObjectClass.TargetType),
                    out Arg <string> .Out("MockString").Dummy))
            .Return(true);
            _mockRepository.ReplayAll();

            string actual = property.DisplayName;

            _mockRepository.VerifyAll();
            Assert.That(actual, Is.EqualTo("MockString"));
        }
Ejemplo n.º 7
0
 private void AppendPropertyName(IPropertyInformation actualProperty, StringBuilder sb)
 {
     sb.AppendLine().AppendLine();
     sb.Append(new string (' ', 4) + "-> ");
     sb.Append(actualProperty.DeclaringType != null ? GetDomainTypeName(actualProperty.DeclaringType.ConvertToRuntimeType()) + "#" : string.Empty);
     sb.Append(actualProperty.Name);
 }
Ejemplo n.º 8
0
        private void AppendPropertyCollectionOutput(
            IPropertyInformation[] allProperties,
            ValidationCollectorInfo validationCollectorInfo,
            StringBuilder sb)
        {
            var loggedProperties = new Dictionary <IPropertyInformation, bool> ();

            foreach (var property in allProperties)
            {
                if (!loggedProperties.ContainsKey(property))
                {
                    IPropertyInformation actualProperty = property;
                    var removedRegistrations            = validationCollectorInfo.Collector.RemovedPropertyRules
                                                          .Where(pr => pr.Property.Equals(actualProperty))
                                                          .SelectMany(pr => pr.Validators).ToArray();
                    var addedHardValidators = validationCollectorInfo.Collector.AddedPropertyRules
                                              .Where(pr => pr.IsHardConstraint && pr.Property.Equals(actualProperty))
                                              .SelectMany(pr => pr.Validators).ToArray();
                    var addedSoftValidators = validationCollectorInfo.Collector.AddedPropertyRules
                                              .Where(pr => !pr.IsHardConstraint && pr.Property.Equals(actualProperty))
                                              .SelectMany(pr => pr.Validators).ToArray();
                    var addedMetaValidations = validationCollectorInfo.Collector.AddedPropertyMetaValidationRules
                                               .Where(pr => pr.Property.Equals(actualProperty))
                                               .SelectMany(pr => pr.MetaValidationRules).ToArray();

                    if (removedRegistrations.Any() || addedHardValidators.Any() || addedSoftValidators.Any() || addedMetaValidations.Any())
                    {
                        AppendPropertyOutput(actualProperty, removedRegistrations, addedHardValidators, addedSoftValidators, addedMetaValidations, sb);
                    }

                    loggedProperties[property] = true;
                }
            }
        }
Ejemplo n.º 9
0
        private IBusinessObjectProperty GetMetadataFromPropertyReflector(string propertyName)
        {
            IPropertyInformation propertyInfo      = GetPropertyInfo(typeof(ClassWithAllDataTypes), propertyName);
            PropertyReflector    propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

            return(propertyReflector.GetMetadata());
        }
Ejemplo n.º 10
0
        private PropertyBase.Parameters GetPropertyParameters(IPropertyInformation property, BindableObjectProvider provider)
        {
            PropertyReflector reflector = PropertyReflector.Create(property, provider);

            return((PropertyBase.Parameters)PrivateInvoke.InvokeNonPublicMethod(
                       reflector, typeof(PropertyReflector), "CreateParameters", GetUnderlyingType(reflector)));
        }
Ejemplo n.º 11
0
 protected PropertyBase.Parameters CreateParameters(
     BindableObjectProvider businessObjectProvider,
     IPropertyInformation propertyInfo,
     Type underlyingType,
     Type concreteType,
     IListInfo listInfo,
     bool isRequired,
     bool isReadOnly,
     IBindablePropertyReadAccessStrategy bindablePropertyReadAccessStrategy   = null,
     IBindablePropertyWriteAccessStrategy bindablePropertyWriteAccessStrategy = null,
     BindableObjectGlobalizationService bindableObjectGlobalizationService    = null)
 {
     return(new PropertyBase.Parameters(
                businessObjectProvider,
                propertyInfo,
                underlyingType,
                new Lazy <Type> (() => concreteType),
                listInfo,
                isRequired,
                isReadOnly,
                new BindableObjectDefaultValueStrategy(),
                bindablePropertyReadAccessStrategy ?? SafeServiceLocator.Current.GetInstance <IBindablePropertyReadAccessStrategy>(),
                bindablePropertyWriteAccessStrategy ?? SafeServiceLocator.Current.GetInstance <IBindablePropertyWriteAccessStrategy>(),
                bindableObjectGlobalizationService ?? SafeServiceLocator.Current.GetInstance <BindableObjectGlobalizationService>()));
 }
 public WrapperObjectSet(SceneNodeObjectSet baseSet, ReferenceStep targetStep, IPropertyInformation redirectedProperty)
     : base(baseSet.DesignerContext, baseSet.TransactionContext)
 {
     this.baseSet            = baseSet;
     this.targetStep         = targetStep;
     this.redirectedProperty = redirectedProperty;
 }
Ejemplo n.º 13
0
        private string GetLogAfter(IEnumerable <IValidationRule> mergedRules, ILogContext logContext)
        {
            var sb = new StringBuilder();

            sb.AppendLine();
            sb.Append("AFTER MERGE:");

            var propertyRules = mergedRules.OfType <PropertyRule>().ToArray();
            var allProperties = propertyRules.Select(mr => (PropertyInfo)mr.Member).Distinct();

            foreach (var property in allProperties)
            {
                IPropertyInformation actualProperty = PropertyInfoAdapter.Create(property);
                var propertyRulesForMember          = propertyRules.Where(pr => (PropertyInfoAdapter.Create((PropertyInfo)pr.Member)).Equals(actualProperty)).ToArray();
                var validators      = propertyRulesForMember.SelectMany(pr => pr.Validators).ToArray();
                var logContextInfos = propertyRulesForMember.SelectMany(logContext.GetLogContextInfos).ToArray();
                AppendPropertyRuleOutput(actualProperty, validators, logContextInfos, sb);
            }

            foreach (var validationRule in mergedRules.Except(propertyRules))
            {
                AppendValidationRuleOutput(validationRule, sb, logContext);
            }

            return(sb.ToString());
        }
Ejemplo n.º 14
0
        public void GetMetadata_ForSealedBusinessObject_WithExistingMixin()
        {
            var mixinTargetType    = typeof(ManualBusinessObject);
            var businessObjectType = typeof(SealedBindableObject);

            Assertion.IsTrue(mixinTargetType.IsAssignableFrom(businessObjectType));

            using (MixinConfiguration.BuildNew()
                   .AddMixinToClass(
                       MixinKind.Extending,
                       mixinTargetType,
                       typeof(MixinStub),
                       MemberVisibility.Public,
                       Enumerable.Empty <Type>(),
                       Enumerable.Empty <Type>())
                   .EnterScope())
            {
                IPropertyInformation propertyInfo = GetPropertyInfo(typeof(ClassWithReferenceType <SealedBindableObject>), "Scalar");

                PropertyReflector propertyReflector = PropertyReflector.Create(propertyInfo, _businessObjectProvider);

                var referenceProperty = (IBusinessObjectReferenceProperty)propertyReflector.GetMetadata();
                Assert.That(() => referenceProperty.SupportsSearchAvailableObjects, Throws.Nothing);
            }
        }
Ejemplo n.º 15
0
        public void ConvertToRuntimeProperty_WithPropertyAdapter_ReturnsRuntimeType()
        {
            var expectedProperty = MemberInfoFromExpressionUtility.GetProperty((TheType t) => t.TheProperty);
            IPropertyInformation propertyInformation = PropertyInfoAdapter.Create(expectedProperty);

            Assert.That(propertyInformation.ConvertToRuntimePropertyInfo(), Is.SameAs(expectedProperty));
        }
Ejemplo n.º 16
0
        public void SetUp()
        {
            _globalizationServiceMock = MockRepository.GenerateStub <IGlobalizationService>();
            _resourceManagerMock      = MockRepository.GenerateStrictMock <IResourceManager>();
            _resourceManagerMock.Stub(stub => stub.IsNull).Return(false);
            _resourceManagerMock.Stub(stub => stub.Name).Return("RM1");

            _typeInformationStub = MockRepository.GenerateStub <ITypeInformation>();
            _typeInformationStub.Stub(stub => stub.Name).Return("TypeName");

            _typeInformationForResourceResolutionStub = MockRepository.GenerateStub <ITypeInformation>();
            _typeInformationForResourceResolutionStub.Stub(stub => stub.Name).Return("TypeNameForResourceResolution");

            _propertyInformationStub = MockRepository.GenerateStub <IPropertyInformation>();
            _propertyInformationStub.Stub(stub => stub.Name).Return("PropertyName");

            _memberInformationNameResolverStub = MockRepository.GenerateStub <IMemberInformationNameResolver>();
            _memberInformationNameResolverStub.Stub(stub => stub.GetPropertyName(_propertyInformationStub)).Return("FakePropertyFullName");
            _memberInformationNameResolverStub.Stub(stub => stub.GetTypeName(_typeInformationStub)).Return("FakeTypeFullName");

            _shortPropertyResourceID = "property:PropertyName";
            _longPropertyResourceID  = "property:FakePropertyFullName";
            _shortTypeResourceID     = "type:TypeName";
            _longTypeResourceID      = "type:FakeTypeFullName";

            _service = new ResourceManagerBasedMemberInformationGlobalizationService(_globalizationServiceMock, _memberInformationNameResolverStub);
        }
 public void SetUp()
 {
     _implementationPropertyInformationStub      = MockRepository.GenerateStub <IPropertyInformation>();
     _declarationPropertyInformationStub         = MockRepository.GenerateStub <IPropertyInformation>();
     _interfaceImplementationPropertyInformation = new InterfaceImplementationPropertyInformation(
         _implementationPropertyInformationStub, _declarationPropertyInformationStub);
 }
        private void AnalyzeAndValidateProperty(IPropertyInformation propertyInformation, string propertyIdentifier)
        {
            if (!_typeConversionProvider.CanConvert(propertyInformation.GetType(), typeof(PropertyInfo)))
            {
                return;
            }

            var property        = (PropertyInfo)_typeConversionProvider.Convert(propertyInformation.GetType(), typeof(PropertyInfo), propertyInformation);
            var isMixinProperty = !property.DeclaringType.IsAssignableFrom(_baseType);

            var getMethod = property.GetGetMethod(true);
            var setMethod = property.GetSetMethod(true);

            if (getMethod != null)
            {
                ValidateAccessor(property, getMethod, isMixinProperty, "get accessor");
            }

            if (setMethod != null)
            {
                ValidateAccessor(property, setMethod, isMixinProperty, "set accessor");
            }

            if (!isMixinProperty)
            {
                _properties.Add(new Tuple <PropertyInfo, string> (property, propertyIdentifier));
            }
        }
        private static string BuildMessage(
            ITypeInformation type,
            IPropertyInformation property,
            string relationID,
            string messageFormat,
            params object[] args)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat(messageFormat, args);
            if (type != null)
            {
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                stringBuilder.AppendFormat("Declaring type: {0}", type);
                if (property != null)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("Property: {0}", property.Name);
                }
                if (relationID != null)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("Relation ID: {0}", relationID);
                }
            }

            return(stringBuilder.ToString());
        }
        public int?GetMaxLength(IPropertyInformation propertyInfo)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);

            var attribute = propertyInfo.GetCustomAttribute <ILengthConstrainedPropertyAttribute> (true);

            return(attribute != null ? attribute.MaximumLength : null);
        }
Ejemplo n.º 21
0
        public IRelationEndPointDefinition ResolveRelationEndPoint(IPropertyInformation propertyInformation)
        {
            ArgumentUtility.CheckNotNull("propertyInformation", propertyInformation);

            var propertyAccessorData = PropertyAccessorDataCache.ResolvePropertyAccessorData(propertyInformation);

            return(propertyAccessorData == null ? null : propertyAccessorData.RelationEndPointDefinition);
        }
        public ClassDefinitionForUnresolvedRelationPropertyType(
            string id, Type classType, IPropertyInformation relationProperty)
            : base(id, classType, false, null, null, new PersistentMixinFinder(classType), new ThrowingDomainObjectCreator())
        {
            ArgumentUtility.CheckNotNull("relationProperty", relationProperty);

            _relationProperty = relationProperty;
        }
Ejemplo n.º 23
0
        public EnumValueFilterProvider(IPropertyInformation propertyInformation, Func <Type, T[]> typeAttributeProvider)
        {
            ArgumentUtility.CheckNotNull("propertyInformation", propertyInformation);
            ArgumentUtility.CheckNotNull("typeAttributeProvider", typeAttributeProvider);

            _propertyInformation   = propertyInformation;
            _typeAttributeProvider = typeAttributeProvider;
        }
        public static MappingValidationResult CreateInvalidResultForProperty(IPropertyInformation propertyInfo, string messageFormat, params object[] args)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);
            ArgumentUtility.CheckNotNullOrEmpty("messageFormat", messageFormat);
            ArgumentUtility.CheckNotNull("args", args);

            return(new MappingValidationResult(false, BuildMessage(propertyInfo.DeclaringType, propertyInfo, null, messageFormat, args)));
        }
 public RelationReflector(
     ClassDefinition classDefinition,
     IPropertyInformation propertyInfo,
     IMemberInformationNameResolver nameResolver,
     IPropertyMetadataProvider propertyMetadataProvider)
     : base(classDefinition, propertyInfo, nameResolver, propertyMetadataProvider)
 {
 }
        public InterfaceImplementationPropertyInformation(IPropertyInformation implementationPropertyInfo, IPropertyInformation declarationPropertyInfo)
        {
            ArgumentUtility.CheckNotNull("implementationPropertyInfo", implementationPropertyInfo);
            ArgumentUtility.CheckNotNull("declarationPropertyInfo", declarationPropertyInfo);

            _implementationPropertyInfo = implementationPropertyInfo;
            _declarationPropertyInfo    = declarationPropertyInfo;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Returns the mapping name for the given <paramref name="propertyInformation"/>.
        /// </summary>
        /// <param name="propertyInformation">The property whose mapping name should be retrieved.</param>
        /// <returns>The name of the given <paramref name="propertyInformation"/> as used internally by the mapping.</returns>
        public string GetPropertyName(IPropertyInformation propertyInformation)
        {
            ArgumentUtility.CheckNotNull("propertyInformation", propertyInformation);

            return(s_propertyNameCache.GetOrCreateValue(
                       propertyInformation,
                       pi => GetPropertyName(pi.GetOriginalDeclaringType(), pi.Name)));
        }
Ejemplo n.º 28
0
 private bool IsPropertyTypeSupported(IPropertyInformation propertyInfo, Type type)
 {
     if (type == typeof(ObjectList <>))
     {
         return(ReflectionUtility.IsObjectList(propertyInfo.PropertyType));
     }
     return(type.IsAssignableFrom(propertyInfo.PropertyType));
 }
 public void SetUp()
 {
     _testHelper          = new SecurityClientTestHelper();
     _securityClient      = _testHelper.CreateSecurityClient();
     _propertyInformation = MockRepository.GenerateMock <IPropertyInformation>();
     _methodInformation   = MockRepository.GenerateMock <IMethodInformation> ();
     _propertyInformation.Expect(mock => mock.GetSetMethod(true)).Return(_methodInformation);
 }
        public bool IsNullable(IPropertyInformation propertyInfo)
        {
            ArgumentUtility.CheckNotNull("propertyInfo", propertyInfo);

            var attribute = propertyInfo.GetCustomAttribute <INullablePropertyAttribute> (true);

            return(attribute == null || attribute.IsNullable);
        }