Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 2
0
        public void Serialize_without_schemaNamespace_returns_false_if_multiple_NamespaceNames()
        {
            var mockModel = new Mock <EdmModel>(DataSpace.SSpace, XmlConstants.SchemaVersionLatest);

            mockModel.Setup(m => m.NamespaceNames).Returns(new string[2]);
            var mockWriter = new Mock <XmlWriter>();

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

            serializer.OnError += (_, e) => validationErrors.Add(e);
            Assert.False(serializer.Serialize(
                             mockModel.Object,
                             ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName,
                             ProviderRegistry.Sql2008_ProviderInfo.ProviderManifestToken,
                             mockWriter.Object,
                             false));
            Assert.Equal(1, validationErrors.Count());
            Assert.Equal(Strings.Serializer_OneNamespaceAndOneContainer, validationErrors[0].ErrorMessage);
            mockWriter.Verify(m => m.WriteStartDocument(), Times.Never());
        }
        private static void ValidateModel(DbModel model, List<EdmSchemaError> errors)
        {
            var settings = new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Fragment };
            using (var writer = XmlWriter.Create(new StringBuilder(), settings))
            {
                var ssdlSerializer = new SsdlSerializer();
                ssdlSerializer.OnError +=
                    CreateOnErrorEventHandler(errors, ErrorCodes.GenerateModelFromDbReverseEngineerStoreModelFailed);

                ssdlSerializer.Serialize(
                    model.StoreModel,
                    model.ProviderInfo.ProviderInvariantName,
                    model.ProviderInfo.ProviderManifestToken,
                    writer);

                var csdlSerializer = new CsdlSerializer();
                csdlSerializer.OnError +=
                    CreateOnErrorEventHandler(errors, ErrorCodes.GenerateModelFromDbInvalidConceptualModel);

                csdlSerializer.Serialize(model.ConceptualModel, writer);

                new MslSerializerWrapper().Serialize(model, writer);
            }
        }
Ejemplo n.º 4
0
        private static List<DataModelErrorEventArgs> SerializeAndValidateSsdl(this EdmModel model, XmlWriter writer)
        {
            var providerInfoProperty = typeof(EdmModel).GetProperty("ProviderInfo", BindingFlags.Instance | BindingFlags.NonPublic);
            var providerInfo = (DbProviderInfo)providerInfoProperty.GetValue(model);

            var validationErrors = new List<DataModelErrorEventArgs>();

            var serializer = new SsdlSerializer();
            serializer.OnError += (_, e) => validationErrors.Add(e);
            serializer.Serialize(model, providerInfo.ProviderInvariantName, providerInfo.ProviderManifestToken, writer, true);

            return validationErrors;
        }
        public void Serialize_with_schemaNamespace_returns_false_if_multiple_NamespaceNames()
        {
            var mockModel = new Mock<EdmModel>(DataSpace.SSpace, XmlConstants.SchemaVersionLatest);
            mockModel.Setup(m => m.NamespaceNames).Returns(new string[2]);
            var mockWriter = new Mock<XmlWriter>();

            var validationErrors = new List<DataModelErrorEventArgs>(); 
            var serializer = new SsdlSerializer();
            serializer.OnError += (_, e) => validationErrors.Add(e);
            Assert.False(serializer.Serialize(
                mockModel.Object,
                "MyNamespace",
                ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName,
                ProviderRegistry.Sql2008_ProviderInfo.ProviderManifestToken,
                mockWriter.Object,
                false));
            Assert.Equal(1, validationErrors.Count());
            Assert.Equal(Strings.Serializer_OneNamespaceAndOneContainer, validationErrors[0].ErrorMessage);
            mockWriter.Verify(m => m.WriteStartDocument(), Times.Never());
        }
        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 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());
        }