public void Configure_should_configure_and_order_keys_when_keys_and_order_specified() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2"); entityTypeConfiguration.Key(mockPropertyInfo2); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2")).SetClrPropertyInfo(mockPropertyInfo2); var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1"); entityTypeConfiguration.Key(mockPropertyInfo1); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetClrPropertyInfo(mockPropertyInfo1); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal(2, entityType.KeyProperties.Count); Assert.Equal("P1", entityType.KeyProperties.First().Name); }
public void Key_appends_key_members_when_not_set_by_attributes() { var config = new EntityTypeConfiguration(typeof(AType1)); config.Key(typeof(AType1).GetDeclaredProperty("Key1")); config.Key(typeof(AType1).GetDeclaredProperty("Key2")); Assert.Equal(2, config.KeyProperties.Count()); Assert.Equal("Key1", config.KeyProperties.First().Name); Assert.Equal("Key2", config.KeyProperties.Last().Name); }
public void Key_does_not_append_key_members_once_set_by_attributes() { var type = new MockType() .Property <int>("Key1") .Property <int>("Key2"); var config = new EntityTypeConfiguration(type); config.Key(type.GetProperty("Key1"), null, true); config.Key(type.GetProperty("Key2")); Assert.Equal(1, config.KeyProperties.Count()); Assert.Equal("Key1", config.KeyProperties.Single().Name); }
public void Key_appends_key_members_when_not_set_by_attributes() { var type = new MockType() .Property <int>("Key1") .Property <int>("Key2"); var config = new EntityTypeConfiguration(type); config.Key(type.GetProperty("Key1")); config.Key(type.GetProperty("Key2")); Assert.Equal(2, config.KeyProperties.Count()); Assert.Equal("Key1", config.KeyProperties.First().Name); Assert.Equal("Key2", config.KeyProperties.Last().Name); }
public void Configure_should_throw_when_key_property_not_found() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo = new MockPropertyInfo(typeof(int), "Id"); entityTypeConfiguration.Key(mockPropertyInfo); Assert.Equal( Strings.KeyPropertyNotFound(("Id"), "E"), Assert.Throws <InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void HasKey_is_noop_when_set() { var type = new MockType() .Property <int>("Property1") .Property <int>("Property2"); var innerConfig = new EntityTypeConfiguration(type); innerConfig.Key(new[] { type.GetProperty("Property1") }); var config = new LightweightEntityConfiguration(type, () => innerConfig); var result = config.HasKey("Property2"); Assert.Equal(1, innerConfig.KeyProperties.Count()); Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property2")); Assert.Same(config, result); }
public void Configure_should_throw_when_key_properties_and_not_root_type() { var entityType = new EntityType("E", "N", DataSpace.CSpace) { BaseType = new EntityType("E", "N", DataSpace.CSpace) }; var type = typeof(string); entityType.BaseType.GetMetadataProperties().SetClrType(type); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.Key(new MockPropertyInfo(typeof(int), "Id")); Assert.Equal( Strings.KeyRegisteredOnDerivedType(typeof(object), typeof(string)), Assert.Throws <InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void HasKey_composite_is_noop_when_set() { var type = new MockType() .Property<int>("Property1") .Property<int>("Property2") .Property<int>("Property3"); var innerConfig = new EntityTypeConfiguration(type); innerConfig.Key(new[] { type.GetProperty("Property1") }); var config = new LightweightEntityConfiguration(type, () => innerConfig); var result = config.HasKey(new[] { "Property2", "Property3" }); Assert.Equal(1, innerConfig.KeyProperties.Count()); Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property2")); Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property3")); Assert.Same(config, result); }
public void HasKey_composite_is_noop_when_set() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); innerConfig.Key(new[] { type.GetDeclaredProperty("Property1") }); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey(new[] { "Property2", "Property4" }); Assert.Equal(1, innerConfig.KeyProperties.Count()); Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property2")); Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property4")); Assert.Same(config, result); }
public void Key_appends_key_members_when_not_set_by_attributes() { var config = new EntityTypeConfiguration(typeof(AType1)); config.Key(typeof(AType1).GetDeclaredProperty("Key1")); config.Key(typeof(AType1).GetDeclaredProperty("Key2")); Assert.Equal(2, config.KeyProperties.Count()); Assert.Equal("Key1", config.KeyProperties.First().Name); Assert.Equal("Key2", config.KeyProperties.Last().Name); }
public void Key_does_not_append_key_members_once_set_by_attributes() { var type = new MockType() .Property<int>("Key1") .Property<int>("Key2"); var config = new EntityTypeConfiguration(type); config.Key(type.GetProperty("Key1"), null, true); config.Key(type.GetProperty("Key2")); Assert.Equal(1, config.KeyProperties.Count()); Assert.Equal("Key1", config.KeyProperties.Single().Name); }
public void Configure_should_throw_when_key_properties_and_not_root_type() { var entityType = new EntityType("E", "N", DataSpace.CSpace) { BaseType = new EntityType("E", "N", DataSpace.CSpace) }; var type = typeof(string); entityType.BaseType.GetMetadataProperties().SetClrType(type); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.Key(new MockPropertyInfo(typeof(int), "Id")); Assert.Equal( Strings.KeyRegisteredOnDerivedType(typeof(object), typeof(string)), Assert.Throws<InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Configure_should_configure_and_order_keys_when_keys_and_order_specified() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2"); entityTypeConfiguration.Key(mockPropertyInfo2); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2")).SetClrPropertyInfo(mockPropertyInfo2); var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1"); entityTypeConfiguration.Key(mockPropertyInfo1); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetClrPropertyInfo(mockPropertyInfo1); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal(2, entityType.KeyProperties.Count); Assert.Equal("P1", entityType.KeyProperties.First().Name); }
public void IsKey_is_noop_when_set() { var typeConfig = new EntityTypeConfiguration(typeof(AType2)); typeConfig.Key(new[] { typeof(AType2).GetDeclaredProperty("Property1") }); var innerConfig = new Properties.Primitive.PrimitivePropertyConfiguration { TypeConfiguration = typeConfig }; var propertyInfo = typeof(AType2).GetDeclaredProperty("Property2"); var config = new ConventionPrimitivePropertyConfiguration(propertyInfo, () => innerConfig); var result = config.IsKey(); Assert.DoesNotContain(propertyInfo, typeConfig.KeyProperties); Assert.Same(config, result); }
public void IsKey_is_noop_when_set() { var type = new MockType() .Property<int>("Property1") .Property<int>("Property2"); var typeConfig = new EntityTypeConfiguration(type); typeConfig.Key(new[] { type.GetProperty("Property1") }); var innerConfig = new PrimitivePropertyConfiguration { TypeConfiguration = typeConfig }; var propertyInfo = type.GetProperty("Property2"); var config = new LightweightPropertyConfiguration(propertyInfo, () => innerConfig); var result = config.IsKey(); Assert.DoesNotContain(propertyInfo, typeConfig.KeyProperties); Assert.Same(config, result); }
public void Configure_should_throw_when_key_property_not_found() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo = new MockPropertyInfo(typeof(int), "Id"); entityTypeConfiguration.Key(mockPropertyInfo); Assert.Equal( Strings.KeyPropertyNotFound(("Id"), "E"), Assert.Throws<InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Key_appends_key_members_when_not_set_by_attributes() { var type = new MockType() .Property<int>("Key1") .Property<int>("Key2"); var config = new EntityTypeConfiguration(type); config.Key(type.GetProperty("Key1")); config.Key(type.GetProperty("Key2")); Assert.Equal(2, config.KeyProperties.Count()); Assert.Equal("Key1", config.KeyProperties.First().Name); Assert.Equal("Key2", config.KeyProperties.Last().Name); }