// remove the base type properties from the derived types. internal void RemoveBaseTypeProperties(StructuralTypeConfiguration derivedStructrualType, StructuralTypeConfiguration baseStructuralType) { IEnumerable <StructuralTypeConfiguration> typesToLift = new[] { derivedStructrualType } .Concat(this.DerivedTypes(derivedStructrualType)); foreach (PropertyConfiguration property in baseStructuralType.Properties .Concat(baseStructuralType.DerivedProperties())) { foreach (StructuralTypeConfiguration structuralType in typesToLift) { PropertyConfiguration derivedPropertyToRemove = structuralType.Properties.SingleOrDefault( p => p.PropertyInfo.Name == property.PropertyInfo.Name); if (derivedPropertyToRemove != null) { structuralType.RemoveProperty(derivedPropertyToRemove.PropertyInfo); } } } foreach (PropertyInfo ignoredProperty in baseStructuralType.IgnoredProperties()) { foreach (StructuralTypeConfiguration structuralType in typesToLift) { PropertyConfiguration derivedPropertyToRemove = structuralType.Properties.SingleOrDefault( p => p.PropertyInfo.Name == ignoredProperty.Name); if (derivedPropertyToRemove != null) { structuralType.RemoveProperty(derivedPropertyToRemove.PropertyInfo); } } } }
public void HasOptionalBinding_AddBindindToNavigationSource() { // Assert ODataModelBuilder builder = new ODataModelBuilder(); var customerType = builder.EntityType <BindingCustomer>(); var navigationSource = builder.EntitySet <BindingCustomer>("Customers"); StructuralTypeConfiguration addressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingAddress"); Assert.Null(addressType); // Guard Assert.Empty(customerType.Properties); // Guard Assert.Null(builder.EntitySets.FirstOrDefault(e => e.Name == "Cities_C")); // Guard // Act new BindingPathConfiguration <BindingCustomer>(builder, customerType, navigationSource.Configuration) .HasSinglePath(c => c.Location) .HasOptionalBinding(a => a.City, "Cities_C"); // Assert addressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingAddress"); Assert.NotNull(addressType); PropertyConfiguration citiesProperty = Assert.Single(addressType.Properties); Assert.Equal("City", citiesProperty.Name); NavigationPropertyConfiguration navigationProperty = Assert.IsType <NavigationPropertyConfiguration>(citiesProperty); Assert.Equal(EdmMultiplicity.ZeroOrOne, navigationProperty.Multiplicity); var bindings = navigationSource.FindBinding(navigationProperty); var binding = Assert.Single(bindings); Assert.Equal("Cities_C", binding.TargetNavigationSource.Name); Assert.Equal("Location/City", binding.BindingPath); }
// remove base type properties from the derived types. internal void RemoveBaseTypeProperties(EntityTypeConfiguration derivedEntity, EntityTypeConfiguration baseEntity) { IEnumerable <EntityTypeConfiguration> typesToLift = new[] { derivedEntity }.Concat(this.DerivedTypes(derivedEntity)); foreach (PropertyConfiguration property in baseEntity.Properties.Concat(baseEntity.DerivedProperties())) { foreach (EntityTypeConfiguration entity in typesToLift) { PropertyConfiguration derivedPropertyToRemove = entity.Properties.SingleOrDefault( p => p.PropertyInfo.Name == property.PropertyInfo.Name); if (derivedPropertyToRemove != null) { entity.RemoveProperty(derivedPropertyToRemove.PropertyInfo); } } } foreach (PropertyInfo ignoredProperty in baseEntity.IgnoredProperties()) { foreach (EntityTypeConfiguration entity in typesToLift) { PropertyConfiguration derivedPropertyToRemove = entity.Properties.SingleOrDefault( p => p.PropertyInfo.Name == ignoredProperty.Name); if (derivedPropertyToRemove != null) { entity.RemoveProperty(derivedPropertyToRemove.PropertyInfo); } } } }
/// <summary> /// Initializes a new instance of the <see cref="QueryableRestrictions"/> class. /// </summary> /// <param name="propertyConfiguration">The PropertyConfiguration containing queryable restrictions.</param> public QueryableRestrictions(PropertyConfiguration propertyConfiguration) { NonFilterable = propertyConfiguration.NonFilterable; Unsortable = propertyConfiguration.Unsortable; NotNavigable = propertyConfiguration.NotNavigable; NotExpandable = propertyConfiguration.NotExpandable; }
private void ReapplyPropertyConvention(PropertyConfiguration property, StructuralTypeConfiguration edmTypeConfiguration) { foreach (IEdmPropertyConvention propertyConvention in _conventions.OfType <IEdmPropertyConvention>()) { propertyConvention.Apply(property, edmTypeConfiguration, this); } }
/// <summary> /// Initializes a new instance of the <see cref="QueryableRestrictions"/> class. /// </summary> /// <param name="propertyConfiguration">The PropertyConfiguration containing queryable restrictions.</param> public QueryableRestrictions(PropertyConfiguration propertyConfiguration) { NotFilterable = propertyConfiguration.NotFilterable; NotSortable = propertyConfiguration.NotSortable; NotNavigable = propertyConfiguration.NotNavigable; NotExpandable = propertyConfiguration.NotExpandable; NotCountable = propertyConfiguration.NotCountable; _autoExpand = propertyConfiguration.AutoExpand; }
private void ValidatePropertyNotAlreadyDefinedInBaseTypes(PropertyInfo propertyInfo) { PropertyConfiguration baseProperty = this.DerivedProperties().Where(p => p.Name == propertyInfo.Name).FirstOrDefault(); if (baseProperty != null) { throw Error.Argument("propertyInfo", SRResources.CannotRedefineBaseTypeProperty, propertyInfo.Name, baseProperty.PropertyInfo.ReflectedType.FullName); } }
public void HasSinglePath_AddBindindPath(bool required, bool contained) { // Assert ODataModelBuilder builder = new ODataModelBuilder(); var customerType = builder.EntityType <BindingCustomer>(); var navigationSource = builder.EntitySet <BindingCustomer>("Customers"); StructuralTypeConfiguration addressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingAddress"); Assert.Null(addressType); // Guard Assert.Empty(customerType.Properties); // Guard // Act var binding = new BindingPathConfiguration <BindingCustomer>(builder, customerType, navigationSource.Configuration); var newBinding = binding.HasSinglePath(c => c.Location, required, contained); // Assert addressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingAddress"); Assert.NotNull(addressType); PropertyConfiguration locationProperty = Assert.Single(customerType.Properties); Assert.Equal("Location", locationProperty.Name); if (contained) { Assert.Equal(EdmTypeKind.Entity, addressType.Kind); Assert.Equal(PropertyKind.Navigation, locationProperty.Kind); NavigationPropertyConfiguration navigationProperty = Assert.IsType <NavigationPropertyConfiguration>(locationProperty); if (required) { Assert.Equal(EdmMultiplicity.One, navigationProperty.Multiplicity); } else { Assert.Equal(EdmMultiplicity.ZeroOrOne, navigationProperty.Multiplicity); } Assert.True(navigationProperty.ContainsTarget); } else { Assert.Equal(EdmTypeKind.Complex, addressType.Kind); Assert.Equal(PropertyKind.Complex, locationProperty.Kind); ComplexPropertyConfiguration complexProperty = Assert.IsType <ComplexPropertyConfiguration>(locationProperty); Assert.Equal(!required, complexProperty.OptionalProperty); Assert.Equal(typeof(BindingAddress), complexProperty.RelatedClrType); } // different bindings Assert.NotSame(binding, newBinding); Assert.Equal("", binding.BindingPath); Assert.IsType <BindingPathConfiguration <BindingAddress> >(newBinding); Assert.Equal("Location", newBinding.BindingPath); }
public PropertyConfigurationTest() { Mock<PropertyInfo> mockPropertyInfo = new Mock<PropertyInfo>(); _propertyInfo = mockPropertyInfo.Object; Mock<StructuralTypeConfiguration> mockTypeConfig = new Mock<StructuralTypeConfiguration>(); _declaringType = mockTypeConfig.Object; Mock<PropertyConfiguration> mockConfiguration = new Mock<PropertyConfiguration>(_propertyInfo, _declaringType) { CallBase = true }; mockConfiguration.Object.Name = "Name"; _configuration = mockConfiguration.Object; }
private void ValidatePropertyNotAlreadyDefinedInDerivedTypes(PropertyInfo propertyInfo) { foreach (EntityTypeConfiguration derivedEntity in ModelBuilder.DerivedTypes(this)) { PropertyConfiguration propertyInDerivedType = derivedEntity.Properties.Where(p => p.Name == propertyInfo.Name).FirstOrDefault(); if (propertyInDerivedType != null) { throw Error.Argument("propertyInfo", SRResources.PropertyAlreadyDefinedInDerivedType, propertyInfo.Name, FullName, derivedEntity.FullName); } } }
internal void ValidatePropertyNotAlreadyDefinedInDerivedTypes(PropertyInfo propertyInfo) { foreach (StructuralTypeConfiguration derivedType in ModelBuilder.DerivedTypes(this)) { PropertyConfiguration propertyInDerivedType = derivedType.Properties.FirstOrDefault(p => p.Name == propertyInfo.Name); if (propertyInDerivedType != null) { throw Error.Argument("propertyInfo", SRResources.PropertyAlreadyDefinedInDerivedType, propertyInfo.Name, FullName, derivedType.FullName); } } }
public PropertyConfigurationTest() { Mock <PropertyInfo> mockPropertyInfo = new Mock <PropertyInfo>(); _propertyInfo = mockPropertyInfo.Object; Mock <StructuralTypeConfiguration> mockTypeConfig = new Mock <StructuralTypeConfiguration>(); _declaringType = mockTypeConfig.Object; Mock <PropertyConfiguration> mockConfiguration = new Mock <PropertyConfiguration>(_propertyInfo, _declaringType) { CallBase = true }; mockConfiguration.Object.Name = "Name"; _configuration = mockConfiguration.Object; }
private bool ShouldApplyLowerCamelCase(PropertyConfiguration property) { if (property.AddedExplicitly) { return(_options.HasFlag(NameResolverOptions.ProcessExplicitPropertyNames)); } else { DataMemberAttribute attribute = property.PropertyInfo.GetCustomAttribute <DataMemberAttribute>(inherit: false); if (attribute != null && !String.IsNullOrWhiteSpace(attribute.Name)) { return(_options.HasFlag(NameResolverOptions.ProcessDataMemberAttributePropertyNames)); } return(_options.HasFlag(NameResolverOptions.ProcessReflectedPropertyNames)); } }
public void CanAddPrimitiveProperty_ForTargetEntityType() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); // Act builder.EntityType <ForeignEntity>().HasRequired(c => c.Principal, (c, r) => c.ForeignKey1 == r.PrincipalKey1); // Assert EntityTypeConfiguration principalEntityType = Assert.Single( builder.StructuralTypes.OfType <EntityTypeConfiguration>().Where(e => e.Name == "ForeignPrincipal")); PropertyConfiguration propertyConfig = Assert.Single(principalEntityType.Properties); PrimitivePropertyConfiguration primitiveConfig = Assert.IsType <PrimitivePropertyConfiguration>(propertyConfig); Assert.Equal("PrincipalKey1", primitiveConfig.Name); Assert.Equal("System.Int32", primitiveConfig.RelatedClrType.FullName); }
public void HasOptionalBinding_AddBindindToNavigationSource_Derived() { // Assert ODataModelBuilder builder = new ODataModelBuilder(); var customerType = builder.EntityType <BindingCustomer>(); var navigationSource = builder.EntitySet <BindingCustomer>("Customers"); StructuralTypeConfiguration addressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingAddress"); Assert.Null(addressType); // Guard Assert.Empty(customerType.Properties); // Guard Assert.Null(builder.EntitySets.FirstOrDefault(e => e.Name == "Cities_D")); // Guard // Act new BindingPathConfiguration <BindingCustomer>(builder, customerType, navigationSource.Configuration) .HasSinglePath((BindingVipCustomer v) => v.VipLocation) .HasOptionalBinding((BindingUsAddress u) => u.UsCity, "Cities_D"); // Assert var usAddressType = builder.StructuralTypes.FirstOrDefault(c => c.Name == "BindingUsAddress"); Assert.NotNull(usAddressType); PropertyConfiguration citiesProperty = Assert.Single(usAddressType.Properties); Assert.Equal("UsCity", citiesProperty.Name); NavigationPropertyConfiguration navigationProperty = Assert.IsType <NavigationPropertyConfiguration>(citiesProperty); Assert.Equal(EdmMultiplicity.ZeroOrOne, navigationProperty.Multiplicity); var bindings = navigationSource.FindBinding(navigationProperty); var binding = Assert.Single(bindings); Assert.Equal("Cities_D", binding.TargetNavigationSource.Name); Assert.Equal("System.Web.OData.Formatter.BindingVipCustomer/VipLocation/System.Web.OData.Formatter.BindingUsAddress/UsCity", binding.BindingPath); }
private bool ShouldApplyLowerCamelCase(PropertyConfiguration property) { if (property.AddedExplicitly) { if (_options.HasFlag(NameResolverOptions.RespectExplicitProperties)) { return false; } } else if (_options.HasFlag(NameResolverOptions.RespectModelAliasing)) { DataMemberAttribute attribute = property.PropertyInfo.GetCustomAttributes(inherit: true) .OfType<DataMemberAttribute>().SingleOrDefault(); if (attribute != null && !String.IsNullOrWhiteSpace(attribute.Name)) { // The property has a resolved name by model aliasing. return false; } } return true; }
private bool ShouldApplyLowerCamelCase(PropertyConfiguration property) { if (property.AddedExplicitly) { return _options.HasFlag(NameResolverOptions.ProcessExplicitPropertyNames); } else { DataMemberAttribute attribute = property.PropertyInfo.GetCustomAttribute<DataMemberAttribute>(inherit: false); if (attribute != null && !String.IsNullOrWhiteSpace(attribute.Name)) { return _options.HasFlag(NameResolverOptions.ProcessDataMemberAttributePropertyNames); } return _options.HasFlag(NameResolverOptions.ProcessReflectedPropertyNames); } }
private void AddExplicitProperty(PropertyInfo propertyInfo, PropertyConfiguration propertyConfiguration) { ExplicitProperties[propertyInfo] = propertyConfiguration; this.explicitPropertyNames.Add(propertyConfiguration.Name); }