示例#1
0
        public void Serialize_with_schemaNamespace_returns_false_if_error_in_model()
        {
            var model      = new EdmModel(DataSpace.SSpace);
            var mockWriter = new Mock <XmlWriter>();

            // add EntityType with no properties which will cause error
            var et = new EntityType("TestEntity", "TestNamespace", DataSpace.SSpace);

            model.AddItem(et);

            var validationErrors = new List <DataModelErrorEventArgs>();
            var serializer       = new SsdlSerializer();

            serializer.OnError += (_, e) => validationErrors.Add(e);
            Assert.False(serializer.Serialize(
                             model,
                             "MyNamespace",
                             ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName,
                             ProviderRegistry.Sql2008_ProviderInfo.ProviderManifestToken,
                             mockWriter.Object,
                             false));
            Assert.Equal(1, validationErrors.Count());
            Assert.Equal(
                Strings.EdmModel_Validator_Semantic_KeyMissingOnEntityType("TestEntity"),
                validationErrors[0].ErrorMessage);
            mockWriter.Verify(m => m.WriteStartDocument(), Times.Never());
        }
示例#2
0
        public void Validate_should_throw_on_error()
        {
            var model = new EdmModel(DataSpace.CSpace);

            model.AddItem(new EntityType("E", "N", DataSpace.CSpace));

            Assert.Throws <ModelValidationException>(() => model.Validate());
        }
示例#3
0
        public void Validate_should_throw_on_error()
        {
            var model = new EdmModel(DataSpace.CSpace);

            model.AddItem(new EntityType("E", "N", DataSpace.CSpace));

            Assert.Throws<ModelValidationException>(() => model.Validate());
        }
示例#4
0
        public void GlobalItems_should_return_namespace_items_and_containers()
        {
            var model = new EdmModel(DataSpace.SSpace);

            model.AddItem(new EntityType("Entity", "Model", DataSpace.SSpace));

            Assert.Equal(2, model.GlobalItems.Count());
        }
示例#5
0
        public void GlobalItems_should_return_namespace_items_and_containers()
        {
            var model = new EdmModel(DataSpace.SSpace);

            model.AddItem(new EntityType("Entity", "Model", DataSpace.SSpace));

            Assert.Equal(2, model.GlobalItems.Count());
        }
        public void AddItem_can_add_function()
        {
            var model    = new EdmModel(DataSpace.SSpace);
            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());

            model.AddItem(function);

            Assert.True(model.Functions.Contains(function));
            Assert.True(model.NamespaceItems.Contains(function));
        }
        public void Custom_namespace_overrides_inferred_namespace()
        {
            var model = new EdmModel(DataSpace.CSpace);

            model.AddItem(new ComplexType("foo", "namespace", DataSpace.CSpace));

            var schemaWriterMock = new Mock <EdmXmlSchemaWriter>(new Mock <XmlWriter>().Object, 3.0, false, null);

            new EdmSerializationVisitor(schemaWriterMock.Object)
            .Visit(new EdmModel(DataSpace.CSpace), "NS");

            schemaWriterMock.Verify(sw => sw.WriteSchemaElementHeader("NS"), Times.Once());
        }
示例#8
0
        public void Can_add_remove_complex_type()
        {
            var model       = new EdmModel(DataSpace.SSpace);
            var complexType = new ComplexType("C", "N", DataSpace.SSpace);

            model.AddItem(complexType);

            Assert.True(model.ComplexTypes.Contains(complexType));
            Assert.True(model.NamespaceItems.Contains(complexType));

            model.RemoveItem(complexType);

            Assert.False(model.ComplexTypes.Contains(complexType));
            Assert.False(model.NamespaceItems.Contains(complexType));
        }
