コード例 #1
0
        public void ThrowsOnMultipleConstructors()
        {
            var ex = Assert.Throws <SchemaGenerationException>(
                () => XMLSchemaGenerator.GenerateSchema(typeof(MultipleConstructors), "Type"));

            Assert.Equal(typeof(MultipleConstructors), ex.TargetType);
            Assert.Equal("Type must have a single public constructor.", ex.Message);
        }
コード例 #2
0
        public void GenerateXMLSchemaForTypeWithDescription()
        {
            var expected = new XElement("Type", new XAttribute("name", "UserScoreWithDescription"), new XAttribute("description", "Type description"),
                                        new XElement("Field",
                                                     new XAttribute("name", "name"),
                                                     new XAttribute("type", "System.String")),
                                        new XElement("Field",
                                                     new XAttribute("name", "score"),
                                                     new XAttribute("type", "System.Int32"))
                                        );

            var actual = XMLSchemaGenerator.GenerateSchema(typeof(UserScoreWithDescription), "Type");

            // Comparing XElements seems problematic, so bodge it by comparing
            // the string forms.
            Assert.Equal(expected.ToString(), actual.ToString());
        }
コード例 #3
0
        public void GenerateXMLSchemaForSimpleTypeWithDefaults()
        {
            /*
             * <Type name=UserScoreWithDefaultScore">
             * <Field name="name" type="System.String" />
             * <Field name="score" type="System.Int32" default="100" />
             * </Type>
             */
            var expected = new XElement("Type", new XAttribute("name", "UserScoreWithDefaultScore"),
                                        new XElement("Field",
                                                     new XAttribute("name", "name"),
                                                     new XAttribute("type", "System.String")),
                                        new XElement("Field",
                                                     new XAttribute("name", "score"),
                                                     new XAttribute("type", "System.Int32"),
                                                     new XAttribute("default", "100"))
                                        );
            var actual = XMLSchemaGenerator.GenerateSchema(typeof(UserScoreWithDefaultScore), "Type");

            // Comparing XElements seems problematic, so bodge it by comparing
            // the string forms.
            Assert.Equal(expected.ToString(), actual.ToString());
        }
コード例 #4
0
        public void GenerateXMLSchemaForTypeContainingList()
        {
            /*
             * <Type name="UserScoreList">
             * <Field name="name" type="System.String" />
             * <Field name="scores" type="System.Collections.Generic.IReadOnlyList`1[System.Int32]" />
             * </Type>
             */

            var expected = new XElement("Type", new XAttribute("name", "UserScoreList"),
                                        new XElement("Field",
                                                     new XAttribute("name", "name"),
                                                     new XAttribute("type", "System.String")),
                                        new XElement("Field",
                                                     new XAttribute("name", "scores"),
                                                     new XAttribute("type", "System.Collections.Generic.IReadOnlyList`1[System.Int32]"))
                                        );

            var actual = XMLSchemaGenerator.GenerateSchema(typeof(UserScoreList), "Type");

            // Comparing XElements seems problematic, so bodge it by comparing
            // the string forms.
            Assert.Equal(expected.ToString(), actual.ToString());
        }
