public void ClrType_returns_type()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            Assert.Same(type.Object, config.ClrType);
        }
        public void Ignore_is_noop_when_not_exists()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            config.Ignore("Property1");

            Assert.Empty(innerConfig.IgnoredProperties);
        }
        public void Property_returns_MissingPropertyConfiguration_when_not_exists()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

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

            Assert.IsType <MissingPropertyConfiguration>(result);
        }
        public void ToTable_configures_when_unset()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            config.ToTable("Table1");

            Assert.Equal("Table1", innerConfig.TableName);
        }
        public void MapToStoredProcedures_with_no_args_should_add_configuration()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            config.MapToStoredProcedures();

            Assert.True(innerConfig.IsMappedToFunctions);
        }
        public void Ignore_configures()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration<LocalEntityType>(type, () => innerConfig);

            config.Ignore(t => t.Property1);

            Assert.Equal(1, innerConfig.IgnoredProperties.Count());
            Assert.True(innerConfig.IgnoredProperties.Any(p => p.Name == "Property1"));
        }
コード例 #7
0
        public void HasKey_evaluates_preconditions()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration <object>(type, () => innerConfig);

            var ex = Assert.Throws <ArgumentNullException>(
                () => config.HasKey <object>(null));

            Assert.Equal("keyExpression", ex.ParamName);
        }
コード例 #8
0
        public void Ignore_configures()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration <LocalEntityType>(type, () => innerConfig);

            config.Ignore(t => t.Property1);

            Assert.Equal(1, innerConfig.IgnoredProperties.Count());
            Assert.True(innerConfig.IgnoredProperties.Any(p => p.Name == "Property1"));
        }
        public void Property_evaluates_preconditions()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration<object>(type, () => innerConfig);

            var ex = Assert.Throws<ArgumentNullException>(
                () => config.Property<object>(null));

            Assert.Equal("propertyExpression", ex.ParamName);
        }
コード例 #10
0
        public void HasKey_composite_evaluates_preconditions()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            var ex = Assert.Throws <ArgumentNullException>(
                () => config.HasKey((string[])null));

            Assert.Equal("propertyNames", ex.ParamName);
        }
コード例 #11
0
        public void HasEntitySetName_configures_when_unset()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasEntitySetName("EntitySet1");

            Assert.Equal("EntitySet1", innerConfig.EntitySetName);
            Assert.Same(config, result);
        }
コード例 #12
0
        public void ToTable_with_schema_evaluates_preconditions()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            var ex = Assert.Throws <ArgumentException>(
                () => config.ToTable(null, null));

            Assert.Equal(Strings.ArgumentIsNullOrWhitespace("tableName"), ex.Message);
        }
コード例 #13
0
        public void Ignore_evaluates_preconditions()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            var ex = Assert.Throws <ArgumentException>(
                () => config.Ignore((string)null));

            Assert.Equal(Strings.ArgumentIsNullOrWhitespace("propertyName"), ex.Message);
        }
コード例 #14
0
        public void ToTable_handles_dot()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            config.ToTable("Schema1.Table1");

            Assert.Equal("Schema1", innerConfig.SchemaName);
            Assert.Equal("Table1", innerConfig.TableName);
        }
コード例 #15
0
        public void HasEntitySetName_evaluates_preconditions()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var ex = Assert.Throws<ArgumentException>(
                () => config.HasEntitySetName(null));

            Assert.Equal(Strings.ArgumentIsNullOrWhitespace("entitySetName"), ex.Message);
        }
コード例 #16
0
        public void HasEntitySetName_configures_when_unset()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasEntitySetName("EntitySet1");

            Assert.Equal("EntitySet1", innerConfig.EntitySetName);
            Assert.Same(config, result);
        }
コード例 #17
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="LightweightEntityConfiguration{T}" /> class.
        /// </summary>
        /// <param name="type">
        ///     The <see cref="Type" /> of this entity type.
        /// </param>
        /// <param name="configuration"> The configuration object that this instance wraps. </param>
        internal LightweightEntityConfiguration(Type type, Func <EntityTypeConfiguration> configuration)
        {
            Check.NotNull(type, "type");
            Check.NotNull(configuration, "configuration");

            if (!typeof(T).IsAssignableFrom(type))
            {
                throw Error.LightweightEntityConfiguration_TypeMismatch(type, typeof(T));
            }

            _configuration = new LightweightEntityConfiguration(type, configuration);
        }
コード例 #18
0
        public void HasKey_composite_is_noop_when_not_exists()
        {
            var type = new MockType()
                       .Property <int>("Property1");
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasKey(new[] { "Property1", "Property2" });

            Assert.Empty(innerConfig.KeyProperties);
            Assert.Same(config, result);
        }
コード例 #19
0
        public void Ignore_configures()
        {
            var type = new MockType()
                       .Property <int>("Property1");
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            config.Ignore("Property1");

            Assert.Equal(1, innerConfig.IgnoredProperties.Count());
            Assert.True(innerConfig.IgnoredProperties.Any(p => p.Name == "Property1"));
        }
コード例 #20
0
        public void HasKey_configures_when_unset()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration <LocalEntityType>(type, () => innerConfig);

            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);
        }