示例#9
0
        public void Can_add_remove_entity_type()
        {
            var model      = new EdmModel(DataSpace.SSpace);
            var entityType = new EntityType("E", "N", DataSpace.SSpace);

            model.AddItem(entityType);

            Assert.True(model.EntityTypes.Contains(entityType));
            Assert.True(model.NamespaceItems.Contains(entityType));

            model.RemoveItem(entityType);

            Assert.False(model.EntityTypes.Contains(entityType));
            Assert.False(model.NamespaceItems.Contains(entityType));
        }
示例#10
0
        public void Can_add_remove_association_type()
        {
            var model           = new EdmModel(DataSpace.SSpace);
            var associationType = new AssociationType("A", "N", false, DataSpace.SSpace);

            model.AddItem(associationType);

            Assert.True(model.AssociationTypes.Contains(associationType));
            Assert.True(model.NamespaceItems.Contains(associationType));

            model.RemoveItem(associationType);

            Assert.False(model.AssociationTypes.Contains(associationType));
            Assert.False(model.NamespaceItems.Contains(associationType));
        }
        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);
        }
示例#12
0
        public void Can_add_remove_enum_type()
        {
            var model    = new EdmModel(DataSpace.SSpace);
            var enumType = new EnumType {
                DataSpace = DataSpace.SSpace
            };

            model.AddItem(enumType);

            Assert.True(model.EnumTypes.Contains(enumType));
            Assert.True(model.NamespaceItems.Contains(enumType));

            model.RemoveItem(enumType);

            Assert.False(model.EnumTypes.Contains(enumType));
            Assert.False(model.NamespaceItems.Contains(enumType));
        }
        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 When_store_function_name_has_a_dot()
        {
            var errors = new List<DataModelErrorEventArgs>();
            var validator = new DataModelValidator();

            validator.OnError += (s, a) => errors.Add(a);

            var model = new EdmModel(DataSpace.SSpace);

            model.AddItem(new EdmFunction("Has.Dots", "N", DataSpace.SSpace));

            validator.Validate(model, validateSyntax: true);

            var error = errors.Single();

            Assert.Equal("Name", error.PropertyName);
            Assert.Equal(Strings.EdmModel_Validator_Syntactic_EdmModel_NameIsNotAllowed("Has.Dots"), error.ErrorMessage);
        }
示例#15
0
        public void When_store_function_name_has_a_dot()
        {
            var errors    = new List <DataModelErrorEventArgs>();
            var validator = new DataModelValidator();

            validator.OnError += (s, a) => errors.Add(a);

            var model = new EdmModel(DataSpace.SSpace);

            model.AddItem(new EdmFunction("Has.Dots", "N", DataSpace.SSpace));

            validator.Validate(model, validateSyntax: true);

            var error = errors.Single();

            Assert.Equal("Name", error.PropertyName);
            Assert.Equal(Strings.EdmModel_Validator_Syntactic_EdmModel_NameIsNotAllowed("Has.Dots"), error.ErrorMessage);
        }
示例#16
0
        public void VisitEdmModel_should_visit_edm_functions()
        {
            var visitorMock
                = new Mock<EdmModelVisitor>
                      {
                          CallBase = true
                      };

            var function = new EdmFunction("F", "N", DataSpace.SSpace);
            var model = new EdmModel(DataSpace.SSpace);
            model.AddItem(function);

            visitorMock.Object.VisitEdmModel(model);

            visitorMock.Verify(v => v.VisitFunctions(It.IsAny<IEnumerable<EdmFunction>>()), Times.Once());
            visitorMock.Verify(v => v.VisitMetadataItem(function), Times.Once());
            visitorMock.Verify(v => v.VisitEdmFunction(function), Times.Once());
        }
示例#17
0
        public void Validation_error_not_reported_for_types_marked_as_invalid()
        {
            var invalidAttribute =
                MetadataProperty.Create(
                    "EdmSchemaInvalid",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    true);

            var model = new EdmModel(DataSpace.SSpace);

            model.AddItem(
                EntityType.Create("E", "N", DataSpace.SSpace, new string[0], new EdmMember[0], new[] { invalidAttribute }));

            using (var writer = XmlWriter.Create(new StringBuilder()))
            {
                var ssdlSerializer = new SsdlSerializer();
                ssdlSerializer.OnError += (_, e) => { throw new Exception("Should not be invoked."); };

                Assert.True(ssdlSerializer.Serialize(model, "N", "invName", "42", writer));
            }
        }
