public void HasKey_throws_when_not_exists() { var type = new MockType(); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); Assert.Equal( Strings.NoSuchProperty("Property2", "T"), Assert.Throws <InvalidOperationException>(() => config.HasKey("Property2")).Message); }
public void HasKey_composite_throws_when_not_exists() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); Assert.Equal( Strings.NoSuchProperty("DoesNotExist1", "AType"), Assert.Throws <InvalidOperationException>(() => config.HasKey(new[] { "DoesNotExist1", "DoesNotExist2" })).Message); }
public void HasKey_configures_with_private_property() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey("Property1").HasKey("Property3"); Assert.Equal(new[] { "Property1", "Property3" }, innerConfig.KeyProperties.Select(p => p.Name)); Assert.Same(config, result); }
public void HasKey_evaluates_preconditions() { var type = typeof(LocalEntityType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration <object>(type, () => innerConfig, new ModelConfiguration()); var ex = Assert.Throws <ArgumentNullException>( () => config.HasKey <object>(null)); Assert.Equal("keyExpression", ex.ParamName); }
public void HasKey_evaluates_preconditions() { var type = new MockType(); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var ex = Assert.Throws <ArgumentException>( () => config.HasKey((string)null)); Assert.Equal(Strings.ArgumentIsNullOrWhitespace("propertyName"), ex.Message); }
public void HasKey_PropertyInfo_configures_when_unset() { var innerConfig = new EntityTypeConfiguration(typeof(AType2)); var config = new ConventionTypeConfiguration(typeof(AType2), () => innerConfig, new ModelConfiguration()); var result = config.HasKey(config.ClrType.GetRuntimeProperties().First(p => p.IsPublic())) .HasKey(config.ClrType.GetRuntimeProperties().Last(p => p.IsPublic())); Assert.Equal(new[] { "Property1", "Property2" }, innerConfig.KeyProperties.Select(p => p.Name)); Assert.Same(config, result); }
public void HasKey_configures_when_unset() { var type = typeof(LocalEntityType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration <LocalEntityType>(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey(e => e.Property1); Assert.Equal(1, innerConfig.KeyProperties.Count()); Assert.True(innerConfig.KeyProperties.Any(p => p.Name == "Property1")); Assert.Same(config, result); }
public void HasKey_composite_configures_with_private_property_when_unset() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey(new[] { "Property1", "Property3" }); Assert.Equal(2, innerConfig.KeyProperties.Count()); Assert.True(innerConfig.KeyProperties.Any(p => p.Name == "Property1")); Assert.True(innerConfig.KeyProperties.Any(p => p.Name == "Property3")); Assert.Same(config, result); }
public void HasKey_configures_when_unset() { var type = new MockType() .Property <int>("Property1") .Property <int>("Property2"); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey("Property1").HasKey("Property2"); Assert.Equal(new[] { "Property1", "Property2" }, innerConfig.KeyProperties.Select(p => p.Name)); Assert.Same(config, result); }
public void HasKey_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("Property2"); Assert.Equal(1, innerConfig.KeyProperties.Count()); Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property2")); Assert.Same(config, result); }
public void HasKey_composite_is_noop_when_called_twice() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey(new[] { "Property1" }) .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 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 ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); 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_configures_with_private_property_when_unset() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey(new[] { "Property1", "Property3" }); Assert.Equal(2, innerConfig.KeyProperties.Count()); Assert.True(innerConfig.KeyProperties.Any(p => p.Name == "Property1")); Assert.True(innerConfig.KeyProperties.Any(p => p.Name == "Property3")); Assert.Same(config, result); }
public void HasKey_composite_evaluates_preconditions() { var type = new MockType(); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var ex = Assert.Throws<ArgumentNullException>( () => config.HasKey((string[])null)); Assert.Equal("propertyNames", ex.ParamName); Assert.Equal( Strings.CollectionEmpty("keyProperties", "HasKey"), Assert.Throws<ArgumentException>( () => config.HasKey(Enumerable.Empty<string>())).Message); }
public void HasKey_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("Property2"); Assert.Equal(1, innerConfig.KeyProperties.Count()); Assert.False(innerConfig.KeyProperties.Any(p => p.Name == "Property2")); Assert.Same(config, result); }
public void HasKey_PropertyInfo_configures_when_unset() { var innerConfig = new EntityTypeConfiguration(typeof(AType2)); var config = new ConventionTypeConfiguration(typeof(AType2), () => innerConfig, new ModelConfiguration()); var result = config.HasKey(config.ClrType.GetRuntimeProperties().First(p => p.IsPublic())) .HasKey(config.ClrType.GetRuntimeProperties().Last(p => p.IsPublic())); Assert.Equal(new[] { "Property1", "Property2" }, innerConfig.KeyProperties.Select(p => p.Name)); Assert.Same(config, result); }
public void HasKey_configures_with_private_property() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey("Property1").HasKey("Property3"); Assert.Equal(new[] { "Property1", "Property3" }, innerConfig.KeyProperties.Select(p => p.Name)); Assert.Same(config, result); }
public void HasKey_evaluates_preconditions() { var type = new MockType(); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var ex = Assert.Throws<ArgumentException>( () => config.HasKey((string)null)); Assert.Equal(Strings.ArgumentIsNullOrWhitespace("propertyName"), ex.Message); }
public void HasKey_PropertyInfo_configures_when_unset() { var type = new MockType() .Property<int>("Property1") .Property<int>("Property2"); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey(config.ClrType.GetProperties().First()) .HasKey(config.ClrType.GetProperties().Last()); Assert.Equal(new[] { "Property1", "Property2" }, innerConfig.KeyProperties.Select(p => p.Name)); Assert.Same(config, result); }
public void HasKey_throws_when_not_exists() { var type = new MockType(); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); Assert.Equal( Strings.NoSuchProperty("Property2", "T"), Assert.Throws<InvalidOperationException>(() => config.HasKey("Property2")).Message); }
public void HasKey_composite_configures_when_unset() { var type = typeof(LocalEntityType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration<LocalEntityType>(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey( e => new { e.Property1, e.Property2 }); Assert.Equal(2, innerConfig.KeyProperties.Count()); Assert.True(innerConfig.KeyProperties.Any(p => p.Name == "Property1")); Assert.True(innerConfig.KeyProperties.Any(p => p.Name == "Property2")); Assert.Same(config, result); }
public void HasKey_composite_is_noop_when_called_twice() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasKey(new[] { "Property1" }) .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 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 ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); 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_throws_when_not_exists() { var type = typeof(AType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); Assert.Equal( Strings.NoSuchProperty("DoesNotExist1", "AType"), Assert.Throws<InvalidOperationException>(() => config.HasKey(new[] { "DoesNotExist1", "DoesNotExist2" })).Message); }
public void HasKey_evaluates_preconditions() { var type = typeof(LocalEntityType); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration<object>(type, () => innerConfig, new ModelConfiguration()); var ex = Assert.Throws<ArgumentNullException>( () => config.HasKey<object>(null)); Assert.Equal("keyExpression", ex.ParamName); }