Beispiel #1
0
        public void Validate(EdmModel model, bool validateSyntax)
        {
            EdmModelValidationContext context = new EdmModelValidationContext(model, validateSyntax);

            context.OnError += this.OnError;
            new EdmModelValidationVisitor(context, EdmModelRuleSet.CreateEdmModelRuleSet(model.SchemaVersion, validateSyntax)).Visit(model);
        }
        public void EdmModel_NameIsTooLong_not_triggered_for_row_and_collection_types()
        {
            var intType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);

            var properties = new EdmProperty[100];
            for (int i = 0; i < 100; i++)
            {
                properties[i] = EdmProperty.Primitive("Property" + i, intType);
            }

            var rowType = new RowType(properties);

            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_NameIsTooLong
                    .Evaluate(validationContext, type);

                Assert.Null(errorEventArgs);
            }
        }
        internal EdmModelValidationVisitor(EdmModelValidationContext context, EdmModelRuleSet ruleSet)
        {
            DebugCheck.NotNull(context);
            DebugCheck.NotNull(ruleSet);

            _context = context;
            _ruleSet = ruleSet;
        }
Beispiel #4
0
        public void Validate(Core.Metadata.Edm.EdmModel root, bool validateSyntax)
        {
            var context = new EdmModelValidationContext(validateSyntax);

            context.OnError += OnError;

            context.Validate(root);
        }
Beispiel #5
0
        internal static void Validate(EdmModel validateRoot, EdmModelValidationContext context)
        {
            var edmModelValidationRuleSet
                = EdmModelRuleSet.CreateEdmModelRuleSet(context.ValidationContextVersion, context.ValidateSyntax);

            var modelVisitor = new EdmModelValidationVisitor(context, edmModelValidationRuleSet);

            modelVisitor.Visit(validateRoot);
        }
        public void IsCSpace_returns_true_when_cspace()
        {
            var validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.CSpace), true);

            Assert.True(validationContext.IsCSpace);

            validationContext = new EdmModelValidationContext(new EdmModel(DataSpace.SSpace), true);

            Assert.False(validationContext.IsCSpace);
        }
        public void Validate(EdmModel model, bool validateSyntax)
        {
            var context = new EdmModelValidationContext(model, validateSyntax);

            context.OnError += OnError;

            var modelVisitor
                = new EdmModelValidationVisitor(
                    context,
                    EdmModelRuleSet.CreateEdmModelRuleSet(model.SchemaVersion, validateSyntax));

            modelVisitor.Visit(model);
        }
Beispiel #8
0
        public void EdmModel_NameIsNotAllowed_triggered_for_conceptual_property_with_period()
        {
            var property = EdmProperty.Primitive("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 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);
        }
        public void EdmModel_NameIsNotAllowed_not_triggered_for_row_and_collection_types()
        {
            var rowType =
                new RowType(new[] { EdmProperty.Primitive("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 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);
        }
Beispiel #12
0
 internal override void Evaluate(EdmModelValidationContext context, MetadataItem item)
 {
     this._validate(context, item as TItem);
 }
 internal EdmModelValidationVisitor(EdmModelValidationContext context, EdmModelRuleSet ruleSet)
 {
     _context = context;
     _ruleSet = ruleSet;
 }
 internal abstract void Evaluate(EdmModelValidationContext context, IMetadataItem item);
Beispiel #15
0
 internal override void Evaluate(EdmModelValidationContext context, IMetadataItem item)
 {
     _validate(context, (TItem)item);
 }
 internal abstract void Evaluate(EdmModelValidationContext context, MetadataItem item);
        private static DataModelErrorEventArgs EdmFunction_ComposableFunctionImportsNotAllowed_V1_V2_runner(double schemaVersion, bool isFunctionImport = true, bool isComposable = true)
        {
            var functionImport = new EdmFunction(
                "f", "Ns", DataSpace.CSpace,
                new EdmFunctionPayload
                {
                    IsComposable = isComposable,
                    IsFunctionImport = isFunctionImport
                });

            var model = new EdmModel(DataSpace.CSpace, schemaVersion);

            var validationContext
                = new EdmModelValidationContext(model, true);

            DataModelErrorEventArgs errorEventArgs = null;
            validationContext.OnError += (_, e) => errorEventArgs = e;

            EdmModelSemanticValidationRules
                .EdmFunction_ComposableFunctionImportsNotAllowed_V1_V2
                .Evaluate(validationContext, functionImport);

            return errorEventArgs;
        }
        public void EdmEntityContainer_DuplicateEntitySetTable()
        {
            var model = new EdmModel(DataSpace.SSpace);

            model.Containers.Single().AddEntitySetBase(
                new EntitySet("Foo", "S", "T", null, new EntityType("E", "N", DataSpace.CSpace)));

            var duplicateEntitySet = new EntitySet("Bar", "S", "T", null, new EntityType("E", "N", DataSpace.CSpace));

            model.Containers.Single().AddEntitySetBase(duplicateEntitySet);

            var validationContext
                = new EdmModelValidationContext(model, true);

            DataModelErrorEventArgs errorEventArgs = null;
            validationContext.OnError += (_, e) => errorEventArgs = e;

            EdmModelSemanticValidationRules
                .EdmEntityContainer_DuplicateEntitySetTable
                .Evaluate(validationContext, model.Containers.Single());

            Assert.NotNull(errorEventArgs);
            Assert.Same(duplicateEntitySet, errorEventArgs.Item);
            Assert.Equal(
                Strings.DuplicateEntitySetTable(
                    duplicateEntitySet.Name,
                    duplicateEntitySet.Schema,
                    duplicateEntitySet.Table),
                errorEventArgs.ErrorMessage);
        }
        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.Primitive("Id", intType) });
            var dependent = 
                new EntityType("P", "ns", dataSpace, new [] {"Id"},
                    new[] { EdmProperty.Primitive("Id", intType), EdmProperty.Primitive("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;
        }
Beispiel #20
0
        public void EdmModel_NameIsNotAllowed_not_triggered_for_store_entity_types_with_spaces()
        {
            var entityType = new EntityType("Entity With Spaces", "N", DataSpace.SSpace);

            var validationContext
                = new EdmModelValidationContext(new EdmModel(DataSpace.SSpace), true);
            DataModelErrorEventArgs errorEventArgs = null;
            validationContext.OnError += (_, e) => errorEventArgs = e;

            EdmModelSyntacticValidationRules
                .EdmModel_NameIsNotAllowed
                .Evaluate(validationContext, entityType);

            Assert.Null(errorEventArgs);
        }