public void Property_returns_same_instance_for_property_names()
        {
            var entityType    = new Model().AddEntityType(typeof(Order));
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            var propertyBuilder = entityBuilder.Property(typeof(Order), Order.IdProperty.Name, ConfigurationSource.DataAnnotation);

            Assert.NotNull(propertyBuilder);
            Assert.Same(propertyBuilder, entityBuilder.Property(Order.IdProperty, ConfigurationSource.DataAnnotation));
        }
        public void Cannot_ignore_same_or_higher_source_property()
        {
            var entityType    = new Model().AddEntityType(typeof(Order));
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            Assert.True(entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.Convention));
            Assert.NotNull(entityBuilder.Property(typeof(Order), Order.IdProperty.Name, ConfigurationSource.Convention));
            Assert.NotNull(entityBuilder.Property(typeof(Order), Order.IdProperty.Name, ConfigurationSource.DataAnnotation));

            Assert.False(entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.Convention));
            Assert.False(entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.DataAnnotation));

            Assert.NotNull(entityType.TryGetProperty(Order.IdProperty.Name));
        }
        public void Can_ignore_same_or_lower_source_property()
        {
            var entityType    = new Model().AddEntityType(typeof(Order));
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            Assert.True(entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.Explicit));

            Assert.Null(entityType.TryGetProperty(Order.IdProperty.Name));
            Assert.True(entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.Explicit));
            Assert.Null(entityBuilder.Property(typeof(Order), Order.IdProperty.Name, ConfigurationSource.DataAnnotation));

            Assert.Equal(Strings.PropertyIgnoredExplicitly(Order.IdProperty.Name, typeof(Order).FullName),
                         Assert.Throws <InvalidOperationException>(() =>
                                                                   Assert.NotNull(entityBuilder.Property(typeof(Order), Order.IdProperty.Name, ConfigurationSource.Explicit))).Message);
        }
        public void Cannot_ignore_existing_property()
        {
            var entityType    = new Model().AddEntityType(typeof(Order));
            var property      = entityType.AddProperty(Order.IdProperty.Name, typeof(int));
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            Assert.Same(property, entityBuilder.Property(typeof(Order), Order.IdProperty.Name, ConfigurationSource.Convention).Metadata);

            Assert.False(entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.DataAnnotation));

            Assert.Same(property, entityBuilder.Property(typeof(Order), Order.IdProperty.Name, ConfigurationSource.Convention).Metadata);
            Assert.False(entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.DataAnnotation));
            Assert.NotNull(entityType.TryGetProperty(Order.IdProperty.Name));

            Assert.Equal(Strings.PropertyAddedExplicitly(Order.IdProperty.Name, typeof(Order).FullName),
                         Assert.Throws <InvalidOperationException>(() =>
                                                                   entityBuilder.Ignore(Order.IdProperty.Name, ConfigurationSource.Explicit)).Message);
        }
        public void Key_works_for_property_names_for_shadow_entity_type()
        {
            var entityType    = new Model().AddEntityType(typeof(Order).Name);
            var entityBuilder = new InternalEntityBuilder(entityType, new InternalModelBuilder(new Model(), null));

            entityBuilder.Property(Order.CustomerIdProperty.PropertyType, Order.CustomerIdProperty.Name, ConfigurationSource.Convention);

            Assert.NotNull(entityBuilder.Key(new[] { Order.CustomerIdProperty.Name }, ConfigurationSource.Convention));

            Assert.Equal(Order.CustomerIdProperty.Name, entityType.GetPrimaryKey().Properties.Single().Name);
        }