public void Can_configure_result_bindings() { var modificationFunctionConfiguration = new ModificationFunctionConfiguration(); var mockPropertyInfo = new MockPropertyInfo(); modificationFunctionConfiguration .Result(new PropertyPath(mockPropertyInfo), "Foo"); var entitySet = new EntitySet(); entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace)); var property = new EdmProperty("P1"); property.SetClrPropertyInfo(mockPropertyInfo); var resultBinding = new StorageModificationFunctionResultBinding("Bar", property); modificationFunctionConfiguration.Configure( new StorageModificationFunctionMapping( entitySet, new EntityType("E", "N", DataSpace.CSpace), new EdmFunction("F", "N", DataSpace.SSpace), new[] { new StorageModificationFunctionParameterBinding( new FunctionParameter( "P", TypeUsage.Create( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In), new StorageModificationFunctionMemberPath(new[] { property }, null), false) }, null, new[] { resultBinding }), ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal("Foo", resultBinding.ColumnName); }
private EdmProperty MapPrimitiveOrComplexOrEnumProperty( PropertyInfo propertyInfo, Func <StructuralTypeConfiguration> structuralTypeConfiguration, bool discoverComplexTypes = false) { EdmProperty property = propertyInfo.AsEdmPrimitiveProperty(); if (property == null) { Type underlyingType = propertyInfo.PropertyType; ComplexType complexType = this._typeMapper.MapComplexType(underlyingType, discoverComplexTypes); if (complexType != null) { property = EdmProperty.CreateComplex(propertyInfo.Name, complexType); } else { bool flag = underlyingType.TryUnwrapNullableType(out underlyingType); if (underlyingType.IsEnum()) { EnumType enumType = this._typeMapper.MapEnumType(underlyingType); if (enumType != null) { property = EdmProperty.CreateEnum(propertyInfo.Name, enumType); property.Nullable = flag; } } } } if (property != null) { property.SetClrPropertyInfo(propertyInfo); new AttributeMapper(this._typeMapper.MappingContext.AttributeProvider).Map(propertyInfo, (ICollection <MetadataProperty>)property.GetMetadataProperties()); if (!property.IsComplexType) { this._typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(propertyInfo, (Func <PropertyConfiguration>)(() => (PropertyConfiguration)structuralTypeConfiguration().Property(new PropertyPath(propertyInfo), new OverridableConfigurationParts?())), this._typeMapper.MappingContext.ModelConfiguration); } } return(property); }
public void Can_configure_rows_affected_parameter_name() { var modificationFunctionConfiguration = new ModificationStoredProcedureConfiguration(); var mockPropertyInfo = new MockPropertyInfo(); modificationFunctionConfiguration.RowsAffectedParameter("Foo"); var entitySet = new EntitySet(); entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace)); var property = new EdmProperty("P1"); property.SetClrPropertyInfo(mockPropertyInfo); var rowsAffectedParameter = new FunctionParameter(); modificationFunctionConfiguration.Configure( new ModificationFunctionMapping( entitySet, new EntityType("E", "N", DataSpace.CSpace), new EdmFunction("F", "N", DataSpace.SSpace), new[] { new ModificationFunctionParameterBinding( new FunctionParameter( "P", TypeUsage.Create( PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In), new ModificationFunctionMemberPath(new[] { property }, null), false) }, rowsAffectedParameter, null), ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal("Foo", rowsAffectedParameter.Name); }
public void Configure_should_ensure_consistency_of_constraint_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("SE", "N", DataSpace.CSpace)); var targetEntityType = new EntityType("TE", "N", DataSpace.CSpace); var propertyInfo = new MockPropertyInfo(typeof(int), "P2").Object; var property = new EdmProperty("P2", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))); targetEntityType.AddMember(property); property.SetClrPropertyInfo(propertyInfo); associationType.TargetEnd = new AssociationEndMember("T", targetEntityType); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N1")); associationType.SetConfiguration(navigationPropertyConfigurationA); var constraint = new ForeignKeyConstraintConfiguration( new[] { propertyInfo }); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2")) { Constraint = constraint }; navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object))); Assert.Equal(constraint, navigationPropertyConfigurationA.Constraint); }
public void Configure_should_throw_when_original_value_parameter_binding_not_found() { var modificationFunctionConfiguration = new ModificationFunctionConfiguration(); var mockPropertyInfo = new MockPropertyInfo(); modificationFunctionConfiguration .Parameter(new PropertyPath(mockPropertyInfo), "P0", "P1"); var entitySet = new EntitySet(); entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace)); var property = new EdmProperty("P0"); property.SetClrPropertyInfo(mockPropertyInfo); Assert.Equal( Strings.ModificationFunctionParameterNotFoundOriginal("P", "F"), Assert.Throws <InvalidOperationException>( () => modificationFunctionConfiguration.Configure( new StorageModificationFunctionMapping( entitySet, new EntityType("E", "N", DataSpace.CSpace), new EdmFunction("F", "N", DataSpace.SSpace), new[] { new StorageModificationFunctionParameterBinding( new FunctionParameter(), new StorageModificationFunctionMemberPath( new[] { property }, null), true) }, null, null), ProviderRegistry.Sql2008_ProviderManifest)).Message); }
public void Can_configure_ia_fk_parameters() { var modificationFunctionConfiguration = new ModificationFunctionConfiguration(); var mockPropertyInfo1 = new MockPropertyInfo(); var mockPropertyInfo2 = new MockPropertyInfo(); modificationFunctionConfiguration .Parameter(new PropertyPath(new[] { mockPropertyInfo1.Object, mockPropertyInfo2.Object }), "Foo"); var entitySet = new EntitySet(); entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace)); var property1 = new EdmProperty("P1"); property1.SetClrPropertyInfo(mockPropertyInfo1); var function = new EdmFunction("F", "N", DataSpace.SSpace); var functionParameter1 = new FunctionParameter(); var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); var associationEndMember1 = new AssociationEndMember("AE1", new EntityType("E", "N", DataSpace.CSpace)) { RelationshipMultiplicity = RelationshipMultiplicity.Many }; var associationEndMember2 = new AssociationEndMember("AE2", new EntityType("E", "N", DataSpace.CSpace)) { RelationshipMultiplicity = RelationshipMultiplicity.One }; associationEndMember2.SetClrPropertyInfo(mockPropertyInfo1); associationType.SourceEnd = associationEndMember1; associationType.TargetEnd = associationEndMember2; var associationSet = new AssociationSet("AS", associationType); associationSet.AddAssociationSetEnd( new AssociationSetEnd(entitySet, associationSet, associationEndMember2)); modificationFunctionConfiguration.Configure( new StorageModificationFunctionMapping( entitySet, new EntityType("E", "N", DataSpace.CSpace), function, new[] { new StorageModificationFunctionParameterBinding( functionParameter1, new StorageModificationFunctionMemberPath( new EdmMember[] { property1, associationEndMember2 }, associationSet), false) }, null, null), ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal("Foo", functionParameter1.Name); }
public void Can_configure_function_name_and_parameters() { var modificationFunctionConfiguration = new ModificationFunctionConfiguration(); modificationFunctionConfiguration.HasName("Foo", "Bar"); var mockPropertyInfo1 = new MockPropertyInfo(); var mockPropertyInfo2 = new MockPropertyInfo(); modificationFunctionConfiguration .Parameter(new PropertyPath(mockPropertyInfo1), "Foo"); modificationFunctionConfiguration .Parameter(new PropertyPath(new[] { mockPropertyInfo1.Object, mockPropertyInfo2.Object }), "Bar"); var entitySet = new EntitySet(); entitySet.ChangeEntityContainerWithoutCollectionFixup(new EntityContainer("C", DataSpace.CSpace)); var property1 = new EdmProperty("P1"); property1.SetClrPropertyInfo(mockPropertyInfo1); var property2 = new EdmProperty("P1"); property2.SetClrPropertyInfo(mockPropertyInfo2); var functionParameter1 = new FunctionParameter( "P1", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In); var functionParameter2 = new FunctionParameter( "P2", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In); var functionParameter3 = new FunctionParameter( "Foo", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In); var function = new EdmFunction( "F", "N", DataSpace.SSpace, new EdmFunctionPayload { Parameters = new[] { functionParameter1, functionParameter2, functionParameter3 } }); var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); var associationEndMember1 = new AssociationEndMember("AE1", new EntityType("E", "N", DataSpace.CSpace)) { RelationshipMultiplicity = RelationshipMultiplicity.Many }; var associationEndMember2 = new AssociationEndMember("AE2", new EntityType("E", "N", DataSpace.CSpace)) { RelationshipMultiplicity = RelationshipMultiplicity.Many }; associationType.SourceEnd = associationEndMember1; associationType.TargetEnd = associationEndMember2; var associationSet = new AssociationSet("AS", associationType); associationSet.AddAssociationSetEnd( new AssociationSetEnd(entitySet, associationSet, associationEndMember2)); modificationFunctionConfiguration.Configure( new StorageModificationFunctionMapping( entitySet, new EntityType("E", "N", DataSpace.CSpace), function, new[] { new StorageModificationFunctionParameterBinding( functionParameter1, new StorageModificationFunctionMemberPath( new EdmMember[] { property1, associationEndMember2 }, associationSet), false), new StorageModificationFunctionParameterBinding( functionParameter2, new StorageModificationFunctionMemberPath( new[] { property1, property2 }, null), false) }, null, null), ProviderRegistry.Sql2008_ProviderManifest); Assert.Equal("Foo", function.StoreFunctionNameAttribute); Assert.Equal("Bar", function.Schema); Assert.Equal("Foo", functionParameter1.Name); Assert.Equal("Bar", functionParameter2.Name); Assert.Equal("Foo1", functionParameter3.Name); }