示例#18
0
        private EdmModel CreateTestModel()
        {
            var model = new EdmModel(DataSpace.SSpace);

            var sqlManifest     = new SqlProviderManifest("2008");
            var stringTypeUsage = sqlManifest.GetStoreType(
                TypeUsage.CreateDefaultTypeUsage(
                    PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));

            var complexType = new ComplexType("Entity", "Unicorns420", DataSpace.SSpace);

            complexType.AddMember(new EdmProperty("NullableProperty", stringTypeUsage)
            {
                Nullable = true
            });
            complexType.AddMember(new EdmProperty("NonNullableProperty", stringTypeUsage)
            {
                Nullable = false
            });
            model.AddItem(complexType);

            return(model);
        }
示例#19
0
        public void Can_add_remove_entity_type()
        {
            var model = new EdmModel(DataSpace.SSpace);
            var entityType = new EntityType("E", "N", DataSpace.SSpace);

            model.AddItem(entityType);

            Assert.True(model.EntityTypes.Contains(entityType));
            Assert.True(model.NamespaceItems.Contains(entityType));

            model.RemoveItem(entityType);

            Assert.False(model.EntityTypes.Contains(entityType));
            Assert.False(model.NamespaceItems.Contains(entityType));
        }
示例#20
0
        public void Can_add_remove_association_type()
        {
            var model = new EdmModel(DataSpace.SSpace);
            var associationType = new AssociationType("A", "N", false, DataSpace.SSpace);

            model.AddItem(associationType);

            Assert.True(model.AssociationTypes.Contains(associationType));
            Assert.True(model.NamespaceItems.Contains(associationType));

            model.RemoveItem(associationType);

            Assert.False(model.AssociationTypes.Contains(associationType));
            Assert.False(model.NamespaceItems.Contains(associationType));
        }
