Exemplo n.º 1
0
        public void TestMap()
        {
            var uri       = container.ResourceManager().ResolveResourceURL("regression/simpleSchema.xsd");
            var schemaUri = uri.ToString();

            var model = XSDSchemaMapper.LoadAndMap(schemaUri, null, container.ResourceManager());

            Assert.That(model.Components.Count, Is.EqualTo(1));

            var simpleEvent = model.Components[0];

            VerifyComplexElement(simpleEvent, "simpleEvent", false);
            VerifySizes(simpleEvent, 0, 0, 3);

            var nested1 = simpleEvent.ComplexElements[0];

            VerifyComplexElement(nested1, "nested1", false);
            VerifySizes(nested1, 1, 2, 1);
            Assert.AreEqual("attr1", nested1.Attributes[0].Name);
            Assert.AreEqual(string.Empty, nested1.Attributes[0].Namespace);
            Assert.AreEqual(_schemaTypeString, nested1.Attributes[0].SimpleType);
            Assert.AreEqual("prop1", nested1.SimpleElements[0].Name);
            Assert.AreEqual(_schemaTypeString, nested1.SimpleElements[0].SimpleType);
            Assert.AreEqual("prop2", nested1.SimpleElements[1].Name);
            Assert.AreEqual(_schemaTypeBoolean, nested1.SimpleElements[1].SimpleType);

            var nested2 = nested1.ComplexElements[0];

            VerifyComplexElement(nested2, "nested2", false);
            VerifySizes(nested2, 0, 1, 0);
            VerifySimpleElement(nested2.SimpleElements[0], "prop3", _schemaTypeInt);

            var prop4 = simpleEvent.ComplexElements[1];

            VerifyElement(prop4, "prop4");
            VerifySizes(prop4, 1, 0, 0);
            Assert.AreEqual("attr2", prop4.Attributes[0].Name);
            Assert.AreEqual(_schemaTypeBoolean, prop4.Attributes[0].SimpleType);
            Assert.AreEqual(_schemaTypeString, prop4.OptionalSimpleType);

            var nested3 = simpleEvent.ComplexElements[2];

            VerifyComplexElement(nested3, "nested3", false);
            VerifySizes(nested3, 0, 0, 1);

            var nested4 = nested3.ComplexElements[0];

            VerifyComplexElement(nested4, "nested4", true);
            VerifySizes(nested4, 1, 4, 0);
            Assert.AreEqual("id", nested4.Attributes[0].Name);
            Assert.AreEqual(_schemaTypeId, nested4.Attributes[0].SimpleType);
            VerifySimpleElement(nested4.SimpleElements[0], "prop5", _schemaTypeString);
            VerifySimpleElement(nested4.SimpleElements[1], "prop6", _schemaTypeString);
            VerifySimpleElement(nested4.SimpleElements[2], "prop7", _schemaTypeString);
            VerifySimpleElement(nested4.SimpleElements[3], "prop8", _schemaTypeString);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Maps the specified XSD schema into the internal model for the schema.
        /// </summary>
        /// <param name="xsModel">The xs model.</param>
        /// <param name="schemaLocation">The schema location.</param>
        /// <param name="maxRecursiveDepth">The max recursive depth.</param>
        /// <returns></returns>
        private static SchemaModel Map(
            XmlSchema xsModel,
            Uri schemaLocation,
            int maxRecursiveDepth)
        {
            var mapper = new XSDSchemaMapper();

            mapper.Import(xsModel, schemaLocation);
            return(mapper.CreateModel());
        }
Exemplo n.º 3
0
        public void TestExtendedElements()
        {
            var uri       = container.ResourceManager().ResolveResourceURL("regression/schemaWithExtensions.xsd");
            var schemaUri = uri.ToString();

            var model = XSDSchemaMapper.LoadAndMap(schemaUri, null, container.ResourceManager());

            var complexEvent = model.Components[0];

            VerifyComplexElement(complexEvent, "complexEvent", false);
            VerifySizes(complexEvent, 0, 0, 1);

            var mainElement = complexEvent.ComplexElements[0];

            VerifyComplexElement(mainElement, "mainElement", false);
            VerifySizes(mainElement, 0, 0, 4);

            var baseType4 = mainElement.ComplexElements[0];

            VerifyComplexElement(baseType4, "baseType4", false);
            VerifySizes(baseType4, 0, 0, 0);

            var aType2 = mainElement.ComplexElements[1];

            VerifyComplexElement(aType2, "aType2", false);
            VerifySizes(aType2, 0, 2, 1);

            var aType3 = mainElement.ComplexElements[2];

            VerifyComplexElement(aType3, "aType3", false);
            VerifySizes(aType3, 0, 1, 2);

            var aType3baseType4 = aType3.ComplexElements[0];

            VerifyComplexElement(aType3baseType4, "baseType4", false);
            VerifySizes(aType3baseType4, 0, 0, 0);

            var aType3type2 = aType3.ComplexElements[1];

            VerifyComplexElement(aType3type2, "aType2", false);
            VerifySizes(aType3type2, 0, 2, 1);

            var aType4 = mainElement.ComplexElements[3];

            VerifyComplexElement(aType4, "aType4", false);
            VerifySizes(aType4, 0, 0, 1);
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            var schemaUrl  = container.ResourceManager().ResolveResourceURL("regression/simpleSchema.xsd");
            var configNoNS = new ConfigurationCommonEventTypeXMLDOM();

            configNoNS.IsXPathPropertyExpr = true;
            configNoNS.SchemaResource      = schemaUrl.ToString();
            configNoNS.RootElementName     = "simpleEvent";
            configNoNS.AddXPathProperty("customProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathResultType.Number);
            configNoNS.AddNamespacePrefix("ss", "samples:schemas:simpleSchema");

            var model = XSDSchemaMapper.LoadAndMap(
                schemaUrl.ToString(),
                null,
                container.ResourceManager());
            var eventTypeNoNS = new SchemaXMLEventType(
                null, configNoNS, model, null, null, null, null, null);

            using (var stream = container.ResourceManager().GetResourceAsStream("regression/simpleWithSchema.xml")) {
                var noNSDoc = new XmlDocument();
                noNSDoc.Load(stream);
                eventSchemaOne = new XMLEventBean(noNSDoc.DocumentElement, eventTypeNoNS);
            }
        }
Exemplo n.º 5
0
        public void TestMap()
        {
            Uri    uri       = _container.ResourceManager().ResolveResourceURL("regression/simpleSchema.xsd");
            String schemaUri = uri.ToString();

            SchemaModel model = XSDSchemaMapper.LoadAndMap(schemaUri, null);

            Assert.AreEqual(1, model.Components.Count);

            SchemaElementComplex component = model.Components[0];

            Assert.AreEqual("simpleEvent", component.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", component.Namespace);
            Assert.AreEqual(0, component.Attributes.Count);
            Assert.AreEqual(0, component.SimpleElements.Count);
            Assert.AreEqual(3, component.ComplexElements.Count);
            Assert.IsFalse(component.IsArray);
            Assert.IsNull(component.OptionalSimpleType);

            SchemaElementComplex nested1Element = component.ComplexElements[0];

            Assert.AreEqual("nested1", nested1Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested1Element.Namespace);
            Assert.AreEqual(1, nested1Element.Attributes.Count);
            Assert.AreEqual(2, nested1Element.SimpleElements.Count);
            Assert.AreEqual(1, nested1Element.ComplexElements.Count);
            Assert.IsFalse(nested1Element.IsArray);
            Assert.IsNull(nested1Element.OptionalSimpleType);

            var schemaTypeString  = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String);
            var schemaTypeBoolean = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean);
            var schemaTypeInteger = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Int);
            var schemaTypeId      = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Id);

            Assert.AreEqual("attr1", nested1Element.Attributes[0].Name);
            Assert.AreEqual(String.Empty, nested1Element.Attributes[0].Namespace);
            Assert.AreEqual(schemaTypeString, nested1Element.Attributes[0].SimpleType);
            Assert.AreEqual("prop1", nested1Element.SimpleElements[0].Name);
            Assert.AreEqual(schemaTypeString, nested1Element.SimpleElements[0].SimpleType);
            Assert.AreEqual("prop2", nested1Element.SimpleElements[1].Name);
            Assert.AreEqual(schemaTypeBoolean, nested1Element.SimpleElements[1].SimpleType);

            SchemaElementComplex nested2Element = nested1Element.ComplexElements[0];

            Assert.AreEqual("nested2", nested2Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested2Element.Namespace);
            Assert.AreEqual(0, nested2Element.Attributes.Count);
            Assert.AreEqual(1, nested2Element.SimpleElements.Count);
            Assert.AreEqual(0, nested2Element.ComplexElements.Count);
            Assert.IsFalse(nested2Element.IsArray);
            Assert.IsNull(nested2Element.OptionalSimpleType);

            SchemaElementSimple simpleProp3 = nested2Element.SimpleElements[0];

            Assert.AreEqual("prop3", simpleProp3.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", simpleProp3.Namespace);
            Assert.AreEqual(schemaTypeInteger, simpleProp3.SimpleType);
            Assert.IsTrue(simpleProp3.IsArray);

            SchemaElementComplex prop4Element = component.ComplexElements[1];

            Assert.AreEqual("prop4", prop4Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", prop4Element.Namespace);
            Assert.AreEqual(1, prop4Element.Attributes.Count);
            Assert.AreEqual(0, prop4Element.SimpleElements.Count);
            Assert.AreEqual(0, prop4Element.ComplexElements.Count);
            Assert.AreEqual("attr2", prop4Element.Attributes[0].Name);
            Assert.AreEqual(schemaTypeBoolean, prop4Element.Attributes[0].SimpleType);
            Assert.IsFalse(prop4Element.IsArray);
            Assert.AreEqual(schemaTypeString, prop4Element.OptionalSimpleType);

            SchemaElementComplex nested3Element = component.ComplexElements[2];

            Assert.AreEqual("nested3", nested3Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested3Element.Namespace);
            Assert.AreEqual(0, nested3Element.Attributes.Count);
            Assert.AreEqual(0, nested3Element.SimpleElements.Count);
            Assert.AreEqual(1, nested3Element.ComplexElements.Count);
            Assert.IsFalse(nested3Element.IsArray);
            Assert.IsNull(nested3Element.OptionalSimpleType);

            SchemaElementComplex nested4Element = nested3Element.ComplexElements[0];

            Assert.AreEqual("nested4", nested4Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested4Element.Namespace);
            Assert.AreEqual(1, nested4Element.Attributes.Count);
            Assert.AreEqual(1, nested4Element.SimpleElements.Count);
            Assert.AreEqual(0, nested4Element.ComplexElements.Count);
            Assert.AreEqual("id", nested4Element.Attributes[0].Name);
            Assert.AreEqual(schemaTypeId, nested4Element.Attributes[0].SimpleType);
            Assert.IsTrue(nested4Element.IsArray);
            Assert.IsNull(nested4Element.OptionalSimpleType);

            SchemaElementSimple prop5Element = nested4Element.SimpleElements[0];

            Assert.AreEqual("prop5", prop5Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", prop5Element.Namespace);
            Assert.AreEqual(schemaTypeString, prop5Element.SimpleType);
            Assert.IsTrue(prop5Element.IsArray);
        }