public void Apply_should_set_concurrency_token()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration();

            new ConcurrencyCheckAttributeConvention()
                .Apply(
                    new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                    new ConcurrencyCheckAttribute());

            Assert.Equal(ConcurrencyMode.Fixed, propertyConfiguration.ConcurrencyMode);
        }
        public void Apply_should_set_concurrency_token()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration();

            new ConcurrencyCheckAttributeConvention()
            .Apply(
                new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                new ConcurrencyCheckAttribute());

            Assert.Equal(ConcurrencyMode.Fixed, propertyConfiguration.ConcurrencyMode);
        }
示例#3
0
        public void Apply_should_set_store_generated_pattern()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration();

            new DatabaseGeneratedAttributeConvention()
            .Apply(
                new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                new DatabaseGeneratedAttribute(DatabaseGeneratedOption.None));

            Assert.Equal(DatabaseGeneratedOption.None, propertyConfiguration.DatabaseGeneratedOption);
        }
示例#4
0
        public void Apply_should_set_store_generated_pattern()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration();

            new DatabaseGeneratedAttributeConvention()
                .Apply(
                    new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                    new DatabaseGeneratedAttribute(DatabaseGeneratedOption.None));

            Assert.Equal(DatabaseGeneratedOption.None, propertyConfiguration.DatabaseGeneratedOption);
        }
示例#5
0
        public void Apply_should_set_column_name_type_and_order()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration();

            new ColumnAttributeConvention()
                .Apply(new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                new ColumnAttribute("Foo"){TypeName = "bar", Order = 1});

            Assert.Equal("Foo", propertyConfiguration.ColumnName);
            Assert.Equal("bar", propertyConfiguration.ColumnType);
            Assert.Equal(1, propertyConfiguration.ColumnOrder);
        }
        public void Apply_invokes_action_when_no_predicates()
        {
            var actionInvoked = false;
            var convention = new PropertyConvention(
                Enumerable.Empty<Func<PropertyInfo, bool>>(),
                c => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.True(actionInvoked);
        }
        public void Apply_does_not_invoke_action_when_single_predicate_false()
        {
            var actionInvoked = false;
            var convention = new PropertyConvention(
                new Func<PropertyInfo, bool>[] { p => false },
                c => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.False(actionInvoked);
        }
示例#8
0
        public void Apply_does_not_invoke_action_when_single_predicate_false()
        {
            var actionInvoked = false;
            var convention    = new PropertyConvention(
                new Func <PropertyInfo, bool>[] { p => false },
                c => actionInvoked = true);
            var propertyInfo  = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.False(actionInvoked);
        }
示例#9
0
        public void Apply_invokes_action_when_no_predicates()
        {
            var actionInvoked = false;
            var convention    = new PropertyConvention(
                Enumerable.Empty <Func <PropertyInfo, bool> >(),
                c => actionInvoked = true);
            var propertyInfo  = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.True(actionInvoked);
        }
        public void Apply_should_ignore_attribute_if_already_set()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration
                {
                    ConcurrencyMode = ConcurrencyMode.None
                };

            new ConcurrencyCheckAttributeConvention()
                .Apply(
                    new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                    new ConcurrencyCheckAttribute());

            Assert.Equal(ConcurrencyMode.None, propertyConfiguration.ConcurrencyMode);
        }
        public void Apply_should_ignore_attribute_if_already_set()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration
            {
                ConcurrencyMode = ConcurrencyMode.None
            };

            new ConcurrencyCheckAttributeConvention()
            .Apply(
                new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                new ConcurrencyCheckAttribute());

            Assert.Equal(ConcurrencyMode.None, propertyConfiguration.ConcurrencyMode);
        }
