private void RaiseDataModelValidationEvent(DataModelErrorEventArgs error) { DebugCheck.NotNull(error); if (OnError != null) { OnError(this, error); } }
public void EdmModel_NameIsNotAllowed_triggered_for_conceptual_property_with_period() { var property = EdmProperty.CreatePrimitive("Property.With.Dots", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)); var validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.CSpace), true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; EdmModelSyntacticValidationRules .EdmModel_NameIsNotAllowed .Evaluate(validationContext, property); Assert.NotNull(errorEventArgs); }
public void EdmModel_NameIsNotAllowed_triggered_for_conceptual_entity_types_with_spaces() { var entityType = new EntityType("Entity With Spaces", "N", DataSpace.CSpace); var validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.CSpace), true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; EdmModelSyntacticValidationRules .EdmModel_NameIsNotAllowed .Evaluate(validationContext, entityType); Assert.NotNull(errorEventArgs); }
public void EdmNavigationProperty_BadNavigationPropertyBadFromRoleType() { var parentEntity = new EntityType("P", "N", DataSpace.CSpace); var targetEntity = new EntityType("T", "N", DataSpace.CSpace); var sourceEntity = new EntityType("S", "N", DataSpace.CSpace); var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace) { SourceEnd = new AssociationEndMember("S", sourceEntity), TargetEnd = new AssociationEndMember("T", targetEntity) }; var navigationProperty = new NavigationProperty("N", TypeUsage.Create(targetEntity)) { RelationshipType = associationType }; parentEntity.AddMember(navigationProperty); var model = new EdmModel(DataSpace.CSpace); model.AddItem(parentEntity); var validationContext = new EdmModelValidationContext(model, true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; EdmModelSemanticValidationRules .EdmNavigationProperty_BadNavigationPropertyBadFromRoleType .Evaluate(validationContext, navigationProperty); Assert.NotNull(errorEventArgs); Assert.Same(navigationProperty, errorEventArgs.Item); Assert.Equal( Strings.BadNavigationPropertyBadFromRoleType( navigationProperty.Name, sourceEntity.Name, navigationProperty.GetFromEnd().Name, navigationProperty.Association.Name, parentEntity.Name), errorEventArgs.ErrorMessage); }
[Fact] // Codeplex 1735 public void EdmAssociationType_ValidateReferentialConstraint_validates_composite_key_properties_in_correct_order() { var principal = new EntityType( "Principal", "N", DataSpace.CSpace, new[] { "IdInt", "IdString" }, new EdmMember[] { new EdmProperty("IdInt", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))), new EdmProperty("IdString", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))) }); var dependent = new EntityType( "Dependent", "N", DataSpace.CSpace, new[] { "Id" }, new EdmMember[] { new EdmProperty("Id", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))), new EdmProperty("IdString", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))), new EdmProperty("IdInt", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))) }); var associationType = new AssociationType("AT", "N", true, DataSpace.CSpace); var fromRole = new AssociationEndMember("Principal", new RefType(principal), RelationshipMultiplicity.ZeroOrOne); var toRole = new AssociationEndMember("Dependent", new RefType(dependent), RelationshipMultiplicity.Many); associationType.Constraint = new ReferentialConstraint( fromRole, toRole, new[] { principal.Properties["IdString"], principal.Properties["IdInt"] }, new[] { dependent.Properties["IdString"], dependent.Properties["IdInt"] }); var validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.CSpace), true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; EdmModelSemanticValidationRules .EdmAssociationType_ValidateReferentialConstraint .Evaluate(validationContext, associationType); Assert.Null(errorEventArgs); }
private DataModelErrorEventArgs ValidateAssociationTypeWithNonFkeyReference(DataSpace dataSpace) { var model = new EdmModel(dataSpace, 1.0); var intType = dataSpace == DataSpace.CSpace ? PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32) : FakeSqlProviderServices.Instance.GetProviderManifest("2008").GetStoreTypes().Single(t => t.Name == "int"); var principal = new EntityType("P", "ns", dataSpace, new [] { "Id" }, new[] { EdmProperty.CreatePrimitive("Id", intType) }); var dependent = new EntityType("P", "ns", dataSpace, new [] { "Id" }, new[] { EdmProperty.CreatePrimitive("Id", intType), EdmProperty.CreatePrimitive("NonKeyProperty", intType) }); foreach (var property in principal.Properties.Concat(dependent.Properties)) { property.Nullable = false; } var associationType = new AssociationType("AT", "ns", false, dataSpace) { Constraint = new ReferentialConstraint( new AssociationEndMember("P", principal.GetReferenceType(), RelationshipMultiplicity.One), new AssociationEndMember("C", dependent.GetReferenceType(), RelationshipMultiplicity.Many), principal.KeyProperties, dependent.Properties.Where(p => p.Name == "NonKeyProperty")) }; model.AddAssociationType(associationType); var validationContext = new EdmModelValidationContext(model, true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; EdmModelSemanticValidationRules .EdmAssociationType_ValidateReferentialConstraint .Evaluate(validationContext, model.AssociationTypes.Single()); return(errorEventArgs); }
public void EdmModel_NameIsNotAllowed_not_triggered_for_row_and_collection_types() { var rowType = new RowType(new[] { EdmProperty.CreatePrimitive("Property", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)) }); foreach (var type in new EdmType[] { rowType, rowType.GetCollectionType() }) { var validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.SSpace), true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; EdmModelSyntacticValidationRules .EdmModel_NameIsNotAllowed .Evaluate(validationContext, type); Assert.Null(errorEventArgs); } }
public void EdmEntityType_InvalidMemberNameMatchesTypeName_calls_on_error_if_name_matches_type_name_in_c_space() { var validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.CSpace), true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; var entity = new EntityType("SameName", "N", DataSpace.CSpace, null, new EdmMember[] { new EdmProperty("SameName") }); EdmModelSemanticValidationRules .EdmEntityType_InvalidMemberNameMatchesTypeName .Evaluate(validationContext, entity); Assert.NotNull(errorEventArgs); Assert.True(entity.Properties.Any(p => p.Name == entity.Name)); }
public void EdmFunction_DuplicateParameterName() { var validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.SSpace), true); DataModelErrorEventArgs errorEventArgs = null; validationContext.OnError += (_, e) => errorEventArgs = e; var parameter1 = new FunctionParameter( "P", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In); var parameter2 = new FunctionParameter( "P2", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)), ParameterMode.In); var function = new EdmFunction( "F", "N", DataSpace.SSpace, new EdmFunctionPayload { Parameters = new[] { parameter1, parameter2 } }); parameter2.Name = "P"; EdmModelSemanticValidationRules .EdmFunction_DuplicateParameterName .Evaluate(validationContext, function); Assert.NotNull(errorEventArgs); Assert.Same(parameter2, errorEventArgs.Item); Assert.Equal( Strings.ParameterNameAlreadyDefinedDuplicate("P"), errorEventArgs.ErrorMessage); }
private static string ToText(DataModelErrorEventArgs errorEventArgs) { return $"{errorEventArgs.Item}.{errorEventArgs.PropertyName}: {errorEventArgs.ErrorMessage}"; }
private static string ToText(DataModelErrorEventArgs errorEventArgs) { return string.Format("{0}.{1}: {2}", errorEventArgs.Item, errorEventArgs.PropertyName, errorEventArgs.ErrorMessage); }