public void HasParameterName_should_set_name_on_inner_configuration()
        {
            var innerConfiguration = CreateConfiguration();
            var primitivePropertyConfiguration
                = new PrimitivePropertyConfiguration(innerConfiguration);

            primitivePropertyConfiguration.HasParameterName("Foo");

            Assert.Equal("Foo", innerConfiguration.ParameterName);
        }
        public void Convert(Metadata data, PrimitivePropertyConfiguration configuration)
        {
            if (data == null) throw new ArgumentNullException("data");
            if (configuration == null) throw new ArgumentNullException("configuration");

            Configuration = configuration;
            ConvertToConfiguration(data);
            if (adapter != null)
            {
                adapter.Convert(data, configuration);
            }
        }
        public ConfigurationAdapter Create(PrimitivePropertyConfiguration configuration)
        {
            Type type = configuration.GetType();
            do
            {
                if (adapters.ContainsKey(type))
                {
                    return (ConfigurationAdapter)Activator.CreateInstance(adapters[type]);
                }
                type = type.BaseType;
            } while (type != null && type != typeof(object));

            throw new InvalidOperationException("unknown configuration " + configuration.GetType().Name);
        }
Esempio n. 4
0
        /// <summary>
        /// Configures a <see cref="T:System.struct" /> property that is defined on this type.
        /// </summary>
        /// <typeparam name="T"> The type of the property being configured. </typeparam>
        /// <param name="propertyExpression"> A lambda expression representing the property to be configured. C#: t => t.MyProperty VB.Net: Function(t) t.MyProperty </param>
        /// <returns> A configuration object that can be used to configure the property. </returns>
        public PrimitivePropertyConfiguration Property <T>(
            Expression <Func <TStructuralType, T> > propertyExpression)
            where T : struct
        {
            if (propertyExpression == null)
            {
                throw new ArgumentNullException("propertyExpression");
            }

            var property = ReflectionExpressions.GetPropertyInfo(propertyExpression);
            PrimitivePropertyConfiguration propertyConfiguration;

            if (!PropertyConfigurationsByProperty.TryGetValue(property, out propertyConfiguration))
            {
                propertyConfiguration = new PrimitivePropertyConfiguration(property);
                PropertyConfigurationsByProperty.Add(property, propertyConfiguration);
            }
            return(propertyConfiguration);
        }
        private T GetOrCreateConfiguration <T>() where T : PrimitivePropertyConfiguration, new()
        {
            if (_configuration == null)
            {
                _configuration = new T();
            }
            else if (!(_configuration is T))
            {
                var newConfig = new T();

                newConfig.CopyFrom(_configuration);

                _configuration = newConfig;
            }

            _configuration.OverridableConfigurationParts = OverridableConfigurationParts.None;

            return((T)_configuration);
        }