示例#21
0
        public void Can_add_remove_complex_type()
        {
            var model = new EdmModel(DataSpace.SSpace);
            var complexType = new ComplexType("C", "N", DataSpace.SSpace);

            model.AddItem(complexType);

            Assert.True(model.ComplexTypes.Contains(complexType));
            Assert.True(model.NamespaceItems.Contains(complexType));

            model.RemoveItem(complexType);

            Assert.False(model.ComplexTypes.Contains(complexType));
            Assert.False(model.NamespaceItems.Contains(complexType));
        }
        public void GetAssociationType_should_return_correct_type()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var associationType
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace)),
                          TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace)),
                          Name = "Foo"
                      };
            model.AddItem(associationType);

            Assert.Same(associationType, model.GetAssociationType("Foo"));
        }
        public void Apply_should_not_discover_when_multiple_associations_exist()
        {
            var associationType = CreateAssociationType();

            var pkProperty = EdmProperty.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            associationType.SourceEnd.GetEntityType().AddKeyMember(pkProperty);

            var fkProperty = EdmProperty.CreatePrimitive("FooId", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            associationType.TargetEnd.GetEntityType().AddMember(fkProperty);

            // Foo.Id == Bar.FooId
            associationType.SourceEnd.GetEntityType().Name = "Foo";

            var model = new EdmModel(DataSpace.CSpace);
            model.AddItem(associationType);
            model.AddItem(associationType);

            (new TypeNameForeignKeyDiscoveryConvention())
                .Apply(associationType, new DbModel(model, null));

            Assert.Null(associationType.Constraint);
        }
        public void Apply_should_discover_when_multiple_associations_exist()
        {
            var associationType = CreateAssociationType();

            var pkProperty = EdmProperty.Primitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            associationType.SourceEnd.GetEntityType().AddKeyMember(pkProperty);

            var fkProperty = EdmProperty.Primitive("NavId", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            associationType.TargetEnd.GetEntityType().AddMember(fkProperty);
            associationType.TargetEnd.GetEntityType().AddNavigationProperty("Nav", associationType).ToEndMember = associationType.SourceEnd;

            // Foo.Id == Bar.NavId

            var model = new EdmModel(DataSpace.CSpace);
            model.AddItem(associationType);
            model.AddItem(associationType);

            ((IEdmConvention<AssociationType>)new NavigationPropertyNameForeignKeyDiscoveryConvention())
                .Apply(associationType, model);

            Assert.NotNull(associationType.Constraint);
        }
        public void Serialize_with_schemaNamespace_returns_false_if_error_in_model()
        {
            var model = new EdmModel(DataSpace.SSpace);
            var mockWriter = new Mock<XmlWriter>();

            // add EntityType with no properties which will cause error
            var et = new EntityType("TestEntity", "TestNamespace", DataSpace.SSpace);
            model.AddItem(et);

            var validationErrors = new List<DataModelErrorEventArgs>();
            var serializer = new SsdlSerializer();
            serializer.OnError += (_, e) => validationErrors.Add(e);
            Assert.False(serializer.Serialize(
                model,
                "MyNamespace",
                ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName,
                ProviderRegistry.Sql2008_ProviderInfo.ProviderManifestToken,
                mockWriter.Object,
                false));
            Assert.Equal(1, validationErrors.Count());
            Assert.Equal(
                Strings.EdmModel_Validator_Semantic_KeyMissingOnEntityType("TestEntity"),
                validationErrors[0].ErrorMessage);
            mockWriter.Verify(m => m.WriteStartDocument(), Times.Never());
        }
        private static EdmModel CreateStoreModel(Version targetSchemaVersion, params EdmFunction[] functions)
        {
            var storeModel = new EdmModel(
                DataSpace.SSpace,
                EntityFrameworkVersion.VersionToDouble(targetSchemaVersion));

            foreach (var function in functions)
            {
                storeModel.AddItem(function);
            }
            return storeModel;
        }
        public void CollectStoreModelErrors_returns_errors_from_function_return_rowtypes()
        {
            var edmSchemaError = new EdmSchemaError("msg", 42, EdmSchemaErrorSeverity.Error);
            var errorMetadataProperty =
                MetadataProperty.Create(
                    MetadataItemHelper.SchemaErrorsMetadataPropertyName,
                    TypeUsage.CreateDefaultTypeUsage(
                        PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType()),
                    new List<EdmSchemaError> { edmSchemaError });

            var rowType = RowType.Create(new EdmProperty[0], new[] { errorMetadataProperty });

            var function =
                EdmFunction.Create(
                    "foo",
                    "bar",
                    DataSpace.SSpace,
                    new EdmFunctionPayload
                        {
                            ReturnParameters =
                                new[]
                                    {
                                        FunctionParameter.Create(
                                            "ReturnType",
                                            rowType,
                                            ParameterMode.ReturnValue)
                                    }
                        },
                    null);

            var model = new EdmModel(DataSpace.SSpace);
            model.AddItem(function);

            var schemaErrors = ModelGenerator.CollectStoreModelErrors(model);

            Assert.NotNull(schemaErrors);
            Assert.Equal(1, schemaErrors.Count);
            Assert.Same(edmSchemaError, schemaErrors.Single());
        }
示例#28
0
        public void UpdateConceptualModel_does_not_update_csdl_when_ReplaceEdmxSection_returns_false()
        {
            // This test is really only to test that EdmxHelper.ReplaceEdmxSection() returns false
            // when the underlying XmlWriter returns null (because of errors in the model it is trying
            // to write) - but that method is private so need to test through one of the other methods

            var edmx = XDocument.Parse(EdmxTemplate);

            // create EntityType with no members (and hence no keys) which will cause error
            var edmModel = new EdmModel(DataSpace.CSpace);
            edmModel.AddItem(
                EntityType.Create(
                    "TestEntity", "TestNamespace", DataSpace.CSpace,
                    new string[0], new EdmMember[0], new MetadataProperty[0]));
            new EdmxHelper(edmx).UpdateConceptualModels(edmModel, "modelNamespace");

            var conceptualModelsElements =
                edmx.Descendants(EdmxV3Namespace + "ConceptualModels").Single();

            Assert.Equal(1, conceptualModelsElements.Elements().Count());
            Assert.Equal(
                XNamespace.None + "dummy",
                conceptualModelsElements.Elements().Single().Name);
        }
示例#29
0
        public void Can_add_remove_enum_type()
        {
            var model = new EdmModel(DataSpace.SSpace);
            var enumType = new EnumType { DataSpace = DataSpace.SSpace };

            model.AddItem(enumType);

            Assert.True(model.EnumTypes.Contains(enumType));
            Assert.True(model.NamespaceItems.Contains(enumType));

            model.RemoveItem(enumType);

            Assert.False(model.EnumTypes.Contains(enumType));
            Assert.False(model.NamespaceItems.Contains(enumType));
        }
        public void CollectStoreModelErrors_returns_errors_on_model_items()
        {
            var edmSchemaError = new EdmSchemaError("msg", 42, EdmSchemaErrorSeverity.Error);
            var errorMetadataProperty =
                MetadataProperty.Create(
                    MetadataItemHelper.SchemaErrorsMetadataPropertyName,
                    TypeUsage.CreateDefaultTypeUsage(
                        PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType()),
                    new List<EdmSchemaError> { edmSchemaError });

            var entityType =
                EntityType.Create(
                    "foo", "bar", DataSpace.SSpace, new string[0], new EdmMember[0],
                    new[] { errorMetadataProperty });

            var model = new EdmModel(DataSpace.SSpace);
            model.AddItem(entityType);

            var schemaErrors = ModelGenerator.CollectStoreModelErrors(model);

            Assert.NotNull(schemaErrors);
            Assert.Equal(1, schemaErrors.Count);
            Assert.Same(edmSchemaError, schemaErrors.Single());
        }
        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 GenerateFunctions_does_not_add_ivalid_functions_to_mapping_context()
            {
                var returnParameter =
                    FunctionParameter.Create(
                        "ReturnType",
                        PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32),
                        ParameterMode.ReturnValue);

                var storeFunction =
                    EdmFunction.Create(
                        "foo",
                        "bar",
                        DataSpace.SSpace,
                        new EdmFunctionPayload { ReturnParameters = new[] { returnParameter } },
                        null);

                var storeModel = new EdmModel(DataSpace.SSpace);
                storeModel.AddItem(storeFunction);

                var mappingContext = new SimpleMappingContext(new EdmModel(DataSpace.SSpace), true);
                Assert.Empty(
                    CreateOneToOneMappingBuilder()
                        .GenerateFunctions(
                            mappingContext,
                            storeModel,
                            new UniqueIdentifierService(),
                            new UniqueIdentifierService()));

                Assert.Equal(1, mappingContext.Errors.Count);
                Assert.Empty(mappingContext.MappedStoreFunctions());
            }
        public void Validation_error_not_reported_for_types_marked_as_invalid()
        {
            var invalidAttribute =
                MetadataProperty.Create(
                    "EdmSchemaInvalid",
                    TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                    true);

            var model = new EdmModel(DataSpace.SSpace);
            model.AddItem(
                EntityType.Create("E", "N", DataSpace.SSpace, new string[0], new EdmMember[0], new[] { invalidAttribute }));

            using (var writer = XmlWriter.Create(new StringBuilder()))
            {
                var ssdlSerializer = new SsdlSerializer();
                ssdlSerializer.OnError += (_, e) => { throw new Exception("Should not be invoked."); };

                Assert.True(ssdlSerializer.Serialize(model, "N", "invName", "42", writer));
            }
        }
        public void CollectStoreModelErrors_returns_empty_error_list_for_model_without_errors()
        {
            var entityType =
                EntityType.Create("foo", "bar", DataSpace.SSpace, new string[0], new EdmMember[0], null);

            var model = new EdmModel(DataSpace.SSpace);
            model.AddItem(entityType);

            var schemaErrors = ModelGenerator.CollectStoreModelErrors(model);

            Assert.NotNull(schemaErrors);
            Assert.Empty(schemaErrors);
        }
示例#35
0
        public void Can_add_remove_function()
        {
            var model = new EdmModel(DataSpace.SSpace);
            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());

            model.AddItem(function);

            Assert.True(model.Functions.Contains(function));
            Assert.True(model.NamespaceItems.Contains(function));

            model.RemoveItem(function);

            Assert.False(model.Functions.Contains(function));
            Assert.False(model.NamespaceItems.Contains(function));
        }
        private EdmModel CreateTestModel()
        {
            var model = new EdmModel(DataSpace.SSpace);

            var sqlManifest = new SqlProviderManifest("2008");
            var stringTypeUsage = sqlManifest.GetStoreType(
                TypeUsage.CreateDefaultTypeUsage(
                    PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));

            var complexType = new ComplexType("Entity", "Unicorns420", DataSpace.SSpace);
            complexType.AddMember(new EdmProperty("NullableProperty", stringTypeUsage) { Nullable = true });
            complexType.AddMember(new EdmProperty("NonNullableProperty", stringTypeUsage) { Nullable = false });
            model.AddItem(complexType);

            return model;
        }
