public void Configure_should_configure_modification_functions() { var model = new EdmModel(DataSpace.CSpace); var entityType = model.AddEntityType("E"); entityType.GetMetadataProperties().SetClrType(typeof(object)); model.AddEntitySet("ESet", entityType); var modificationFunctionsConfigurationMock = new Mock <ModificationStoredProceduresConfiguration>(); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.MapToStoredProcedures(modificationFunctionsConfigurationMock.Object, true); entityType.SetConfiguration(entityTypeConfiguration); var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model); entityTypeConfiguration.Configure(entityType, databaseMapping, ProviderRegistry.Sql2008_ProviderManifest); modificationFunctionsConfigurationMock .Verify( m => m.Configure( It.IsAny <EntityTypeModificationFunctionMapping>(), It.IsAny <DbProviderManifest>()), Times.Once()); }
public void Configure_should_configure_modification_functions() { var model = new EdmModel(DataSpace.CSpace); var entityType = model.AddEntityType("E"); entityType.GetMetadataProperties().SetClrType(typeof(object)); model.AddEntitySet("ESet", entityType); var modificationFunctionsConfigurationMock = new Mock<ModificationStoredProceduresConfiguration>(); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.MapToStoredProcedures(modificationFunctionsConfigurationMock.Object, true); entityType.SetConfiguration(entityTypeConfiguration); var databaseMapping = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model); entityTypeConfiguration.Configure(entityType, databaseMapping, ProviderRegistry.Sql2008_ProviderManifest); modificationFunctionsConfigurationMock .Verify( m => m.Configure( It.IsAny<EntityTypeModificationFunctionMapping>(), It.IsAny<DbProviderManifest>()), Times.Once()); }
public void Configure_should_configure_and_order_keys_when_keys_and_order_specified() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2"); entityTypeConfiguration.Key(mockPropertyInfo2); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2")).SetClrPropertyInfo(mockPropertyInfo2); var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1"); entityTypeConfiguration.Key(mockPropertyInfo1); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetClrPropertyInfo(mockPropertyInfo1); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal(2, entityType.KeyProperties.Count); Assert.Equal("P1", entityType.KeyProperties.First().Name); }
public void Configure_should_set_configuration() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); Assert.Same(entityTypeConfiguration, entityType.GetConfiguration()); }
public void Configure_should_set_configuration() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); Assert.Same(entityTypeConfiguration, entityType.GetConfiguration()); }
public void Configure_should_throw_when_key_property_not_found() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo = new MockPropertyInfo(typeof(int), "Id"); entityTypeConfiguration.Key(mockPropertyInfo); Assert.Equal( Strings.KeyPropertyNotFound(("Id"), "E"), Assert.Throws <InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Configure_should_throw_when_property_not_found() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyConfiguration = new Mock <PrimitivePropertyConfiguration>(); entityTypeConfiguration.Property(new PropertyPath(new MockPropertyInfo()), () => mockPropertyConfiguration.Object); Assert.Equal( Strings.PropertyNotFound(("P"), "E"), Assert.Throws <InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Configure_should_configure_entity_set_name() { var model = new EdmModel(DataSpace.CSpace); var entityType = new EntityType("E", "N", DataSpace.CSpace); var entitySet = model.AddEntitySet("ESet", entityType); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)) { EntitySetName = "MySet" }; entityTypeConfiguration.Configure(entityType, model); Assert.Equal("MySet", entitySet.Name); Assert.Same(entityTypeConfiguration, entitySet.GetConfiguration()); }
public void Configure_should_configure_properties() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyConfiguration = new Mock <PrimitivePropertyConfiguration>(); var mockPropertyInfo = new MockPropertyInfo(); property.SetClrPropertyInfo(mockPropertyInfo); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo), () => mockPropertyConfiguration.Object); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); mockPropertyConfiguration.Verify(p => p.Configure(property)); }
public void Configure_should_throw_when_key_properties_and_not_root_type() { var entityType = new EntityType("E", "N", DataSpace.CSpace) { BaseType = new EntityType("E", "N", DataSpace.CSpace) }; var type = typeof(string); entityType.BaseType.GetMetadataProperties().SetClrType(type); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.Key(new MockPropertyInfo(typeof(int), "Id")); Assert.Equal( Strings.KeyRegisteredOnDerivedType(typeof(object), typeof(string)), Assert.Throws <InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Configure_should_configure_entity_set_name() { var model = new EdmModel(DataSpace.CSpace); var entityType = new EntityType("E", "N", DataSpace.CSpace); var entitySet = model.AddEntitySet("ESet", entityType); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)) { EntitySetName = "MySet" }; entityTypeConfiguration.Configure(entityType, model); Assert.Equal("MySet", entitySet.Name); Assert.Same(entityTypeConfiguration, entitySet.GetConfiguration()); }
public void Configure_should_throw_when_key_property_not_found() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo = new MockPropertyInfo(typeof(int), "Id"); entityTypeConfiguration.Key(mockPropertyInfo); Assert.Equal( Strings.KeyPropertyNotFound(("Id"), "E"), Assert.Throws<InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Configure_should_throw_when_key_properties_and_not_root_type() { var entityType = new EntityType("E", "N", DataSpace.CSpace) { BaseType = new EntityType("E", "N", DataSpace.CSpace) }; var type = typeof(string); entityType.BaseType.GetMetadataProperties().SetClrType(type); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); entityTypeConfiguration.Key(new MockPropertyInfo(typeof(int), "Id")); Assert.Equal( Strings.KeyRegisteredOnDerivedType(typeof(object), typeof(string)), Assert.Throws<InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Configure_should_configure_and_order_keys_when_keys_and_order_specified() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); var property1 = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property1); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2"); entityTypeConfiguration.Key(mockPropertyInfo2); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P2")).SetClrPropertyInfo(mockPropertyInfo2); var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1"); entityTypeConfiguration.Key(mockPropertyInfo1); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0; (entityType.GetDeclaredPrimitiveProperties().SingleOrDefault(p => p.Name == "P1")).SetClrPropertyInfo(mockPropertyInfo1); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); Assert.Equal(2, entityType.KeyProperties.Count); Assert.Equal("P1", entityType.KeyProperties.First().Name); }
public void Configure_should_throw_when_property_not_found() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>(); entityTypeConfiguration.Property(new PropertyPath(new MockPropertyInfo()), () => mockPropertyConfiguration.Object); Assert.Equal( Strings.PropertyNotFound(("P"), "E"), Assert.Throws<InvalidOperationException>( () => entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace))).Message); }
public void Configure_should_configure_properties() { var entityType = new EntityType("E", "N", DataSpace.CSpace); var property = EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)); entityType.AddMember(property); var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object)); var mockPropertyConfiguration = new Mock<PrimitivePropertyConfiguration>(); var mockPropertyInfo = new MockPropertyInfo(); property.SetClrPropertyInfo(mockPropertyInfo); entityTypeConfiguration.Property(new PropertyPath(mockPropertyInfo), () => mockPropertyConfiguration.Object); entityTypeConfiguration.Configure(entityType, new EdmModel(DataSpace.CSpace)); mockPropertyConfiguration.Verify(p => p.Configure(property)); }