public void NavigationProperty_throws_when_property_not_found()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            Assert.Equal(
                Strings.NoSuchProperty("foo", type.Name),
                Assert.Throws <InvalidOperationException>(() => config.NavigationProperty("foo")).Message);

            Assert.Equal(
                "propertyInfo",
                Assert.Throws <ArgumentNullException>(() => config.NavigationProperty((PropertyInfo)null)).ParamName);
        }
Esempio n. 2
0
        public void NavigationProperty_evaluates_preconditions()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration <LocalEntityType>(type, () => innerConfig, new ModelConfiguration());

            Assert.Equal(
                "propertyExpression",
                Assert.Throws <ArgumentNullException>(
                    () => config.NavigationProperty <object>(null)).ParamName);

            Assert.Equal(
                Strings.LightweightEntityConfiguration_InvalidNavigationProperty("Property1"),
                Assert.Throws <InvalidOperationException>(
                    () => config.NavigationProperty(e => e.Property1)).Message);
        }
        public void NavigationProperty_evaluates_preconditions()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("propertyName"),
                Assert.Throws <ArgumentException>(
                    () => config.NavigationProperty((string)null)).Message);

            Assert.Equal(
                Strings.LightweightEntityConfiguration_InvalidNavigationProperty("Property1"),
                Assert.Throws <InvalidOperationException>(
                    () => config.NavigationProperty(type.GetDeclaredProperty("Property1"))).Message);
        }
Esempio n. 4
0
        public void NavigationProperty_returns_configuration()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration <LocalEntityType>(type, () => innerConfig, new ModelConfiguration());

            var result = config.NavigationProperty(e => e.NavigationProperty);

            Assert.NotNull(result);
            Assert.NotNull(result.ClrPropertyInfo);
            Assert.Equal("NavigationProperty", result.ClrPropertyInfo.Name);
            Assert.Equal(typeof(LocalEntityType), result.ClrPropertyInfo.PropertyType);
            Assert.NotNull(result.Configuration);
            Assert.IsType <NavigationPropertyConfiguration>(result.Configuration);
        }
        internal ConventionNavigationPropertyConfiguration NavigationProperty <TProperty>(Expression <Func <T, TProperty> > propertyExpression)
        {
            Check.NotNull(propertyExpression, "propertyExpression");

            return(_configuration.NavigationProperty(propertyExpression.GetComplexPropertyAccess()));
        }
        public void NavigationProperty_throws_when_property_not_found()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            Assert.Equal(
                Strings.NoSuchProperty("foo", type.Name),
                Assert.Throws<InvalidOperationException>(() => config.NavigationProperty("foo")).Message);

            Assert.Equal(
                "propertyInfo",
                Assert.Throws<ArgumentNullException>(() => config.NavigationProperty((PropertyInfo)null)).ParamName);
        }
        public void NavigationProperty_returns_configuration_by_name_for_private_property()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            var result = config.NavigationProperty("PrivateNavigationProperty");

            Assert.NotNull(result);
            Assert.NotNull(result.ClrPropertyInfo);
            Assert.Equal("PrivateNavigationProperty", result.ClrPropertyInfo.Name);
            Assert.Equal(typeof(LocalEntityType), result.ClrPropertyInfo.PropertyType);
            Assert.NotNull(result.Configuration);
            Assert.IsType<NavigationPropertyConfiguration>(result.Configuration);
        }
        public void NavigationProperty_evaluates_preconditions()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            Assert.Equal(
                Strings.ArgumentIsNullOrWhitespace("propertyName"),
                Assert.Throws<ArgumentException>(
                    () => config.NavigationProperty((string)null)).Message);

            Assert.Equal(
                Strings.LightweightEntityConfiguration_InvalidNavigationProperty("Property1"),
                Assert.Throws<InvalidOperationException>(
                    () => config.NavigationProperty(type.GetDeclaredProperty("Property1"))).Message);
        }
        public void NavigationProperty_evaluates_preconditions()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new ConventionTypeConfiguration<LocalEntityType>(type, () => innerConfig, new ModelConfiguration());

            Assert.Equal(
                "propertyExpression",
                Assert.Throws<ArgumentNullException>(
                    () => config.NavigationProperty<object>(null)).ParamName);

            Assert.Equal(
                Strings.LightweightEntityConfiguration_InvalidNavigationProperty("Property1"),
                Assert.Throws<InvalidOperationException>(
                    () => config.NavigationProperty(e => e.Property1)).Message);
        }