Ejemplo n.º 1
0
        public void AddDynamicPropertyDictionary_ThrowsIfTypeIsNotDictionary()
        {
            // Arrange
            MockPropertyInfo property = new MockPropertyInfo(typeof(Int32), "Test");
            Mock <StructuralTypeConfiguration> mock = new Mock <StructuralTypeConfiguration> {
                CallBase = true
            };
            StructuralTypeConfiguration configuration = mock.Object;

            // Act & Assert
            ExceptionAssert.ThrowsArgument(() => configuration.AddDynamicPropertyDictionary(property),
                                           "propertyInfo",
                                           string.Format("The argument must be of type '{0}'.", "IDictionary<string, object>"));
        }
        private void MapStructuralType(StructuralTypeConfiguration structuralType)
        {
            IEnumerable <PropertyInfo> properties = ConventionsHelpers.GetProperties(structuralType, includeReadOnly: this._isQueryCompositionMode);

            foreach (PropertyInfo property in properties)
            {
                bool isCollection;
                IEdmTypeConfiguration mappedType;

                PropertyKind propertyKind = this.GetPropertyType(property, out isCollection, out mappedType);

                if (propertyKind == PropertyKind.Primitive || propertyKind == PropertyKind.Complex || propertyKind == PropertyKind.Enum)
                {
                    this.MapStructuralProperty(structuralType, property, propertyKind, isCollection);
                }
                else if (propertyKind == PropertyKind.Dynamic)
                {
                    structuralType.AddDynamicPropertyDictionary(property);
                }
                else
                {
                    // don't add this property if the user has already added it.
                    if (structuralType.NavigationProperties.All(p => p.Name != property.Name))
                    {
                        NavigationPropertyConfiguration addedNavigationProperty;
                        if (!isCollection)
                        {
                            addedNavigationProperty = structuralType.AddNavigationProperty(property, EdmMultiplicity.ZeroOrOne);
                        }
                        else
                        {
                            addedNavigationProperty = structuralType.AddNavigationProperty(property, EdmMultiplicity.Many);
                        }

                        ContainedAttribute containedAttribute = property.GetCustomAttribute <ContainedAttribute>();
                        if (containedAttribute != null)
                        {
                            addedNavigationProperty.Contained();
                        }

                        addedNavigationProperty.AddedExplicitly = false;
                    }
                }
            }

            this.MapDerivedTypes(structuralType);
        }