コード例 #1
0
        public void Property_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("DoesNotExist", type.Name),
                Assert.Throws <InvalidOperationException>(() => config.Property("DoesNotExist")).Message);

            Assert.Equal(
                "propertyInfo",
                Assert.Throws <ArgumentNullException>(() => config.Property((PropertyInfo)null)).ParamName);
        }
コード例 #2
0
        public void Property_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.Property <object>(null));

            Assert.Equal("propertyExpression", ex.ParamName);
        }
コード例 #3
0
        public void Property_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.Property((string)null));

            Assert.Equal(Strings.ArgumentIsNullOrWhitespace("propertyName"), ex.Message);
        }
        public void Property_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.Property<object>(null));

            Assert.Equal("propertyExpression", ex.ParamName);
        }
コード例 #5
0
        public void Property_throws_when_indexer()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            var ex = Assert.Throws <InvalidOperationException>(
                () => config.Property("Item"));

            Assert.Equal(
                Strings.LightweightEntityConfiguration_NonScalarProperty("Item"),
                ex.Message);
        }
コード例 #6
0
        public void Property_throws_when_nonscalar()
        {
            var type = new MockType()
                       .Property <object>("NonScalar");
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            var ex = Assert.Throws <InvalidOperationException>(
                () => config.Property("NonScalar"));

            Assert.Equal(
                Strings.LightweightEntityConfiguration_NonScalarProperty("NonScalar"),
                ex.Message);
        }
コード例 #7
0
        public void Property_returns_configuration()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration <LocalEntityType>(type, () => innerConfig, new ModelConfiguration());

            var result = config.Property(e => e.Property1);

            Assert.NotNull(result);
            Assert.NotNull(result.ClrPropertyInfo);
            Assert.Equal("Property1", result.ClrPropertyInfo.Name);
            Assert.Equal(typeof(decimal), result.ClrPropertyInfo.PropertyType);
            Assert.NotNull(result.Configuration);
            Assert.IsType <Properties.Primitive.DecimalPropertyConfiguration>(result.Configuration());
        }
コード例 #8
0
        public void Property_returns_configuration_for_complex_type_properties()
        {
            var type        = typeof(AType);
            var innerConfig = new ComplexTypeConfiguration(type);
            var config      = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            config.IsComplexType();
            var result = config.Property("Property5");

            Assert.NotNull(result);
            Assert.NotNull(result.ClrPropertyInfo);
            Assert.Equal("Property5", result.ClrPropertyInfo.Name);
            Assert.Equal(typeof(decimal), result.ClrPropertyInfo.PropertyType);
            Assert.NotNull(result.Configuration);
            Assert.IsType <Properties.Primitive.DecimalPropertyConfiguration>(result.Configuration());
        }
        public ConventionPrimitivePropertyConfiguration Property <TProperty>(Expression <Func <T, TProperty> > propertyExpression)
        {
            Check.NotNull(propertyExpression, "propertyExpression");

            return(_configuration.Property(propertyExpression.GetComplexPropertyAccess()));
        }
コード例 #10
0
        public void Property_returns_configuration_for_complex_type_properties()
        {
            var type = typeof(AType);
            var innerConfig = new ComplexTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            config.IsComplexType();
            var result = config.Property("Property5");

            Assert.NotNull(result);
            Assert.NotNull(result.ClrPropertyInfo);
            Assert.Equal("Property5", result.ClrPropertyInfo.Name);
            Assert.Equal(typeof(decimal), result.ClrPropertyInfo.PropertyType);
            Assert.NotNull(result.Configuration);
            Assert.IsType<Properties.Primitive.DecimalPropertyConfiguration>(result.Configuration());
        }
コード例 #11
0
        public void Property_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("DoesNotExist", type.Name),
                Assert.Throws<InvalidOperationException>(() => config.Property("DoesNotExist")).Message);

            Assert.Equal(
                "propertyInfo",
                Assert.Throws<ArgumentNullException>(() => config.Property((PropertyInfo)null)).ParamName);
        }
コード例 #12
0
        public void Property_throws_when_indexer()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            var ex = Assert.Throws<InvalidOperationException>(
                () => config.Property("Item"));

            Assert.Equal(
                Strings.LightweightEntityConfiguration_NonScalarProperty("Item"),
                ex.Message);
        }
コード例 #13
0
        public void Property_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.Property((string)null));

            Assert.Equal(Strings.ArgumentIsNullOrWhitespace("propertyName"), ex.Message);
        }
コード例 #14
0
        public void Property_returns_configuration()
        {
            var type = new MockType()
                .Property<decimal>("Property1");
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            var result = config.Property("Property1");

            Assert.NotNull(result);
            Assert.NotNull(result.ClrPropertyInfo);
            Assert.Equal("Property1", result.ClrPropertyInfo.Name);
            Assert.Equal(typeof(decimal), result.ClrPropertyInfo.PropertyType);
            Assert.NotNull(result.Configuration);
            Assert.IsType<Properties.Primitive.DecimalPropertyConfiguration>(result.Configuration());
        }
コード例 #15
0
        public void Property_throws_when_nonscalar()
        {
            var type = new MockType()
                .Property<object>("NonScalar");
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration());

            var ex = Assert.Throws<InvalidOperationException>(
                () => config.Property("NonScalar"));

            Assert.Equal(
                Strings.LightweightEntityConfiguration_NonScalarProperty("NonScalar"),
                ex.Message);
        }