示例#12
0
        public void Apply_should_ignore_attribute_if_already_set()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration
                {
                    DatabaseGeneratedOption = DatabaseGeneratedOption.Computed
                };

            new DatabaseGeneratedAttributeConvention()
                .Apply(
                    new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                    new DatabaseGeneratedAttribute(DatabaseGeneratedOption.None));

            Assert.Equal(DatabaseGeneratedOption.Computed, propertyConfiguration.DatabaseGeneratedOption);
        }
示例#13
0
        public void Apply_should_ignore_attribute_if_already_set()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration
            {
                DatabaseGeneratedOption = DatabaseGeneratedOption.Computed
            };

            new DatabaseGeneratedAttributeConvention()
            .Apply(
                new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                new DatabaseGeneratedAttribute(DatabaseGeneratedOption.None));

            Assert.Equal(DatabaseGeneratedOption.Computed, propertyConfiguration.DatabaseGeneratedOption);
        }
        public void Apply_should_set_column_name_type_and_order()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration();

            new ColumnAttributeConvention()
            .Apply(new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration),
                   new ColumnAttribute("Foo")
            {
                TypeName = "bar", Order = 1
            });

            Assert.Equal("Foo", propertyConfiguration.ColumnName);
            Assert.Equal("bar", propertyConfiguration.ColumnType);
            Assert.Equal(1, propertyConfiguration.ColumnOrder);
        }
示例#15
0
        public void Apply_should_not_set_column_name_type_or_when_already_set()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration
                                            {
                                                ColumnName = "Bar",
                                                ColumnType = "foo",
                                                ColumnOrder = 0
                                            };

            new ColumnAttributeConvention()
                .Apply(new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration), new ColumnAttribute("Foo"){TypeName = "bar", Order = 1});

            Assert.Equal("Bar", propertyConfiguration.ColumnName);
            Assert.Equal("foo", propertyConfiguration.ColumnType);
            Assert.Equal(0, propertyConfiguration.ColumnOrder);
        }
        public void Apply_invokes_action_when_all_predicates_true()
        {
            var actionInvoked = false;
            var convention = new PropertyConvention(
                new Func<PropertyInfo, bool>[]
                    {
                        p => true,
                        p => true
                    },
                c => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.True(actionInvoked);
        }
示例#17
0
        public void Apply_invokes_action_when_all_predicates_true()
        {
            var actionInvoked = false;
            var convention    = new PropertyConvention(
                new Func <PropertyInfo, bool>[]
            {
                p => true,
                p => true
            },
                c => actionInvoked = true);
            var propertyInfo  = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.True(actionInvoked);
        }
示例#18
0
        public void Apply_does_not_invoke_action_and_short_circuts_when_first_predicate_false()
        {
            var lastPredicateInvoked = false;
            var actionInvoked        = false;
            var convention           = new PropertyConvention(
                new Func <PropertyInfo, bool>[]
            {
                p => false,
                p => lastPredicateInvoked = true
            },
                c => actionInvoked = true);
            var propertyInfo  = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.False(lastPredicateInvoked);
            Assert.False(actionInvoked);
        }
        public void Apply_should_not_set_column_name_type_or_when_already_set()
        {
            var propertyConfiguration = new PrimitivePropertyConfiguration
            {
                ColumnName  = "Bar",
                ColumnType  = "foo",
                ColumnOrder = 0
            };

            new ColumnAttributeConvention()
            .Apply(new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => propertyConfiguration), new ColumnAttribute("Foo")
            {
                TypeName = "bar", Order = 1
            });

            Assert.Equal("Bar", propertyConfiguration.ColumnName);
            Assert.Equal("foo", propertyConfiguration.ColumnType);
            Assert.Equal(0, propertyConfiguration.ColumnOrder);
        }
示例#20
0
 internal PrimitiveColumnConfiguration(System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration)
 {
     this._configuration = configuration;
 }
