public void CloneWithDefiningQuery_does_not_creat_schema_and_table_extended_attributes_if_they_are_null()
        {
            var property =
                EdmProperty.CreatePrimitive(
                    "Id",
                    ProviderManifest.GetStoreTypes().Single(t => t.PrimitiveTypeKind == PrimitiveTypeKind.Int32));

            var customMetadataProperty =
                MetadataProperty.Create(
                    "http://tempUri:myProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            var entityType =
                EntityType.Create("EntityType", "MyModel", DataSpace.SSpace, new[] { "Id" }, new[] { property }, null);

            var entitySet = EntitySet.Create("EntityTypeSet", null, null, null, entityType, new[] { customMetadataProperty });

            var clonedEntitySet = EntitySetDefiningQueryConverter.CloneWithDefiningQuery(entitySet, "definingQuery");

            Assert.Null(clonedEntitySet.Schema);
            Assert.Null(clonedEntitySet.Table);
            Assert.False(entitySet.MetadataProperties.Any(p => p.Name.EndsWith(StoreSchemaAttributeNamespace + ":Schema")));
            Assert.False(entitySet.MetadataProperties.Any(p => p.Name.EndsWith(StoreSchemaAttributeNamespace + ":Name")));
        }
        public void CloneWithDefiningQuery_creates_new_equivalent_entity_set_but_with_defining_query()
        {
            var property =
                EdmProperty.CreatePrimitive(
                    "Id",
                    ProviderManifest.GetStoreTypes().Single(t => t.PrimitiveTypeKind == PrimitiveTypeKind.Int32));

            var customMetadataProperty =
                MetadataProperty.Create(
                    "http://tempUri:myProperty",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    "value");

            var entityType =
                EntityType.Create("EntityType", "MyModel", DataSpace.SSpace, new[] { "Id" }, new[] { property }, null);

            var entitySet = EntitySet.Create("EntityTypeSet", "dbo", "EntityTypes", null, entityType, new[] { customMetadataProperty });

            var clonedEntitySet = EntitySetDefiningQueryConverter.CloneWithDefiningQuery(entitySet, "definingQuery");

            Assert.NotNull(clonedEntitySet);
            Assert.NotSame(clonedEntitySet, entitySet);
            Assert.Same(entitySet.Name, clonedEntitySet.Name);
            Assert.Same(entitySet.ElementType, clonedEntitySet.ElementType);
            Assert.Null(clonedEntitySet.Schema);
            Assert.Null(clonedEntitySet.Table);
            Assert.Equal(
                entitySet.Schema,
                clonedEntitySet.MetadataProperties.Single(p => p.Name == StoreSchemaAttributeNamespace + ":Schema")
                .Value);
            Assert.Equal(
                entitySet.Table,
                clonedEntitySet.MetadataProperties.Single(p => p.Name == StoreSchemaAttributeNamespace + ":Name")
                .Value);

            Assert.Equal(
                entitySet.MetadataProperties.Single(p => p.Name == "http://tempUri:myProperty").Value,
                clonedEntitySet.MetadataProperties.Single(p => p.Name == "http://tempUri:myProperty").Value);
        }