public void Can_get_and_set_configuration_facet() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); associationType.SetConfiguration(42); Assert.Equal(42, associationType.GetConfiguration()); }
public void Configure_should_not_validate_consistency_of_dependent_end_when_both_false() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo()); associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo()); navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object))); }
public void Configure_should_validate_consistency_of_function_configuration_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var functionConfiguration1 = new ModificationFunctionConfiguration(); functionConfiguration1.HasName("Foo"); var functionConfiguration2 = new ModificationFunctionConfiguration(); functionConfiguration2.HasName("Bar"); var functionsConfiguration1 = new ModificationFunctionsConfiguration(); functionsConfiguration1.Insert(functionConfiguration1); var functionsConfiguration2 = new ModificationFunctionsConfiguration(); functionsConfiguration2.Insert(functionConfiguration2); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo()) { ModificationFunctionsConfiguration = functionsConfiguration1 }; associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo()) { ModificationFunctionsConfiguration = functionsConfiguration2 }; Assert.Equal( Strings.ConflictingFunctionsMapping("P", typeof(object)), Assert.Throws<InvalidOperationException>( () => navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object)))).Message); }
public void Configure_should_validate_consistency_of_constraint_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo()) { Constraint = new ForeignKeyConstraintConfiguration( new[] { new MockPropertyInfo(typeof(int), "P1").Object }) }; associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo()) { Constraint = new ForeignKeyConstraintConfiguration( new[] { new MockPropertyInfo(typeof(int), "P2").Object }) }; Assert.Equal( Strings.ConflictingConstraint("P", typeof(object)), Assert.Throws<InvalidOperationException>( () => navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object)))).Message); }
public void Configure_should_validate_consistency_of_inverse_end_kind_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var mockPropertyInfo = new MockPropertyInfo(); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(mockPropertyInfo) { RelationshipMultiplicity = RelationshipMultiplicity.ZeroOrOne }; associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo()) { InverseEndKind = RelationshipMultiplicity.Many, InverseNavigationProperty = mockPropertyInfo }; Assert.Equal( Strings.ConflictingMultiplicities("P", typeof(object)), Assert.Throws<InvalidOperationException>( () => navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object)))).Message); }
public void Configure_should_ensure_consistency_of_function_configuration_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var functionConfiguration = new ModificationStoredProcedureConfiguration(); functionConfiguration.HasName("Bar"); var functionsConfiguration = new ModificationStoredProceduresConfiguration(); functionsConfiguration.Insert(functionConfiguration); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N1")); associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2")) { ModificationStoredProceduresConfiguration = functionsConfiguration }; navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object))); Assert.Equal(functionsConfiguration, navigationPropertyConfigurationA.ModificationStoredProceduresConfiguration); }
public void Configure_should_validate_consistency_of_mapping_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var manyToManyAssociationMappingConfiguration1 = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration1.ToTable("A"); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N1")) { AssociationMappingConfiguration = manyToManyAssociationMappingConfiguration1 }; associationType.SetConfiguration(navigationPropertyConfigurationA); var manyToManyAssociationMappingConfiguration2 = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration2.ToTable("B"); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2")) { AssociationMappingConfiguration = manyToManyAssociationMappingConfiguration2 }; Assert.Equal( Strings.ConflictingMapping("N2", typeof(object)), Assert.Throws<InvalidOperationException>( () => navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object)))).Message); }
public void Configure_should_ensure_consistency_of_mapping_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N1")); associationType.SetConfiguration(navigationPropertyConfigurationA); var manyToManyAssociationMappingConfiguration = new ManyToManyAssociationMappingConfiguration(); manyToManyAssociationMappingConfiguration.ToTable("B"); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2")) { AssociationMappingConfiguration = manyToManyAssociationMappingConfiguration }; navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object))); Assert.Equal(manyToManyAssociationMappingConfiguration, navigationPropertyConfigurationA.AssociationMappingConfiguration); }
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_ensure_consistency_of_principality_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); var sourceEntityType = new EntityType("SE", "N", DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", sourceEntityType); var targetEntityType = new EntityType("TE", "N", DataSpace.CSpace); associationType.TargetEnd = new AssociationEndMember("T", targetEntityType); var navPropertyInfoA = new MockPropertyInfo(typeof(AType1), "N1"); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(navPropertyInfoA); associationType.SetConfiguration(navigationPropertyConfigurationA); var navPropertyA = new NavigationProperty("N1", TypeUsage.Create(targetEntityType)); navPropertyA.SetClrPropertyInfo(navPropertyInfoA); navPropertyA.RelationshipType = associationType; navPropertyA.ToEndMember = associationType.TargetEnd; navPropertyA.FromEndMember = associationType.SourceEnd; sourceEntityType.AddNavigationProperty(navPropertyA); var navPropertyInfoB = new MockPropertyInfo(typeof(AType1), "N2"); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(navPropertyInfoB) { IsNavigationPropertyDeclaringTypePrincipal = false }; var navPropertyB = new NavigationProperty("N2", TypeUsage.Create(sourceEntityType)); navPropertyB.SetClrPropertyInfo(navPropertyInfoB); navPropertyB.RelationshipType = associationType; navPropertyB.ToEndMember = associationType.SourceEnd; navPropertyB.FromEndMember = associationType.TargetEnd; targetEntityType.AddNavigationProperty(navPropertyB); var model = new EdmModel(DataSpace.CSpace); model.AddItem(sourceEntityType); model.AddItem(targetEntityType); navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, model, new EntityTypeConfiguration(typeof(object))); Assert.Equal(true, navigationPropertyConfigurationA.IsNavigationPropertyDeclaringTypePrincipal); }
public void Configure_should_ensure_consistency_of_delete_action_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N1")); associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2")) { DeleteAction = OperationAction.Cascade }; navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object))); Assert.Equal(OperationAction.Cascade, navigationPropertyConfigurationA.DeleteAction); }
public void Configure_should_wnsure_consistency_of_inverse_end_kind_when_already_configured() { var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace); associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)); associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)); var mockPropertyInfo = new MockPropertyInfo(typeof(AType1), "N1"); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(mockPropertyInfo); associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo(typeof(AType1), "N2")) { InverseEndKind = RelationshipMultiplicity.Many, InverseNavigationProperty = mockPropertyInfo }; navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(DataSpace.CSpace), new EntityTypeConfiguration(typeof(object))); Assert.Equal(RelationshipMultiplicity.Many, navigationPropertyConfigurationA.RelationshipMultiplicity); }
public void Configure_should_validate_consistency_of_delete_action_when_already_configured() { var associationType = new AssociationType(); associationType.SourceEnd = new AssociationEndMember("S", new EntityType()); associationType.TargetEnd = new AssociationEndMember("T", new EntityType()); var navigationPropertyConfigurationA = new NavigationPropertyConfiguration(new MockPropertyInfo()) { DeleteAction = OperationAction.None }; associationType.SetConfiguration(navigationPropertyConfigurationA); var navigationPropertyConfigurationB = new NavigationPropertyConfiguration(new MockPropertyInfo()) { DeleteAction = OperationAction.Cascade }; Assert.Equal( Strings.ConflictingCascadeDeleteOperation("P", typeof(object)), Assert.Throws<InvalidOperationException>( () => navigationPropertyConfigurationB.Configure( new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType())) { RelationshipType = associationType }, new EdmModel(), new EntityTypeConfiguration(typeof(object)))).Message); }