Esempio n. 6
0
        internal void Configure(
            DbDatabaseMapping databaseMapping, StorageMappingFragment fragment, EntityType entityType)
        {
            DebugCheck.NotNull(fragment);

            var edmPropertyPath = EntityMappingConfiguration.PropertyPathToEdmPropertyPath(PropertyPath, entityType);

            if (edmPropertyPath.Count() > 1)
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            var column
                = fragment.ColumnMappings
                  .Where(pm => pm.PropertyPath.SequenceEqual(edmPropertyPath.Single()))
                  .Select(pm => pm.ColumnProperty)
                  .SingleOrDefault();

            if (column == null ||
                !fragment.Table.Properties.Contains(column))
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition(
                    databaseMapping, entityType, fragment.Table, column))
            {
                column.Nullable = true;
            }

            // Make the property required
            var newConfiguration = new PrimitivePropertyConfiguration
            {
                IsNullable = false,
                OverridableConfigurationParts =
                    OverridableConfigurationParts.OverridableInSSpace
            };

            newConfiguration.Configure(edmPropertyPath.Single().Last());

            fragment.AddNullabilityCondition(column, isNull: false);
        }
        internal PrimitiveColumnConfiguration(PrimitivePropertyConfiguration configuration)
        {
            DebugCheck.NotNull(configuration);

            _configuration = configuration;
        }
        public void HasAnnotation_sets_annotation_on_underlying_configuration()
        {
            var mockConfig = new Mock<Properties.Primitive.PrimitivePropertyConfiguration>();

            var configuration = new PrimitivePropertyConfiguration(mockConfig.Object);

            configuration.HasColumnAnnotation("A", "V");

            mockConfig.Verify(m => m.SetAnnotation("A", "V"));
        }
        public void HasAnnotation_throws_for_invalid_annotation_names()
        {
            var configuration = new PrimitivePropertyConfiguration(CreateConfiguration());

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(() => configuration.HasColumnAnnotation(null, null)).Message);

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("name"),
                Assert.Throws<ArgumentException>(() => configuration.HasColumnAnnotation(" ", null)).Message);

            Assert.Equal(
                Strings.BadAnnotationName("Cheese:Pickle"),
                Assert.Throws<ArgumentException>(() => configuration.HasColumnAnnotation("Cheese:Pickle", null)).Message);
        }
        public void HasDatabaseGeneratedOption_should_throw_when_argument_out_of_range()
        {
            var configuration = new PrimitivePropertyConfiguration(new Properties.Primitive.PrimitivePropertyConfiguration());

            Assert.Equal(
                new ArgumentOutOfRangeException("databaseGeneratedOption").Message,
                Assert.Throws<ArgumentOutOfRangeException>(() => configuration.HasDatabaseGeneratedOption((DatabaseGeneratedOption?)(-1))).
                    Message);
        }
        public void HasColumnOrder_should_throw_when_argument_out_of_range()
        {
            var configuration = new PrimitivePropertyConfiguration(new Properties.Primitive.PrimitivePropertyConfiguration());

            Assert.Equal(
                new ArgumentOutOfRangeException("columnOrder").Message,
                Assert.Throws<ArgumentOutOfRangeException>(() => configuration.HasColumnOrder(-1)).Message);
        }
 public Ef6PrimitivePropertyConfigurationAdapter(PrimitivePropertyConfiguration configuration)
 {
     _Configuration = configuration;
 }
        private static EdmProperty CreateColumn(Mock<EntityType> mockTableType, string name, PrimitivePropertyConfiguration config = null)
        {
            var mockColumn = CreateMockMember(mockTableType.Object, name);
            mockColumn.Setup(m => m.Annotations).Returns(
                config == null
                    ? new DataModelAnnotation[0]
                    : new[]
                        {
                            new DataModelAnnotation
                                {
                                    Name = "Configuration",
                                    Value = config
                                }
                        });
            
            mockColumn.SetupProperty(
                m => m.TypeUsage, TypeUsage.CreateStringTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String), true, false));

            mockTableType.Setup(m => m.HasMember(mockColumn.Object)).Returns(true);

            return mockColumn.Object;
        }
        internal void Configure(
            DbDatabaseMapping databaseMapping, StorageMappingFragment fragment, EntityType entityType)
        {
            DebugCheck.NotNull(fragment);

            var edmPropertyPath = EntityMappingConfiguration.PropertyPathToEdmPropertyPath(PropertyPath, entityType);

            if (edmPropertyPath.Count() > 1)
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            var column
                = fragment.ColumnMappings
                          .Where(pm => pm.PropertyPath.SequenceEqual(edmPropertyPath.Single()))
                          .Select(pm => pm.ColumnProperty)
                          .SingleOrDefault();

            if (column == null
                || !fragment.Table.Properties.Contains(column))
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition(
                databaseMapping, entityType, fragment.Table, column))
            {
                column.Nullable = true;
            }

            // Make the property required
            var newConfiguration = new PrimitivePropertyConfiguration
                {
                    IsNullable = false,
                    OverridableConfigurationParts =
                        OverridableConfigurationParts.OverridableInSSpace
                };

            newConfiguration.Configure(edmPropertyPath.Single().Last());

            fragment.AddNullabilityCondition(column, isNull: false);
        }
        internal PrimitiveColumnConfiguration(PrimitivePropertyConfiguration configuration)
        {
            DebugCheck.NotNull(configuration);

            _configuration = configuration;
        }
        private static EdmProperty CreateColumn(Mock <EntityType> mockTableType, string name, PrimitivePropertyConfiguration config = null)
        {
            var mockColumn = CreateMockMember(mockTableType.Object, name);

            mockColumn.Setup(m => m.Annotations).Returns(
                config == null
                    ? new DataModelAnnotation[0]
                    : new[]
            {
                new DataModelAnnotation
                {
                    Name  = "Configuration",
                    Value = config
                }
            });

            mockColumn.SetupProperty(
                m => m.TypeUsage, TypeUsage.CreateStringTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String), true, false));

            mockTableType.Setup(m => m.HasMember(mockColumn.Object)).Returns(true);

            return(mockColumn.Object);
        }