示例#21
0
        public void RemoveDuplicateTphColumns()
        {
            int index1;

            for (int index2 = 0; index2 < this._columnMappings.Count - 1; index2 = index1)
            {
                StructuralType declaringType = this._columnMappings[index2].PropertyPath[0].DeclaringType;
                EdmProperty    column        = this._columnMappings[index2].ColumnProperty;
                index1 = index2 + 1;
                EdmType commonBaseType;
                while (index1 < this._columnMappings.Count && column.Name == this._columnMappings[index1].ColumnProperty.Name && (declaringType != this._columnMappings[index1].PropertyPath[0].DeclaringType && TypeSemantics.TryGetCommonBaseType((EdmType)declaringType, (EdmType)this._columnMappings[index1].PropertyPath[0].DeclaringType, out commonBaseType)))
                {
                    ++index1;
                }
                System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration1 = column.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration;
                for (int index3 = index2 + 1; index3 < index1; ++index3)
                {
                    ColumnMappingBuilder toFixup = this._columnMappings[index3];
                    System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration2 = toFixup.ColumnProperty.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration;
                    string errorMessage;
                    if (configuration1 != null && !configuration1.IsCompatible(configuration2, false, out errorMessage))
                    {
                        throw new MappingException(Strings.BadTphMappingToSharedColumn((object)string.Join(".", this._columnMappings[index2].PropertyPath.Select <EdmProperty, string>((Func <EdmProperty, string>)(p => p.Name))), (object)declaringType.Name, (object)string.Join(".", toFixup.PropertyPath.Select <EdmProperty, string>((Func <EdmProperty, string>)(p => p.Name))), (object)toFixup.PropertyPath[0].DeclaringType.Name, (object)column.Name, (object)column.DeclaringType.Name, (object)errorMessage));
                    }
                    configuration2?.Configure(column, this._table, this._storeModel.ProviderManifest, false, false);
                    column.Nullable = true;
                    foreach (AssociationType associationType in this._storeModel.AssociationTypes.Where <AssociationType>((Func <AssociationType, bool>)(a => a.Constraint != null)).Select(a => new
                    {
                        a = a,
                        p = a.Constraint.ToProperties
                    }).Where(_param1 =>
                    {
                        if (!_param1.p.Contains(column))
                        {
                            return(_param1.p.Contains(toFixup.ColumnProperty));
                        }
                        return(true);
                    }).Select(_param0 => _param0.a).ToArray <AssociationType>())
                    {
                        this._storeModel.RemoveAssociationType(associationType);
                    }
                    if (toFixup.ColumnProperty.DeclaringType.HasMember((EdmMember)toFixup.ColumnProperty))
                    {
                        toFixup.ColumnProperty.DeclaringType.RemoveMember((EdmMember)toFixup.ColumnProperty);
                    }
                    toFixup.ColumnProperty = column;
                }
            }
        }
示例#22
0
 public static void AddColumn(EntityType table, EdmProperty column)
 {
     if (table.Properties.Contains(column))
     {
         return;
     }
     System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration configuration = column.GetConfiguration() as System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration;
     if (configuration == null || string.IsNullOrWhiteSpace(configuration.ColumnName))
     {
         string name = column.GetPreferredName() ?? column.Name;
         column.SetUnpreferredUniqueName(column.Name);
         column.Name = ((IEnumerable <INamedDataModelItem>)table.Properties).UniquifyName(name);
     }
     table.AddMember((EdmMember)column);
 }
        public void Apply_does_not_invoke_action_and_short_circuts_when_first_predicate_false()
        {
            var lastPredicateInvoked = false;
            var actionInvoked = false;
            var convention = new PropertyConvention(
                new Func<PropertyInfo, bool>[]
                    {
                        p => false,
                        p => lastPredicateInvoked = true
                    },
                c => actionInvoked = true);
            var propertyInfo = new MockPropertyInfo();
            var configuration = new PrimitivePropertyConfiguration();

            convention.Apply(propertyInfo, () => configuration, new ModelConfiguration());

            Assert.False(lastPredicateInvoked);
            Assert.False(actionInvoked);
        }