public void Configure_should_uniquify_unconfigured_assocation_function_names() { var typeA = new MockType("A"); var typeB = new MockType("B").Property(typeA.AsCollection(), "As"); var mockPropertyInfo = typeB.GetProperty("As"); typeA.Property(typeB.AsCollection(), "Bs"); var modelConfiguration = new ModelConfiguration(); var navigationPropertyConfiguration = modelConfiguration.Entity(typeB).Navigation(mockPropertyInfo); navigationPropertyConfiguration.ModificationFunctionsConfiguration = new ModificationFunctionsConfiguration(); var modificationFunctionConfiguration = new ModificationFunctionConfiguration(); modificationFunctionConfiguration.HasName("M2M_Delete"); navigationPropertyConfiguration.ModificationFunctionsConfiguration .Insert(modificationFunctionConfiguration); var model = new EdmModel(DataSpace.CSpace); var entityA = model.AddEntityType("A"); entityA.Annotations.SetClrType(typeA); entityA.SetConfiguration(modelConfiguration.Entity(typeA)); var entityB = model.AddEntityType("B"); entityB.Annotations.SetClrType(typeB); entityB.SetConfiguration(modelConfiguration.Entity(typeB)); model.AddEntitySet("AS", entityA); model.AddEntitySet("BS", entityB); var associationType = model.AddAssociationType( "M2M", entityA, RelationshipMultiplicity.Many, entityB, RelationshipMultiplicity.Many); associationType.SetConfiguration(navigationPropertyConfiguration); var navigationProperty = entityB.AddNavigationProperty("As", associationType); navigationProperty.SetClrPropertyInfo(mockPropertyInfo); model.AddAssociationSet("M2MSet", associationType); var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest) .Generate(model); modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest); Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete")); Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete1")); }
public void Apply_finds_inverse_when_many_to_many() { var mockTypeA = new MockType("A"); var mockTypeB = new MockType("B").Property(mockTypeA.AsCollection(), "As"); var mockPropertyInfo = mockTypeB.GetProperty("As"); mockTypeA.Property(mockTypeB.AsCollection(), "Bs"); var modelConfiguration = new ModelConfiguration(); new InversePropertyAttributeConvention() .Apply(mockPropertyInfo, modelConfiguration, new InversePropertyAttribute("Bs")); var navigationPropertyConfiguration = modelConfiguration.Entity(mockTypeB).Navigation(mockPropertyInfo); Assert.Same(mockTypeA.GetProperty("Bs"), navigationPropertyConfiguration.InverseNavigationProperty); }
public void ComplexType_Containing_EntityCollection_Throws() { MockType entityType = new MockType("EntityType"); MockType complexType = new MockType("ComplexTypeWithEntityCollection") .Property(entityType.AsCollection(), "CollectionProperty"); var modelBuilder = new ODataConventionModelBuilder(); modelBuilder.AddEntity(entityType); modelBuilder.AddComplexType(complexType); Assert.Throws <InvalidOperationException>( () => modelBuilder.GetEdmModel(), "The complex type 'DefaultNamespace.ComplexTypeWithEntityCollection' refers to the entity type 'DefaultNamespace.EntityType' through the property 'CollectionProperty'."); }
public void ComplexType_Containing_EntityCollection_Throws() { MockType entityType = new MockType("EntityType"); MockType complexType = new MockType("ComplexTypeWithEntityCollection") .Property(entityType.AsCollection(), "CollectionProperty"); var modelBuilder = new ODataConventionModelBuilder(); modelBuilder.AddEntity(entityType); modelBuilder.AddComplexType(complexType); Assert.Throws<InvalidOperationException>( () => modelBuilder.GetEdmModel(), "The complex type 'DefaultNamespace.ComplexTypeWithEntityCollection' refers to the entity type 'DefaultNamespace.EntityType' through the property 'CollectionProperty'."); }
public void ODataConventionModelBuilder_Sets_IsAddedExplicitly_Appropriately() { // Arrange MockType relatedEntity = new MockType("RelatedEntity") .Property<int>("ID"); MockType relatedComplexType = new MockType("RelatedComplexType"); MockType type = new MockType() .Property<int>("ID") .Property<int>("ExplicitlyAddedPrimitive") .Property<int>("InferredPrimitive") .Property<int[]>("ExplicitlyAddedPrimitiveCollection") .Property<int[]>("InferredAddedPrimitiveCollection") .Property(relatedComplexType, "ExplicitlyAddedComplex") .Property(relatedComplexType, "InferredComplex") .Property(relatedComplexType.AsCollection(), "ExplicitlyAddedComplexCollection") .Property(relatedComplexType.AsCollection(), "InferredComplexCollection") .Property(relatedEntity, "ExplicitlyAddedNavigation") .Property(relatedEntity, "InferredNavigation") .Property(relatedEntity.AsCollection(), "ExplicitlyAddedNavigationCollection") .Property(relatedEntity.AsCollection(), "InferredNavigationCollection"); var builder = new ODataConventionModelBuilder(); var entity = builder.AddEntity(type); entity.AddProperty(type.GetProperty("ExplicitlyAddedPrimitive")); entity.AddCollectionProperty(type.GetProperty("ExplicitlyAddedPrimitiveCollection")); entity.AddComplexProperty(type.GetProperty("ExplicitlyAddedComplex")); entity.AddCollectionProperty(type.GetProperty("ExplicitlyAddedComplexCollection")); entity.AddNavigationProperty(type.GetProperty("ExplicitlyAddedNavigation"), EdmMultiplicity.ZeroOrOne); entity.AddNavigationProperty(type.GetProperty("ExplicitlyAddedNavigationCollection"), EdmMultiplicity.Many); builder.OnModelCreating = (b) => { var explicitlyAddedProperties = entity.Properties.Where(p => p.Name.Contains("ExplicitlyAdded")); var inferredProperties = entity.Properties.Where(p => p.Name.Contains("Inferred")); Assert.Equal(13, entity.Properties.Count()); Assert.Equal(6, explicitlyAddedProperties.Count()); Assert.Equal(6, inferredProperties.Count()); foreach (var explicitlyAddedProperty in explicitlyAddedProperties) { Assert.True(explicitlyAddedProperty.AddedExplicitly); } foreach (var inferredProperty in inferredProperties) { Assert.False(inferredProperty.AddedExplicitly); } }; Assert.DoesNotThrow(() => builder.GetEdmModel()); }