Exemplo n.º 1
0
        public void Cloning_an_entity_configuration_clones_its_mapping_information()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            configuration.ToTable("Table");

            var clone = configuration.Clone();

            Assert.Equal("Table", clone.GetTableName().Name);

            configuration.ToTable("AnotherTable");

            Assert.Equal("Table", clone.GetTableName().Name);
        }
Exemplo n.º 2
0
        public void Cloning_an_entity_configuration_clones_its_subtype_mapping_information()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            var mappingConfiguration = new EntityMappingConfiguration();

            configuration.AddSubTypeMappingConfiguration(typeof(object), mappingConfiguration);

            var clone = configuration.Clone();

            Assert.NotSame(configuration.SubTypeMappingConfigurations, clone.SubTypeMappingConfigurations);
            Assert.True(clone.SubTypeMappingConfigurations.ContainsKey(typeof(object)));
            Assert.NotSame(mappingConfiguration, clone.SubTypeMappingConfigurations[typeof(object)]);

            configuration.AddSubTypeMappingConfiguration(typeof(int), new EntityMappingConfiguration());
            Assert.False(clone.SubTypeMappingConfigurations.ContainsKey(typeof(int)));
        }
Exemplo n.º 3
0
        public void Cloning_an_entity_configuration_clones_its_scalar_properties()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            configuration.IsReplaceable = true;
            configuration.ToTable("Table");
            configuration.IsExplicitEntity = true;
            configuration.EntitySetName    = "ESN";

            var clone = configuration.Clone();

            Assert.True(clone.IsReplaceable);
            Assert.True(clone.IsTableNameConfigured);
            Assert.True(clone.IsExplicitEntity);
            Assert.Equal("ESN", clone.EntitySetName);
            Assert.Same(typeof(object), clone.ClrType);
        }
Exemplo n.º 4
0
        public void Cloning_an_entity_configuration_clones_its_ignored_properties()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            var mockProperty1 = new MockPropertyInfo(typeof(int), "P1");

            configuration.Ignore(mockProperty1);

            var clone = configuration.Clone();

            Assert.True(clone.IgnoredProperties.Contains(mockProperty1));

            var mockProperty2 = new MockPropertyInfo(typeof(int), "P2");

            configuration.Ignore(mockProperty2);

            Assert.False(clone.IgnoredProperties.Contains(mockProperty2));
        }
Exemplo n.º 5
0
        public void Cloning_an_entity_configuration_clones_its_primitive_property_information()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            var mockProperty1 = new MockPropertyInfo(typeof(int), "P1");
            var propConfig1   = configuration.Property(new PropertyPath(mockProperty1));

            var clone = configuration.Clone();

            Assert.True(clone.ConfiguredProperties.Contains(mockProperty1));
            Assert.NotSame(propConfig1, clone.Property(new PropertyPath(mockProperty1)));

            var mockProperty2 = new MockPropertyInfo(typeof(int), "P2");

            configuration.Property(new PropertyPath(mockProperty2));

            Assert.False(clone.ConfiguredProperties.Contains(mockProperty2));
        }
Exemplo n.º 6
0
        public void Cloning_an_entity_configuration_clones_its_navigation_property_information()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            var mockNavProp1 = new MockPropertyInfo(typeof(object), "Nav1");
            var navConfig1   = configuration.Navigation(mockNavProp1);

            var clone = configuration.Clone();

            Assert.True(clone.ConfiguredProperties.Contains(mockNavProp1));
            Assert.NotSame(navConfig1, clone.Navigation(mockNavProp1));

            var mockNavProp2 = new MockPropertyInfo(typeof(object), "Nav2");

            configuration.Navigation(mockNavProp2);

            Assert.False(clone.ConfiguredProperties.Contains(mockNavProp2));
        }
Exemplo n.º 7
0
        public void Cloning_an_entity_configuration_clones_its_key_information()
        {
            var configuration = new EntityTypeConfiguration(typeof(object));

            var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1");

            configuration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0;

            var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2");

            configuration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1;

            // This will set _isKeyConfigured to true
            configuration.Key(
                new List <PropertyInfo>
            {
                mockPropertyInfo1
            });

            var clone = configuration.Clone();

            VerifyKeyProperty(clone, "P1", mockPropertyInfo1, mockPropertyInfo2);

            // This should have no effect because _isKeyConfigured is set to true
            clone.Key(mockPropertyInfo2, null);

            VerifyKeyProperty(clone, "P1", mockPropertyInfo1, mockPropertyInfo2);

            // This should change the key on the original, but not on the clone.
            configuration.Key(
                new List <PropertyInfo>
            {
                mockPropertyInfo2
            });

            VerifyKeyProperty(configuration, "P2", mockPropertyInfo1, mockPropertyInfo2);
            VerifyKeyProperty(clone, "P1", mockPropertyInfo1, mockPropertyInfo2);
        }