Ejemplo n.º 1
0
        public void ImportXmlType()
        {
            XsdDataContractImporter importer = SchemaUtils.CreateImporterWithDefaultOptions();

            importer.Options.ImportXmlType = true;
            importer.Import(SchemaUtils.PositiveSchemas, SchemaUtils.ValidTypeNames[0]);
            _output.WriteLine(SchemaUtils.DumpCode(importer.CodeCompileUnit));
            Assert.True(importer.Options.ImportXmlType);
        }
Ejemplo n.º 2
0
        public void Namespaces(string dcns, string clrns)
        {
            XsdDataContractImporter importer = SchemaUtils.CreateImporterWithDefaultOptions();

            Assert.NotNull(importer.Options.Namespaces);
            Assert.Empty(importer.Options.Namespaces);

            importer.Options.Namespaces.Add(dcns, clrns);
            importer.Import(SchemaUtils.PositiveSchemas, SchemaUtils.ValidTypeNames[0]);
            _output.WriteLine(SchemaUtils.DumpCode(importer.CodeCompileUnit));
        }
Ejemplo n.º 3
0
        public void CodeProvider()
        {
            XsdDataContractImporter importer     = SchemaUtils.CreateImporterWithDefaultOptions();
            CodeDomProvider         codeProvider = CodeDomProvider.CreateProvider("csharp");

            importer.Options.CodeProvider = codeProvider;
            Console.WriteLine(importer.Options.CodeProvider.GetType().FullName);
            importer.Import(SchemaUtils.PositiveSchemas, SchemaUtils.ValidTypeNames[0]);
            _output.WriteLine(SchemaUtils.DumpCode(importer.CodeCompileUnit));
            Assert.Equal(codeProvider, importer.Options.CodeProvider);
        }
Ejemplo n.º 4
0
        public void Import(Action <XsdDataContractImporter> import, int codeLength = -1)
        {
            XsdDataContractImporter importer = SchemaUtils.CreateImporterWithDefaultOptions();

            import(importer);
            string code = SchemaUtils.DumpCode(importer.CodeCompileUnit);

            _output.WriteLine(code);
            if (codeLength >= 0)
            {
                Assert.Equal(codeLength, code.Length);
            }
        }
Ejemplo n.º 5
0
        public void CanImport(bool expectedResult, Func <XsdDataContractImporter, bool> canImport, Type expectedExceptionType = null, string msg = null)
        {
            XsdDataContractImporter importer = SchemaUtils.CreateImporterWithDefaultOptions();

            if (expectedExceptionType == null)
            {
                Assert.Equal(expectedResult, canImport(importer));
            }
            else
            {
                var ex = Assert.Throws(expectedExceptionType, () => canImport(importer));

                if (!string.IsNullOrEmpty(msg))
                {
                    Assert.Equal(msg, ex.Message);
                }
            }
        }
Ejemplo n.º 6
0
        public void DefaultOptions()
        {
            XsdDataContractImporter importer = SchemaUtils.CreateImporterWithDefaultOptions();

            Assert.NotNull(importer);
            Assert.NotNull(importer.Options);
            Assert.False(importer.Options.EnableDataBinding);
            Assert.False(importer.Options.GenerateInternal);
            Assert.False(importer.Options.GenerateSerializable);
            Assert.False(importer.Options.ImportXmlType);
            Assert.Null(importer.Options.CodeProvider);
            Assert.NotNull(importer.Options.Namespaces);
            Assert.Empty(importer.Options.Namespaces);
            Assert.NotNull(importer.Options.ReferencedCollectionTypes);
            Assert.Empty(importer.Options.ReferencedCollectionTypes);
            Assert.NotNull(importer.Options.ReferencedTypes);
            Assert.Empty(importer.Options.ReferencedTypes);
            Assert.Null(importer.Options.DataContractSurrogate);
        }
Ejemplo n.º 7
0
        public void ReferencedTypes(XmlSchemaSet schemas, XmlQualifiedName qname, Type[] referencedTypes, Type expectedExceptionType = null, string msg = null)
        {
            XsdDataContractImporter importer = SchemaUtils.CreateImporterWithDefaultOptions();

            for (int i = 0; i < referencedTypes.Length; i++)
            {
                importer.Options.ReferencedTypes.Add(referencedTypes[i]);
            }

            if (expectedExceptionType == null)
            {
                importer.Import(schemas, qname);
                _output.WriteLine(SchemaUtils.DumpCode(importer.CodeCompileUnit));
            }
            else
            {
                var ex = Assert.Throws(expectedExceptionType, () => importer.Import(schemas, qname));

                if (!string.IsNullOrEmpty(msg))
                {
                    Assert.StartsWith(msg, ex.Message);
                }
            }
        }