コード例 #21
0
        public void ToTable_with_schema_is_noop_when_set()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);

            innerConfig.ToTable("Table1", "Schema1");
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            config.ToTable("Table2", "Schema2");

            Assert.Equal("Table1", innerConfig.TableName);
            Assert.Equal("Schema1", innerConfig.SchemaName);
        }
コード例 #22
0
        public void Property_throws_when_indexer()
        {
            var type        = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

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

            Assert.Equal(
                Strings.LightweightEntityConfiguration_NonScalarProperty("Item"),
                ex.Message);
        }
コード例 #23
0
        public void MapToStoredProcedures_with_action_should_invoke_and_add_configuration()
        {
            var type        = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            LightweightModificationFunctionsConfiguration configuration = null;

            config.MapToStoredProcedures(c => configuration = c);

            Assert.Same(
                configuration.Configuration,
                innerConfig.ModificationFunctionsConfiguration);
        }
コード例 #24
0
        public void Property_throws_when_nonscalar()
        {
            var type = new MockType()
                       .Property <object>("NonScalar");
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

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

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

            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 <DecimalPropertyConfiguration>(result.Configuration());
        }
コード例 #26
0
        public void HasKey_composite_configures_when_unset()
        {
            var type = new MockType()
                       .Property <int>("Property1")
                       .Property <int>("Property2");
            var innerConfig = new EntityTypeConfiguration(type);
            var config      = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasKey(new[] { "Property1", "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 Property_returns_configuration()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration<LocalEntityType>(type, () => innerConfig);

            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<DecimalPropertyConfiguration>(result.Configuration());
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        public void HasKey_composite_configures_when_unset()
        {
            var type = new MockType()
                .Property<int>("Property1")
                .Property<int>("Property2");
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasKey(new[] { "Property1", "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);
        }
コード例 #31
0
        public void HasKey_composite_evaluates_preconditions()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var ex = Assert.Throws<ArgumentNullException>(
                () => config.HasKey((string[])null));

            Assert.Equal("propertyNames", ex.ParamName);
        }
コード例 #32
0
        public void ToTable_with_schema_is_noop_when_set()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            innerConfig.ToTable("Table1", "Schema1");
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            config.ToTable("Table2", "Schema2");

            Assert.Equal("Table1", innerConfig.TableName);
            Assert.Equal("Schema1", innerConfig.SchemaName);
        }
コード例 #33
0
        public void ToTable_handles_dot()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            config.ToTable("Schema1.Table1");

            Assert.Equal("Schema1", innerConfig.SchemaName);
            Assert.Equal("Table1", innerConfig.TableName);
        }
コード例 #34
0
        public void ToTable_configures_when_unset()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            config.ToTable("Table1");

            Assert.Equal("Table1", innerConfig.TableName);
        }
コード例 #35
0
        public void Property_returns_MissingPropertyConfiguration_when_not_exists()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

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

            Assert.IsType<MissingPropertyConfiguration>(result);
        }
コード例 #36
0
        public void Property_throws_when_indexer()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

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

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

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

            Assert.Equal(
                Strings.LightweightEntityConfiguration_NonScalarProperty("NonScalar"),
                ex.Message);
        }
        public void MapToStoredProcedures_with_no_args_should_add_configuration()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration<LocalEntityType>(type, () => innerConfig);

            config.MapToStoredProcedures();

            Assert.True(innerConfig.IsMappedToFunctions);
        }
        public void MapToStoredProcedures_with_action_should_invoke_and_add_configuration()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration<LocalEntityType>(type, () => innerConfig);

            ModificationFunctionsConfiguration<LocalEntityType> configuration = null;

            config.MapToStoredProcedures(c => configuration = c);

            Assert.Same(
                configuration.Configuration,
                innerConfig.ModificationFunctionsConfiguration);
        }
コード例 #40
0
        public void HasKey_composite_is_noop_when_not_exists()
        {
            var type = new MockType()
                .Property<int>("Property1");
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            var result = config.HasKey(new[] { "Property1", "Property2" });

            Assert.Empty(innerConfig.KeyProperties);
            Assert.Same(config, result);
        }
        public void MapToStoredProcedures_configures_when_unset()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            config.MapToStoredProcedures();

            Assert.True(innerConfig.IsMappedToFunctions);
        }
コード例 #42
0
        public void ClrType_returns_type()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            Assert.Same(type.Object, config.ClrType);
        }
コード例 #43
0
        public void Ignore_configures()
        {
            var type = new MockType()
                .Property<int>("Property1");
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            config.Ignore("Property1");

            Assert.Equal(1, innerConfig.IgnoredProperties.Count());
            Assert.True(innerConfig.IgnoredProperties.Any(p => p.Name == "Property1"));
        }
コード例 #44
0
        public void Ignore_is_noop_when_not_exists()
        {
            var type = new MockType();
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration(type, () => innerConfig);

            config.Ignore("Property1");

            Assert.Empty(innerConfig.IgnoredProperties);
        }
        public void HasKey_composite_configures_when_unset()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new EntityTypeConfiguration(type);
            var config = new LightweightEntityConfiguration<LocalEntityType>(type, () => innerConfig);

            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);
        }