public void AddCollectionProperty_ThrowsIfTypeIsDateTime(Type propertyType) { // Arrange MockType type = new MockType("Customer", @namespace: "Contoso"); MockPropertyInfo property = new MockPropertyInfo(propertyType, "Birthday"); property.SetupGet(p => p.ReflectedType).Returns(type); property.SetupGet(p => p.DeclaringType).Returns(type); Mock <StructuralTypeConfiguration> mock = new Mock <StructuralTypeConfiguration> { CallBase = true }; mock.Setup(e => e.ModelBuilder).Returns(new Mock <ODataModelBuilder>().Object); StructuralTypeConfiguration configuration = mock.Object; mock.SetupGet(c => c.ClrType).Returns(type); // Act & Assert Assert.ThrowsArgument( () => configuration.AddCollectionProperty(property), "propertyInfo", string.Format( "The type '{0}' of property 'Birthday' in the 'Contoso.Customer' type is not a supported type.", propertyType.FullName)); }
private void MapStructuralProperty(StructuralTypeConfiguration type, PropertyInfo property, PropertyKind propertyKind, bool isCollection) { Contract.Assert(type != null); Contract.Assert(property != null); Contract.Assert(propertyKind == PropertyKind.Complex || propertyKind == PropertyKind.Primitive || propertyKind == PropertyKind.Enum); bool addedExplicitly = type.Properties.Any(p => p.PropertyInfo.Name == property.Name); PropertyConfiguration addedEdmProperty; if (!isCollection) { if (propertyKind == PropertyKind.Primitive) { addedEdmProperty = type.AddProperty(property); } else if (propertyKind == PropertyKind.Enum) { AddEnumType(TypeHelper.GetUnderlyingTypeOrSelf(property.PropertyType)); addedEdmProperty = type.AddEnumProperty(property); } else { addedEdmProperty = type.AddComplexProperty(property); } } else { if (_isQueryCompositionMode) { Contract.Assert(propertyKind != PropertyKind.Complex, "we don't create complex types in query composition mode."); } if (property.PropertyType.IsGenericType) { Type elementType = property.PropertyType.GetGenericArguments().First(); Type elementUnderlyingTypeOrSelf = TypeHelper.GetUnderlyingTypeOrSelf(elementType); if (elementUnderlyingTypeOrSelf.IsEnum) { AddEnumType(elementUnderlyingTypeOrSelf); } } addedEdmProperty = type.AddCollectionProperty(property); } addedEdmProperty.AddedExplicitly = addedExplicitly; }
private CollectionPropertyConfiguration GetCollectionPropertyConfiguration(Expression propertyExpression, bool optional = false) { PropertyInfo propertyInfo = PropertySelectorVisitor.GetSelectedProperty(propertyExpression); CollectionPropertyConfiguration property; property = _configuration.AddCollectionProperty(propertyInfo); if (optional) { property.IsOptional(); } else { property.IsRequired(); } return(property); }