示例#37
0
        public void UpdateStorageModel_add_errors_if_validation_fails()
        {
            var edmx = XDocument.Parse(EdmxTemplate);

            var storeModel = new EdmModel(DataSpace.SSpace);
            var providerInfo = new DbProviderInfo("ProviderInvariantName", "20081");

            storeModel.AddItem(
                EntityType.Create("entities", "ns", DataSpace.SSpace, new string[0], new EdmMember[0], null));

            var errors = new List<EdmSchemaError>();
            new EdmxHelper(edmx)
                .UpdateStorageModels(storeModel, "myNamespace", providerInfo, errors);

            Assert.NotEmpty(errors);
        }
        public void GenerateModel_combines_store_model_and_mapping_errors()
        {
            var storeModelError = new EdmSchemaError("storeError", 42, EdmSchemaErrorSeverity.Error);
            var errorMetadataProperty =
                MetadataProperty.Create(
                    MetadataItemHelper.SchemaErrorsMetadataPropertyName,
                    TypeUsage.CreateDefaultTypeUsage(
                        PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String).GetCollectionType()),
                    new List<EdmSchemaError> { storeModelError });

            var entityType =
                EntityType.Create(
                    "foo", "bar", DataSpace.SSpace, new string[0], new EdmMember[0],
                    new[] { errorMetadataProperty });

            var storeModel = new EdmModel(DataSpace.SSpace);
            storeModel.AddItem(entityType);

            var mappingContext = new SimpleMappingContext(storeModel, true);
            mappingContext.AddMapping(
                storeModel.Containers.Single(),
                EntityContainer.Create("C", DataSpace.CSpace, null, null, null));
            mappingContext.Errors.Add(new EdmSchemaError("mappingError", 911, EdmSchemaErrorSeverity.Warning));

            var mockModelGenerator = new Mock<ModelGenerator>(new ModelBuilderSettings(), "storeNamespace");
            mockModelGenerator
                .Setup(g => g.CreateStoreModel())
                .Returns(() => storeModel);

            mockModelGenerator
                .Setup(g => g.CreateMappingContext(It.IsAny<EdmModel>()))
                .Returns(() => mappingContext);

            var errors = new List<EdmSchemaError>();
            mockModelGenerator.Object.GenerateModel(errors);
            Assert.Equal(new[] { storeModelError, mappingContext.Errors.Single() }, errors);
        }