Exemple #1
0
        public void ReferenceTypes() // From IsReferenceTypes.cs
        {
            List <Type> types = new List <Type>()
            {
                typeof(ExporterTypesTests.Order_ContainsRef),
                typeof(ExporterTypesTests.Customers_ContainsDuplicateRefs),
                typeof(ExporterTypesTests.Student_ContainsDuplicateCollectionRefs),
                typeof(ExporterTypesTests.CircularLinkedList_ContainsBackpointingRef),
                typeof(ExporterTypesTests.RefCircularLinks_ContainsBackpointer),
                typeof(ExporterTypesTests.RefCircularNodeA_ContainsRefWithBackpointer),
                typeof(ExporterTypesTests.RefNestedNode_ContainsBackpointer),
                typeof(ExporterTypesTests.RefSimpleDataContractCycle_ContainsRefWithBackpointer),
                typeof(ExporterTypesTests.Fruit),
                typeof(ExporterTypesTests.RefApple),
                typeof(ExporterTypesTests.EdibleContainer_ContainsPolymorphicRefs),
            };

            XsdDataContractExporter exporter = new XsdDataContractExporter();
            ExportOptions           options  = new ExportOptions();

            options.KnownTypes.Add(typeof(ArrayList));
            options.KnownTypes.Add(typeof(Guid));

            exporter.Export(types);
            exporter.Export(types); // Run twice, to ensure that types are not re-exported

            string schemas = SchemaUtils.DumpSchema(exporter.Schemas);

            _output.WriteLine(schemas);
            _output.WriteLine($"----------------- {exporter.Schemas.Count}, {exporter.Schemas.GlobalElements.Count}, {exporter.Schemas.GlobalTypes.Count}");

            Assert.Equal(3, exporter.Schemas.Count);
            Assert.Equal(39, exporter.Schemas.GlobalElements.Count);
            Assert.Equal(21, exporter.Schemas.GlobalTypes.Count);

            SchemaUtils.OrderedContains(@"<xs:schema xmlns:tns=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Xml.XsdDataContractExporterTests"" xmlns:ser=""http://schemas.microsoft.com/2003/10/Serialization/"" elementFormDefault=""qualified"" targetNamespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Xml.XsdDataContractExporterTests"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:import namespace=""http://schemas.microsoft.com/2003/10/Serialization/"" />", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Order_ContainsRef"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCustomer"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Customers_ContainsDuplicateRefs"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Student_ContainsDuplicateCollectionRefs"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefGrades"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.CircularLinkedList_ContainsBackpointingRef"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefNode"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCircularLinks_ContainsBackpointer"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCircularNodeA_ContainsRefWithBackpointer"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefCircularNodeB_ContainsRefWithBackpointer"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefNestedNode_ContainsBackpointer"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefSimpleDataContractCycle_ContainsRefWithBackpointer"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefSimpleDataContractCycleNextLink"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Fruit"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefEdibleItem"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.RefApple"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.EdibleContainer_ContainsPolymorphicRefs"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:schema targetNamespace=""http://www.w3.org/2001/XMLSchema"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">", ref schemas);
        }
Exemple #2
0
        public void TypesTest()
        {
            var types = new List <Type>()
            {
                typeof(DataContractTypes.Person1),
                typeof(DataContractTypes.Person2),
                typeof(ExporterTypesTests.Group),
                typeof(ExporterTypesTests.NoDataContract),
                typeof(ExporterTypesTests.DataContractWithValidMember),
                typeof(ExporterTypesTests.DataContractWithValidMember),
                typeof(ExporterTypesTests.PersonInfo),
            };

            XsdDataContractExporter exporter = new XsdDataContractExporter();
            ExportOptions           options  = new ExportOptions();

            options.KnownTypes.Add(typeof(ArrayList));
            options.KnownTypes.Add(typeof(Guid));
            exporter.Options = options;

            exporter.Export(types);
            exporter.Export(types); // Run twice, to ensure that types are not re-exported

            string schemas = SchemaUtils.DumpSchema(exporter.Schemas);

            _output.WriteLine(schemas);
            _output.WriteLine($"----------------- {exporter.Schemas.Count}, {exporter.Schemas.GlobalElements.Count}, {exporter.Schemas.GlobalTypes.Count}");

            Assert.Equal(5, exporter.Schemas.Count);
            Assert.Equal(36, exporter.Schemas.GlobalElements.Count);
            Assert.Equal(18, exporter.Schemas.GlobalTypes.Count);

            SchemaUtils.OrderedContains(@"<xs:schema xmlns:tns=""http://schemas.datacontract.org/2004/07/SerializableTypes.XsdDataContractExporterTests"" elementFormDefault=""qualified"" targetNamespace=""http://schemas.datacontract.org/2004/07/SerializableTypes.XsdDataContractExporterTests"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""DataContractTypes.Person1"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""DataContractTypes.Person1"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:schema xmlns:tns=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Xml.XsdDataContractExporterTests"" elementFormDefault=""qualified"" targetNamespace=""http://schemas.datacontract.org/2004/07/System.Runtime.Serialization.Xml.XsdDataContractExporterTests"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:import namespace=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"" />", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Group"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ArrayOfExporterTypesTests.Person"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Person"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Employee"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Admin"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Architect"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.Engineer"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.NoDataContract"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.DataContractWithValidMember"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.PersonInfo"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:complexType name=""ExporterTypesTests.InnerPersonCollection"">", ref schemas);
            SchemaUtils.OrderedContains(@"<xs:schema xmlns:tns=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"" elementFormDefault=""qualified"" targetNamespace=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">", ref schemas);
        }
Exemple #3
0
        public void Export(string testname, Action <XsdDataContractExporter> export, Action <string, XmlSchemaSet> schemaCheck = null)
        {
            _output.WriteLine($"=============== {testname} ===============");
            XsdDataContractExporter exporter = new XsdDataContractExporter();

            export(exporter);

            string schemas = SchemaUtils.DumpSchema(exporter.Schemas);

            _output.WriteLine("Count = " + exporter.Schemas.Count);
            _output.WriteLine(schemas);

            // When checking schema count, be sure to include the "Serialization" schema - which is omitted from 'DumpSchema' - as
            // well as the XmlSchema, both of which are the base from which all further schemas build.
            if (schemaCheck != null)
            {
                schemaCheck(schemas, exporter.Schemas);
            }

            Assert.True(schemas.Length > 0);
        }
Exemple #4
0
        public void SurrogateProvider(Type type, ISerializationSurrogateProvider surrogate, Action <string, XmlSchemaSet> schemaCheck = null)
        {
            ExportOptions options = new ExportOptions()
            {
                DataContractSurrogate = surrogate
            };
            XsdDataContractExporter exporter = new XsdDataContractExporter()
            {
                Options = options
            };

            exporter.Export(type);
            string schema = SchemaUtils.DumpSchema(exporter.Schemas);

            _output.WriteLine(schema);

            if (schemaCheck != null)
            {
                schemaCheck(schema, exporter.Schemas);
            }
        }