コード例 #5
0
        public void GenerateSchemaForTypeContainingComplexType()
        {
            /*
             * <Type name="TestDefaultParams">
             * <Field name="sb" type="System.SByte" default="-12" />
             * <Field name="b" type="System.Byte" default="12" />
             * <Field name="s" type="System.Int16" default="-1234" />
             * <Field name="us" type="System.UInt16" default="1234" />
             * <Field name="i" type="System.Int32" default="-12345" />
             * <Field name="ui" type="System.UInt32" default="12345" />
             * <Field name="l" type="System.Int64" default="-12345678900" />
             * <Field name="ul" type="System.UInt64" default="12345678900" />
             * <Field name="str" type="System.String" default="str" />
             * <Field name="f" type="System.Single" default="1.23" />
             * <Field name="d" type="System.Double" default="1.23" />
             * <Field name="dc" type="System.Decimal" default="1.23" />
             * <Field name="e" type="Dasher.Schema.Generation.Tests.XMLSchemaGeneratorTests+TestEnum" default="Bar" />
             * <Field name="complex" type="Dasher.Schema.Generation.Tests.XMLSchemaGeneratorTests+UserScore" default="null">
             *    <Field name="name" type="System.String" />
             *    <Field name="score" type="System.Int32" />
             * </Field>
             * <Field name="bo" type="System.Boolean" default="true" />
             * </Type>
             */

            var expected = new XElement("Type", new XAttribute("name", "TestDefaultParams"),
                                        new XElement("Field",
                                                     new XAttribute("name", "sb"),
                                                     new XAttribute("type", "System.SByte"),
                                                     new XAttribute("default", "-12")),
                                        new XElement("Field",
                                                     new XAttribute("name", "b"),
                                                     new XAttribute("type", "System.Byte"),
                                                     new XAttribute("default", "12")),
                                        new XElement("Field",
                                                     new XAttribute("name", "s"),
                                                     new XAttribute("type", "System.Int16"),
                                                     new XAttribute("default", "-1234")),
                                        new XElement("Field",
                                                     new XAttribute("name", "us"),
                                                     new XAttribute("type", "System.UInt16"),
                                                     new XAttribute("default", "1234")),
                                        new XElement("Field",
                                                     new XAttribute("name", "i"),
                                                     new XAttribute("type", "System.Int32"),
                                                     new XAttribute("default", "-12345")),
                                        new XElement("Field",
                                                     new XAttribute("name", "ui"),
                                                     new XAttribute("type", "System.UInt32"),
                                                     new XAttribute("default", "12345")),
                                        new XElement("Field",
                                                     new XAttribute("name", "l"),
                                                     new XAttribute("type", "System.Int64"),
                                                     new XAttribute("default", "-12345678900")),
                                        new XElement("Field",
                                                     new XAttribute("name", "ul"),
                                                     new XAttribute("type", "System.UInt64"),
                                                     new XAttribute("default", "12345678900")),
                                        new XElement("Field",
                                                     new XAttribute("name", "str"),
                                                     new XAttribute("type", "System.String"),
                                                     new XAttribute("default", "str")),
                                        new XElement("Field",
                                                     new XAttribute("name", "f"),
                                                     new XAttribute("type", "System.Single"),
                                                     new XAttribute("default", "1.23")),
                                        new XElement("Field",
                                                     new XAttribute("name", "d"),
                                                     new XAttribute("type", "System.Double"),
                                                     new XAttribute("default", "1.23")),
                                        new XElement("Field",
                                                     new XAttribute("name", "dc"),
                                                     new XAttribute("type", "System.Decimal"),
                                                     new XAttribute("default", "1.23")),
                                        new XElement("Field",
                                                     new XAttribute("name", "e"),
                                                     new XAttribute("type", "Dasher.Schema.Generation.Tests.XMLSchemaGeneratorTests+TestEnum"),
                                                     new XAttribute("default", "Bar")),
                                        new XElement("Field",
                                                     new XAttribute("name", "complex"),
                                                     new XAttribute("type", "Dasher.Schema.Generation.Tests.XMLSchemaGeneratorTests+UserScore"),
                                                     new XAttribute("default", "null"),
                                                     new XElement("Field",
                                                                  new XAttribute("name", "name"),
                                                                  new XAttribute("type", "System.String")),
                                                     new XElement("Field",
                                                                  new XAttribute("name", "score"),
                                                                  new XAttribute("type", "System.Int32"))
                                                     ),
                                        new XElement("Field",
                                                     new XAttribute("name", "bo"),
                                                     new XAttribute("type", "System.Boolean"),
                                                     new XAttribute("default", "true"))
                                        );
            var actual = XMLSchemaGenerator.GenerateSchema(typeof(TestDefaultParams), "Type");

            // Comparing XElements seems problematic, so bodge it by comparing
            // the string forms.
            Assert.Equal(expected.ToString(), actual.ToString());
        }