public void Configure_should_preserve_the_most_derived_configuration() { var configurationA = CreateConfiguration(); configurationA.ConcurrencyMode = ConcurrencyMode.Fixed; var configurationB = new Properties.Primitive.PrimitivePropertyConfiguration(); configurationB.IsNullable = false; var property = EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); Assert.Null(property.GetConfiguration()); configurationA.Configure(property); Assert.Equal( ConcurrencyMode.Fixed, ((Properties.Primitive.PrimitivePropertyConfiguration)property.GetConfiguration()).ConcurrencyMode); configurationB.Configure(property); Assert.Equal( ConcurrencyMode.Fixed, ((Properties.Primitive.PrimitivePropertyConfiguration)property.GetConfiguration()).ConcurrencyMode); Assert.Equal(false, ((Properties.Primitive.PrimitivePropertyConfiguration)property.GetConfiguration()).IsNullable); Assert.Equal(GetConfigurationType(), property.GetConfiguration().GetType()); }
private PrimitivePropertyConfiguration Cloning_a_primitive_property_configuration_clones_its_property_information_implementation( PrimitivePropertyConfiguration configuration) { configuration.IsNullable = true; configuration.ConcurrencyMode = ConcurrencyMode.Fixed; configuration.DatabaseGeneratedOption = DatabaseGeneratedOption.Identity; configuration.ColumnType = "ColumnType"; configuration.ColumnName = "ColumnName"; configuration.ColumnOrder = 1; configuration.OverridableConfigurationParts = OverridableConfigurationParts.OverridableInCSpace; configuration.SetAnnotation("A1", "V1"); configuration.SetAnnotation("A2", "V2"); configuration.SetAnnotation("A3", "V3"); configuration.SetAnnotation("A1", "V4"); configuration.SetAnnotation("A2", null); var clone = configuration.Clone(); Assert.True(clone.IsNullable.Value); Assert.Equal(ConcurrencyMode.Fixed, clone.ConcurrencyMode); Assert.Equal(DatabaseGeneratedOption.Identity, clone.DatabaseGeneratedOption); Assert.Equal("ColumnType", clone.ColumnType); Assert.Equal("ColumnName", clone.ColumnName); Assert.Equal(1, clone.ColumnOrder); Assert.Equal(OverridableConfigurationParts.OverridableInCSpace, clone.OverridableConfigurationParts); Assert.Equal("V4", clone.Annotations["A1"]); Assert.Null(clone.Annotations["A2"]); Assert.Equal("V3", clone.Annotations["A3"]); return(clone); }
private void ConfigureColumnType( DbProviderManifest providerManifest, Properties.Primitive.PrimitivePropertyConfiguration existingConfiguration, EdmProperty discriminatorColumn) { if (((existingConfiguration != null) && existingConfiguration.ColumnType != null) || ((_configuration != null) && (_configuration.ColumnType != null))) { return; } PrimitiveType primitiveType; Value.GetType().IsPrimitiveType(out primitiveType); var edmType = (PrimitiveType)providerManifest.GetStoreType( (primitiveType == PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)) ? DatabaseMappingGenerator.DiscriminatorTypeUsage : TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(primitiveType.PrimitiveTypeKind))).EdmType; if ((existingConfiguration != null) && !discriminatorColumn.TypeName.Equals(edmType.Name, StringComparison.OrdinalIgnoreCase)) { throw Error.ConflictingInferredColumnType( discriminatorColumn.Name, discriminatorColumn.TypeName, edmType.Name); } discriminatorColumn.PrimitiveType = edmType; }
public void ClrPropertyInfo_returns_propertyInfo() { var propertyInfo = new MockPropertyInfo(); var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(propertyInfo, () => innerConfig); Assert.Same(propertyInfo.Object, config.ClrPropertyInfo); }
public void HasColumnOrder_throws_on_negative_arguments() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); Assert.Equal( "columnOrder", Assert.Throws <ArgumentOutOfRangeException>(() => config.HasColumnOrder(-1)).ParamName); }
public void HasPrecision_with_scale_throws_when_not_decimal() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); Assert.Equal( Strings.LightweightPrimitivePropertyConfiguration_HasPrecisionNonDecimal("P"), Assert.Throws <InvalidOperationException>(() => config.HasPrecision(8, 2)).Message); }
public void IsUnicode_with_parameter_is_noop_when_not_string() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.IsUnicode(false); Assert.Same(config, result); }
public void IsUnicode_with_parameter_throws_when_not_string() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var ex = Assert.Throws <InvalidOperationException>(() => config.IsUnicode(false)); Assert.Equal(Strings.LightweightPrimitivePropertyConfiguration_IsUnicodeNonString("P"), ex.Message); }
public void IsOptional_throws_on_non_nullable_property() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(typeof(int), "IntProperty"), () => innerConfig); Assert.Equal( Strings.LightweightPrimitivePropertyConfiguration_NonNullableProperty("System.Object.IntProperty", typeof(int).Name), Assert.Throws <InvalidOperationException>(() => config.IsOptional()).Message); }
private ValueConditionConfiguration( EntityMappingConfiguration owner, ValueConditionConfiguration source) { this._entityMappingConfiguration = owner; this.Discriminator = source.Discriminator; this.Value = source.Value; this._configuration = source._configuration == null ? (System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration)null : source._configuration.Clone(); }
public void HasMaxLength_throws_when_not_length() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); Assert.Equal( Strings.LightweightPrimitivePropertyConfiguration_NonLength("P"), Assert.Throws <InvalidOperationException>(() => config.HasMaxLength(256)).Message); }
public void IsRowVersion_throws_when_not_binary() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); Assert.Equal( Strings.LightweightPrimitivePropertyConfiguration_IsRowVersionNonBinary("P"), Assert.Throws <InvalidOperationException>(() => config.IsRowVersion()).Message); }
public void HasColumnName_configures_when_unset() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.HasColumnName("Column1"); Assert.Equal("Column1", innerConfig.ColumnName); Assert.Same(config, result); }
public void IsRequired_configures_when_unset() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.IsRequired(); Assert.Equal(false, innerConfig.IsNullable); Assert.Same(config, result); }
public void HasDatabaseGeneratedOption_evaluates_preconditions() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var ex = Assert.Throws <ArgumentOutOfRangeException>( () => config.HasDatabaseGeneratedOption((DatabaseGeneratedOption)(-1))); Assert.Equal("databaseGeneratedOption", ex.ParamName); }
public void IsConcurrencyToken_with_parameter_configures_when_unset() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.IsConcurrencyToken(false); Assert.Equal(ConcurrencyMode.None, innerConfig.ConcurrencyMode); Assert.Same(config, result); }
public void HasDatabaseGeneratedOption_configures_when_unset() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed); Assert.Equal(DatabaseGeneratedOption.Computed, innerConfig.DatabaseGeneratedOption); Assert.Same(config, result); }
public void HasColumnName_evaluates_preconditions() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var ex = Assert.Throws <ArgumentException>( () => config.HasColumnName("")); Assert.Equal(Strings.ArgumentIsNullOrWhitespace("columnName"), ex.Message); }
public void IsOptional_is_noop_when_set() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration { IsNullable = false }; var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.IsOptional(); Assert.Equal(false, innerConfig.IsNullable); Assert.Same(config, result); }
public void HasColumnType_is_noop_when_set() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration { ColumnType = "int" }; var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.HasColumnType("long"); Assert.Equal("int", innerConfig.ColumnType); Assert.Same(config, result); }
public void IsConcurrencyToken_is_noop_when_set() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration { ConcurrencyMode = ConcurrencyMode.None }; var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.IsConcurrencyToken(); Assert.Equal(ConcurrencyMode.None, innerConfig.ConcurrencyMode); Assert.Same(config, result); }
public void HasAnnotation_configures_only_annotations_that_have_not_already_been_set() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration(); innerConfig.SetAnnotation("A1", "V1"); var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.HasColumnAnnotation("A1", "V1B").HasColumnAnnotation("A2", "V2"); Assert.Equal("V1", innerConfig.Annotations["A1"]); Assert.Equal("V2", innerConfig.Annotations["A2"]); Assert.Same(config, result); }
public void HasColumnOrder_is_noop_when_set() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration { ColumnOrder = 1 }; var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.HasColumnOrder(2); Assert.Equal(1, innerConfig.ColumnOrder); Assert.Same(config, result); }
public void HasParameterName_is_noop_when_set() { var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration { ParameterName = "Parameter1" }; var config = new ConventionPrimitivePropertyConfiguration(new MockPropertyInfo(), () => innerConfig); var result = config.HasParameterName("Parameter2"); Assert.Equal("Parameter1", innerConfig.ParameterName); Assert.Same(config, result); }
private ValueConditionConfiguration(EntityMappingConfiguration owner, ValueConditionConfiguration source) { DebugCheck.NotNull(source); _entityMappingConfiguration = owner; Discriminator = source.Discriminator; Value = source.Value; _configuration = (source._configuration == null) ? null : source._configuration.Clone(); }
private T GetOrCreateConfiguration <T>() where T : System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration, new() { if (this._configuration == null) { this._configuration = (System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration) new T(); } else if (!(this._configuration is T)) { T obj = new T(); obj.CopyFrom(this._configuration); this._configuration = (System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration)obj; } this._configuration.OverridableConfigurationParts = OverridableConfigurationParts.None; return((T)this._configuration); }
private PrimitivePropertyConfiguration OverrideFrom(PrimitivePropertyConfiguration overridingConfiguration, bool inCSpace) { if (overridingConfiguration.GetType().IsAssignableFrom(GetType())) { MakeCompatibleWith(overridingConfiguration, inCSpace); FillFrom(overridingConfiguration, inCSpace); return(this); } else { overridingConfiguration.FillFrom(this, inCSpace); return(overridingConfiguration); } }
public void IsKey_configures_when_unset() { var typeConfig = new EntityTypeConfiguration(typeof(AType1)); var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration { TypeConfiguration = typeConfig }; var propertyInfo = typeof(AType1).GetDeclaredProperty("Property1"); var config = new ConventionPrimitivePropertyConfiguration(propertyInfo, () => innerConfig); var result = config.IsKey(); Assert.Equal(1, typeConfig.KeyProperties.Count()); Assert.Contains(propertyInfo, typeConfig.KeyProperties); Assert.Same(config, result); }
internal override bool IsCompatible( PrimitivePropertyConfiguration other, bool inCSpace, out string errorMessage) { LengthPropertyConfiguration other1 = other as LengthPropertyConfiguration; bool flag1 = base.IsCompatible(other, inCSpace, out errorMessage); int num1; if (other1 != null) { num1 = this.IsCompatible <bool, LengthPropertyConfiguration>((Expression <Func <LengthPropertyConfiguration, bool?> >)(c => c.IsFixedLength), other1, ref errorMessage) ? 1 : 0; } else { num1 = 1; } bool flag2 = num1 != 0; int num2; if (other1 != null) { num2 = this.IsCompatible <bool, LengthPropertyConfiguration>((Expression <Func <LengthPropertyConfiguration, bool?> >)(c => c.IsMaxLength), other1, ref errorMessage) ? 1 : 0; } else { num2 = 1; } bool flag3 = num2 != 0; int num3; if (other1 != null) { num3 = this.IsCompatible <int, LengthPropertyConfiguration>((Expression <Func <LengthPropertyConfiguration, int?> >)(c => c.MaxLength), other1, ref errorMessage) ? 1 : 0; } else { num3 = 1; } bool flag4 = num3 != 0; if (flag1 && flag2 && flag3) { return(flag4); } return(false); }
internal override void MakeCompatibleWith(PrimitivePropertyConfiguration other, bool inCSpace) { DebugCheck.NotNull(other); base.MakeCompatibleWith(other, inCSpace); var dateTimePropertyConfiguration = other as DateTimePropertyConfiguration; if (dateTimePropertyConfiguration == null) { return; } if (dateTimePropertyConfiguration.Precision != null) { Precision = null; } }