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 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 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);
            }
        }
예제 #4
0
        internal EdmModelValidationVisitor(EdmModelValidationContext context, EdmModelRuleSet ruleSet)
        {
            DebugCheck.NotNull(context);
            DebugCheck.NotNull(ruleSet);

            _context = context;
            _ruleSet = ruleSet;
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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 EdmType_SystemNamespaceEncountered_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;

                EdmModelSemanticValidationRules
                .EdmType_SystemNamespaceEncountered
                .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);
        }
 internal abstract void Evaluate(EdmModelValidationContext context, IMetadataItem item);
 internal override void Evaluate(EdmModelValidationContext context, MetadataItem item)
 {
     Debug.Assert(item is TItem);
     _validate(context, item as TItem);
 }
 internal override void Evaluate(EdmModelValidationContext context, IMetadataItem item)
 {
     _validate(context, (TItem)item);
 }