public void CreatePropertyDefinitions() { var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null); var propertyInfo1 = PropertyInfoAdapter.Create(typeof(Order).GetProperty("OrderNumber")); var propertyInfo2 = PropertyInfoAdapter.Create(typeof(Order).GetProperty("DeliveryDate")); var fakePropertyDefinition1 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "P1"); var fakePropertyDefinition2 = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "P2"); _mappingObjectFactoryMock .Expect(mock => mock.CreatePropertyDefinition(classDefinition, propertyInfo1)) .Return(fakePropertyDefinition1); _mappingObjectFactoryMock .Expect(mock => mock.CreatePropertyDefinition(classDefinition, propertyInfo2)) .Return(fakePropertyDefinition2); _mappingObjectFactoryMock.Replay(); var result = _factory.CreatePropertyDefinitions(classDefinition, new[] { propertyInfo1, propertyInfo2 }); _mappingObjectFactoryMock.VerifyAllExpectations(); Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result[0], Is.SameAs(fakePropertyDefinition1)); Assert.That(result[1], Is.SameAs(fakePropertyDefinition2)); }
public void CanBeSetFromOutside_ImplicitInterfaceScalar_FromImplementation() { PropertyInfoAdapter adapter = _implicitInterfaceAdapter; Assert.That(adapter.CanBeSetFromOutside, Is.True); AssertCanSet(adapter, new ClassWithReferenceType <SimpleReferenceType>(), new SimpleReferenceType()); }
public void NoRelationProperty_UnsupportedType() { var propertyDefinition = new PropertyDefinition( _classDefinition, PropertyInfoAdapter.Create(typeof(DerivedValidationDomainObjectClass).GetProperty("PropertyWithTypeObjectWithStorageClassPersistent")), "PropertyWithTypeObjectWithStorageClassPersistent", false, true, null, StorageClass.Persistent); propertyDefinition.SetStorageProperty(new FakeStoragePropertyDefinition("PropertyWithTypeObjectWithStorageClassPersistent")); _classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition }, true)); _classDefinition.SetReadOnly(); var validationResult = _validationRule.Validate(_classDefinition); var expectedMessage = "The property type 'Object' is not supported. If you meant to declare a relation, 'Object' must be derived from 'DomainObject'. " + "For non-mapped properties, use the 'StorageClassNoneAttribute'.\r\n\r\n" + "Declaring type: Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Validation.DerivedValidationDomainObjectClass\r\n" + "Property: PropertyWithTypeObjectWithStorageClassPersistent"; AssertMappingValidationResult(validationResult, false, expectedMessage); }
private Expression ResolveMemberInClassDefinition( SqlEntityExpression originatingEntity, PropertyInfoAdapter propertyInfoAdapter, ClassDefinition classDefinition) { var endPointDefinition = classDefinition.ResolveRelationEndPoint(propertyInfoAdapter); if (endPointDefinition != null) { if (endPointDefinition.Cardinality != CardinalityType.One) { var message = string.Format( "Cannot resolve a collection-valued end-point definition. ('{0}.{1}')", originatingEntity.Type, propertyInfoAdapter.Name); throw new NotSupportedException(message); } return(new SqlEntityRefMemberExpression(originatingEntity, propertyInfoAdapter.PropertyInfo)); } var propertyDefinition = classDefinition.ResolveProperty(propertyInfoAdapter); if (propertyDefinition != null) { return(_storageSpecificExpressionResolver.ResolveProperty(originatingEntity, propertyDefinition)); } return(null); }
protected RelationEndPointDefinition GetRelationEndPointDefinition <TSource, TRelated> (Expression <Func <TSource, TRelated> > propertyAccessExpression) { var typeDefinition = MappingConfiguration.GetTypeDefinition(typeof(TSource)); var propertyInfoAdapter = PropertyInfoAdapter.Create(NormalizingMemberInfoFromExpressionUtility.GetProperty(propertyAccessExpression)); return((RelationEndPointDefinition)typeDefinition.ResolveRelationEndPoint(propertyInfoAdapter)); }
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()); }
public void SetUp() { _propertyInfo = typeof(string).GetProperty("Length"); _propertyInfoAdapter = PropertyInfoAdapter.Create(_propertyInfo); _converter = new PropertyInfoAdapterConverter(); }
public void ExtractPropertyValidatorsToRemove() { var addingComponentPropertyRule = MockRepository.GenerateStub <IAddingComponentPropertyRule>(); addingComponentPropertyRule.Stub(stub => stub.Validators) .Return( new IPropertyValidator[] { _stubPropertyValidator1, _stubPropertyValidator2, _stubPropertyValidator3, _stubPropertyValidator4 }); addingComponentPropertyRule.Stub(stub => stub.CollectorType).Return(typeof(CustomerValidationCollector1)); addingComponentPropertyRule.Stub(stub => stub.Property).Return(PropertyInfoAdapter.Create(typeof(Customer).GetProperty("LastName"))); _logContextMock.Expect( mock => mock.ValidatorRemoved( Arg <IPropertyValidator> .Is.Same(_stubPropertyValidator2), Arg <ValidatorRegistrationWithContext[]> .List.Equal(new[] { _registrationWithContext1, _registrationWithContext6 }), Arg <IValidationRule> .Is.Same(addingComponentPropertyRule))).Repeat.Once(); _logContextMock.Expect( mock => mock.ValidatorRemoved( Arg <IPropertyValidator> .Is.Same(_stubPropertyValidator3), Arg <ValidatorRegistrationWithContext[]> .List.Equal(new[] { _registrationWithContext2 }), Arg <IValidationRule> .Is.Same(addingComponentPropertyRule))).Repeat.Once(); var result = _extractor.ExtractPropertyValidatorsToRemove(addingComponentPropertyRule).ToArray(); _logContextMock.VerifyAllExpectations(); Assert.That(result, Is.EqualTo(new IPropertyValidator[] { _stubPropertyValidator2, _stubPropertyValidator3 })); }
public void RelationDefinitionWithTypeNotFoundClassDefinition() { var classDefinition = new ClassDefinitionForUnresolvedRelationPropertyType( "Test", typeof(ClassOutOfInheritanceHierarchy), PropertyInfoAdapter.Create(typeof(DerivedValidationDomainObjectClass).GetProperty("Property"))); var endPoint = new VirtualRelationEndPointDefinition( classDefinition, "RelationProperty", false, CardinalityType.One, null, PropertyInfoAdapter.Create(typeof(DerivedValidationDomainObjectClass).GetProperty("Property"))); var relationDefinition = new RelationDefinition("ID", endPoint, endPoint); var validationResult = _validationRule.Validate(relationDefinition); var expectedMessage = "The relation property 'Property' has return type 'String', which is not a part of the mapping. " + "Relation properties must not point to classes above the inheritance root.\r\n\r\n" + "Declaring type: Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Validation.DerivedValidationDomainObjectClass\r\n" + "Property: Property"; AssertMappingValidationResult(validationResult, false, expectedMessage); }
public void OppositeRelationPropertyNameDoesNotMatch() { var endPointDefinition1 = new VirtualRelationEndPointDefinition( _classDefinition1, "RelationProperty3", false, CardinalityType.One, null, PropertyInfoAdapter.Create(typeof(RelationEndPointPropertyClass1).GetProperty("RelationProperty3"))); var endPointDefinition2 = new VirtualRelationEndPointDefinition( _classDefinition2, "RelationPopertyWithNonMatchingPropertyName", false, CardinalityType.One, null, PropertyInfoAdapter.Create(typeof(RelationEndPointPropertyClass2).GetProperty("RelationPopertyWithNonMatchingPropertyName"))); var relationDefinition = CreateRelationDefinitionAndSetBackReferences("Test", endPointDefinition1, endPointDefinition2); var validationResult = _validationRule.Validate(relationDefinition); var expectedMessage = "Opposite relation property 'RelationPopertyWithNonMatchingPropertyName' declared on type 'RelationEndPointPropertyClass2' " + "defines a 'DBBidirectionalRelationAttribute' whose opposite property does not match.\r\n\r\n" + "Declaring type: Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Validation.Reflection." + "RelationEndPointNamesAreConsistentValidationRule.RelationEndPointPropertyClass1\r\n" + "Property: RelationProperty3"; AssertMappingValidationResult(validationResult, false, expectedMessage); }
public void ContainsPropertyDisplayName() { var service = SafeServiceLocator.Current.GetInstance <IMemberInformationGlobalizationService>(); Assert.That( service.ContainsPropertyDisplayName( PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithShortIdentifier")), TypeAdapter.Create(typeof(ClassWithResources))), Is.True); Assert.That( service.ContainsPropertyDisplayName( PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithLongIdentifier")), TypeAdapter.Create(typeof(ClassWithResources))), Is.True); Assert.That( service.ContainsPropertyDisplayName( PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithoutResources")), TypeAdapter.Create(typeof(ClassWithResources))), Is.False); Assert.That( service.ContainsPropertyDisplayName( PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithLongIdentifier")), TypeAdapter.Create(typeof(ClassWithoutMultiLingualResourcesAttributes))), Is.False); Assert.That( () => service.ContainsPropertyDisplayName( PropertyInfoAdapter.Create(typeof(ClassWithProperties).GetProperty("PropertyWithLongIdentifier")), TypeAdapter.Create(typeof(ClassWithMissingResources))), Throws.TypeOf <MissingManifestResourceException>()); }
public void IsVirtualEndRelationEndpoint_BidirectionalOneToMany() { var propertyInfo = PropertyInfoAdapter.Create(_classType.GetProperty("BaseBidirectionalOneToMany")); var relationEndPointReflector = CreateRelationEndPointReflector(propertyInfo); Assert.That(relationEndPointReflector.IsVirtualEndRelationEndpoint(), Is.True); }
private IRelationEndPointDefinition GetEagerFetchRelationEndPointDefinition(FetchRequestBase fetchRequest, ClassDefinition classDefinition) { var propertyInfo = fetchRequest.RelationMember as PropertyInfo; if (propertyInfo == null) { var message = string.Format( "The member '{0}' is a '{1}', which cannot be fetched by this LINQ provider. Only properties can be fetched.", fetchRequest.RelationMember.Name, fetchRequest.RelationMember.MemberType); throw new NotSupportedException(message); } var propertyInfoAdapter = PropertyInfoAdapter.Create(propertyInfo); var endPoint = classDefinition.ResolveRelationEndPoint(propertyInfoAdapter) ?? classDefinition.GetAllDerivedClasses() .Select(cd => cd.ResolveRelationEndPoint(propertyInfoAdapter)) .FirstOrDefault(ep => ep != null); if (endPoint == null) { Assertion.IsNotNull(propertyInfo.DeclaringType); var message = string.Format( "The property '{0}.{1}' is not a relation end point. Fetching it is not supported by this LINQ provider.", propertyInfo.DeclaringType.FullName, propertyInfo.Name); throw new NotSupportedException(message); } return(endPoint); }
public void ResolvePropertyAccessorData_PropertyInformation_UnknownOnThisObject() { var propertyinformation = PropertyInfoAdapter.Create(typeof(OrderItem).GetProperty("Product")); var data = _orderCache.ResolvePropertyAccessorData(propertyinformation); Assert.That(data, Is.Null); }
public void CreateRelationEndPointDefinitionCollection() { var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(OrderTicket)); var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(classDefinition); classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition }, true)); var fakeRelationEndPoint = new RelationEndPointDefinition(propertyDefinition, false); var expectedPropertyInfo = PropertyInfoAdapter.Create(typeof(OrderTicket).GetProperty("Order")); _mappingObjectFactoryMock .Expect( mock => mock.CreateRelationEndPointDefinition( Arg.Is(classDefinition), Arg.Is(PropertyInfoAdapter.Create(expectedPropertyInfo.PropertyInfo)))) .Return(fakeRelationEndPoint); _mappingObjectFactoryMock.Replay(); var result = _factory.CreateRelationEndPointDefinitionCollection(classDefinition); _mappingObjectFactoryMock.VerifyAllExpectations(); _memberInformationNameResolverMock.VerifyAllExpectations(); Assert.That(result.Count, Is.EqualTo(1)); Assert.That(result[0], Is.SameAs(fakeRelationEndPoint)); }
public void GetGetMethod_GetSetMethod_ExplicitPropertyImplementation() { var implementationPropertyInfo = PropertyInfoAdapter.Create(typeof(ClassImplementingInterface).GetProperty( "Remotion.ObjectBinding.UnitTests.TestDomain.IInterfaceToImplement.ExplicitProperty", BindingFlags.NonPublic | BindingFlags.Instance)); var declaringPropertyInfo = PropertyInfoAdapter.Create(typeof(IInterfaceToImplement).GetProperty("ExplicitProperty")); var interfaceImplementationPropertyInformation = new InterfaceImplementationPropertyInformation( implementationPropertyInfo, declaringPropertyInfo); var getMethodResult = interfaceImplementationPropertyInformation.GetGetMethod(false); CheckMethodInformation( typeof(InterfaceImplementationMethodInformation), TypeAdapter.Create(typeof(ClassImplementingInterface)), "Remotion.ObjectBinding.UnitTests.TestDomain.IInterfaceToImplement.get_ExplicitProperty", getMethodResult); var setMethodResult = interfaceImplementationPropertyInformation.GetSetMethod(false); CheckMethodInformation( typeof(InterfaceImplementationMethodInformation), TypeAdapter.Create(typeof(ClassImplementingInterface)), "Remotion.ObjectBinding.UnitTests.TestDomain.IInterfaceToImplement.set_ExplicitProperty", setMethodResult); }
private IPropertyInformation EnsurePropertyDefinitionExisitsOnClassDefinition( ClassDefinition classDefinition, Type declaringType, string propertyName) { var propertyInfo = PropertyInfoAdapter.Create(declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)); var propertyReflector = new PropertyReflector( classDefinition, propertyInfo, new ReflectionBasedMemberInformationNameResolver(), PropertyMetadataProvider, DomainModelConstraintProviderStub); var propertyDefinition = propertyReflector.GetMetadata(); if (!classDefinition.MyPropertyDefinitions.Contains(propertyDefinition.PropertyName)) { var propertyDefinitions = new PropertyDefinitionCollection(classDefinition.MyPropertyDefinitions, false); propertyDefinitions.Add(propertyDefinition); PrivateInvoke.SetNonPublicField(classDefinition, "_propertyDefinitions", propertyDefinitions); var endPoints = new RelationEndPointDefinitionCollection(classDefinition.MyRelationEndPointDefinitions, false); endPoints.Add(MappingObjectFactory.CreateRelationEndPointDefinition(classDefinition, propertyInfo)); PrivateInvoke.SetNonPublicField(classDefinition, "_relationEndPoints", endPoints); } return(propertyInfo); }
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)); }
public void RelationToClassNotInMapping() { var endPoint1 = new VirtualRelationEndPointDefinition( _derivedClassDefinition1, "RelationProperty4", false, CardinalityType.One, null, PropertyInfoAdapter.Create(typeof(DerivedRelationEndPointPropertyClass1).GetProperty("RelationProperty4"))); var endPoint2 = new VirtualRelationEndPointDefinition( _derivedClassDefinition2, "RelationProperty4", false, CardinalityType.One, null, PropertyInfoAdapter.Create(typeof(DerivedRelationEndPointPropertyClass2).GetProperty("RelationProperty4"))); var relationDefinition = CreateRelationDefinitionAndSetBackReferences("Test", endPoint1, endPoint2); var validationResult = _validationRule.Validate(relationDefinition); var expectedMessage = "The type 'BaseRelationEndPointPropertyClass2' cannot be assigned to the type of the opposite relation propery 'RelationProperty4' declared " + "on type 'DerivedRelationEndPointPropertyClass1'.\r\n\r\n" + "Declaring type: Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Validation.Reflection." + "RelationEndPointTypesAreConsistentValidationRule.BaseRelationEndPointPropertyClass2\r\n" + "Property: RelationProperty4"; AssertMappingValidationResult(validationResult, false, expectedMessage); }
// Note: The re-bind-specific IPropertyInformation implementations should no longer be necessary after re-bind is changed to explicitly support // interfaces. (Because re-bind will no longer represent explicit interface properties within the BusinessObjectClass for the class - // the BusinessObjectClass for the interface must be used instead.) private IPropertyInformation GetPropertyInformation(PropertyInfo propertyInfo) { var introducedMemberAttributes = propertyInfo.GetCustomAttributes(typeof(IntroducedMemberAttribute), true); if (introducedMemberAttributes.Length > 0) { var introducedMemberAttribute = (IntroducedMemberAttribute)introducedMemberAttributes[0]; var interfaceProperty = PropertyInfoAdapter.Create(introducedMemberAttribute.IntroducedInterface.GetProperty(introducedMemberAttribute.InterfaceMemberName)); var mixinProperty = interfaceProperty.FindInterfaceImplementation(introducedMemberAttribute.Mixin); var interfaceImplementation = new InterfaceImplementationPropertyInformation(mixinProperty, interfaceProperty); return(new MixinIntroducedPropertyInformation(interfaceImplementation)); } else { var propertyInfoAdapter = PropertyInfoAdapter.Create(propertyInfo); var interfaceDeclaration = propertyInfoAdapter.FindInterfaceDeclarations().FirstOrDefault(); if (interfaceDeclaration != null) { return(new InterfaceImplementationPropertyInformation(propertyInfoAdapter, interfaceDeclaration)); } else { return(propertyInfoAdapter); } } }
public void ResolvePropertyAccessorData_PropertyInformation_Unknown() { var propertyinformation = PropertyInfoAdapter.Create(typeof(Order).GetProperty("NotInMapping")); var data = _orderCache.ResolvePropertyAccessorData(propertyinformation); Assert.That(data, Is.Null); }
protected PropertyInfoAdapter GetPropertyInformation(Type declaringType, string propertyName) { var propertyInfo = declaringType.GetProperty( propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); Assert.That(propertyInfo, Is.Not.Null, "Property not found: '{0}.{1}'", declaringType, propertyName); return(PropertyInfoAdapter.Create(propertyInfo)); }
public void IsMixedProperty_MixedProperty_ReturnsTrue() { var property = PropertyInfoAdapter.Create(typeof(MixinAddingProperty).GetProperty("MixedProperty")); var result = ReflectionUtility.IsMixedProperty(property, _classDefinitionWithMixedProperty); Assert.That(result, Is.True); }
public void IsMixedProperty_NoMixedProperty_ReturnsFalse() { var property = PropertyInfoAdapter.Create(typeof(ClassWithMixedProperty).GetProperty("PublicNonMixedProperty")); var result = ReflectionUtility.IsMixedProperty(property, _classDefinitionWithMixedProperty); Assert.That(result, Is.False); }
public void GetDeclaringDomainObjectTypeForProperty_MixedProperty() { var property = PropertyInfoAdapter.Create(typeof(MixinAddingProperty).GetProperty("MixedProperty")); var result = ReflectionUtility.GetDeclaringDomainObjectTypeForProperty(property, _classDefinitionWithMixedProperty); Assert.That(result, Is.SameAs(typeof(ClassWithMixedProperty))); }
public void FindInterfaceImplementation() { var propertyInfoAdapter = PropertyInfoAdapter.Create(typeof(string).GetProperty("Length")); _implementationPropertyInformationStub.Stub(stub => stub.FindInterfaceImplementation(typeof(bool))).Return(propertyInfoAdapter); Assert.That(_interfaceImplementationPropertyInformation.FindInterfaceImplementation(typeof(bool)), Is.SameAs(propertyInfoAdapter)); }
public void FindDeclaringProperty() { var objToReturn = PropertyInfoAdapter.Create(typeof(string).GetProperty("Length")); _implementationMethodInformationStub.Stub(stub => stub.FindDeclaringProperty()).Return(objToReturn); Assert.That(_interfaceImplementationMethodInformation.FindDeclaringProperty(), Is.SameAs(objToReturn)); }
public void PropertyInfo() { ClassDefinition employeeClassDefinition = MappingConfiguration.Current.GetTypeDefinition(typeof(Employee)); VirtualRelationEndPointDefinition relationEndPointDefinition = (VirtualRelationEndPointDefinition)employeeClassDefinition.GetRelationEndPointDefinition(typeof(Employee) + ".Computer"); Assert.That(relationEndPointDefinition.PropertyInfo, Is.EqualTo(PropertyInfoAdapter.Create(typeof(Employee).GetProperty("Computer")))); }
protected IPropertyInformation GetPropertyInfo(Type type, string propertyName) { PropertyInfo propertyInfo = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); Assert.IsNotNull(propertyInfo, "Property '{0}' was not found on type '{1}'.", propertyName, type); return(PropertyInfoAdapter.Create(propertyInfo)); }
public void FindDeclaringProperty() { var propertyInfoAdapter = PropertyInfoAdapter.Create(typeof(string).GetProperty("Length")); _implementationMethodInformationStub.Stub(stub => stub.FindDeclaringProperty()).Return(propertyInfoAdapter); Assert.That(_mixinIntroducedMethodInformation.FindDeclaringProperty(), Is.SameAs(propertyInfoAdapter)); }