AssertDataSet() public method

public AssertDataSet ( string label, DataSet ds, string name, int tableCount, int relCount ) : void
label string
ds DataSet
name string
tableCount int
relCount int
return void
Beispiel #1
0
        public void SingleChild()
        {
            DataSet ds = GetDataSet(_xml5, null);

            DataSetAssertion.AssertDataSet("ds", ds, "NewDataSet", 1, 0);
            DataTable dt = ds.Tables[0];

            DataSetAssertion.AssertDataTable("dt", dt, "root", 1, 0, 0, 0, 0, 0);
            DataSetAssertion.AssertDataColumn("col", dt.Columns[0], "child", true, false, 0, 1, "child", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);

            ds = GetDataSet(_xml6, null);
            DataSetAssertion.AssertDataSet("ds", ds, "NewDataSet", 1, 0);
            dt = ds.Tables[0];
            DataSetAssertion.AssertDataTable("dt", dt, "root", 1, 0, 0, 0, 0, 0);
            DataSetAssertion.AssertDataColumn("col", dt.Columns[0], "col1", true, false, 0, 1, "col1", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
        }
Beispiel #2
0
        public void SignificantWhitespaceIgnored2()
        {
            // To make sure, create pure significant whitespace element
            // using XmlNodeReader (that does not have xml:space attribute
            // column).
            DataSet     ds  = new DataSet();
            XmlDocument doc = new XmlDocument();

            doc.AppendChild(doc.CreateElement("root"));
            doc.DocumentElement.AppendChild(doc.CreateSignificantWhitespace
                                                ("      \n\n"));
            XmlReader xr = new XmlNodeReader(doc);

            ds.InferXmlSchema(xr, null);
            DataSetAssertion.AssertDataSet("pure_whitespace", ds, "root", 0, 0);
        }
Beispiel #3
0
        private void ReadTest1Check(DataSet ds)
        {
            DataSetAssertion.AssertDataSet("dataset", ds, "NewDataSet", 2, 1);
            DataSetAssertion.AssertDataTable("tbl1", ds.Tables[0], "Table1", 3, 0, 0, 1, 1, 0);
            DataSetAssertion.AssertDataTable("tbl2", ds.Tables[1], "Table2", 3, 0, 1, 0, 1, 0);

            DataRelation rel = ds.Relations[0];

            DataSetAssertion.AssertDataRelation("rel", rel, "Rel1", false,
                                                new string[] { "Column1_3" },
                                                new string[] { "Column2_1" }, true, true);
            DataSetAssertion.AssertUniqueConstraint("uc", rel.ParentKeyConstraint,
                                                    "Constraint1", false, new string[] { "Column1_3" });
            DataSetAssertion.AssertForeignKeyConstraint("fk", rel.ChildKeyConstraint, "Rel1",
                                                        AcceptRejectRule.None, Rule.Cascade, Rule.Cascade,
                                                        new string[] { "Column2_1" },
                                                        new string[] { "Column1_3" });
        }
Beispiel #4
0
        public void TwoElementTable()
        {
            // FIXME: Also test ReadXml (, XmlReadMode.InferSchema) and
            // make sure that ReadXml() stores DataRow to el1 (and maybe to others)
            DataSet ds = GetDataSet(_xml15, null);

            DataSetAssertion.AssertDataSet("ds", ds, "root", 2, 0);

            DataTable dt = ds.Tables[0];

            DataSetAssertion.AssertDataTable("dt", dt, "table1", 2, 0, 0, 0, 0, 0);
            DataSetAssertion.AssertDataColumn("col1_1", dt.Columns[0], "col1_1", true, false, 0, 1, "col1_1", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("col1_2", dt.Columns[1], "col1_2", true, false, 0, 1, "col1_2", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);

            dt = ds.Tables[1];
            DataSetAssertion.AssertDataTable("dt", dt, "table2", 2, 0, 0, 0, 0, 0);
            DataSetAssertion.AssertDataColumn("col2_1", dt.Columns[0], "col2_1", true, false, 0, 1, "col2_1", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("col2_2", dt.Columns[1], "col2_2", true, false, 0, 1, "col2_2", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);
        }
Beispiel #5
0
        public void SingleElement()
        {
            DataSet ds = GetDataSet(_xml1, null);

            DataSetAssertion.AssertDataSet("xml1", ds, "root", 0, 0);

            ds = GetDataSet(_xml4, null);
            DataSetAssertion.AssertDataSet("xml4", ds, "root", 0, 0);

            // namespaces
            ds = GetDataSet(_xml14, null);
            DataSetAssertion.AssertDataSet("xml14", ds, "root", 0, 0);
            Assert.Equal(string.Empty, ds.Prefix);
            Assert.Equal("urn:foo", ds.Namespace);

            ds = GetDataSet(_xml17, null);
            DataSetAssertion.AssertDataSet("xml17", ds, "root", 0, 0);
            Assert.Equal("urn:foo", ds.Namespace);
        }
Beispiel #6
0
        public void IsDataSetOnLocalElementIgnored()
        {
            string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
    <xs:element name='Root' type='unusedType'>
    </xs:element>
    <xs:complexType name='unusedType'>
        <xs:sequence>
            <xs:element name='Child' type='xs:string' msdata:IsDataSet='True' />
        </xs:sequence>
    </xs:complexType>
</xs:schema>";

            // msdata:IsDataSet does not affect even if the value is invalid
            string xs = string.Format(xsbase, "true");

            var ds = new DataSet();

            ds.ReadXmlSchema(new StringReader(xs));
            // Child should not be regarded as DataSet element
            DataSetAssertion.AssertDataSet("ds", ds, "NewDataSet", 1, 0);
        }
Beispiel #7
0
        public void TestSampleFileSimpleTables()
        {
            var ds = new DataSet();

            ds.Tables.Add(new DataTable("foo"));
            ds.Tables[0].ReadXmlSchema(new StringReader(
                                           @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
                <xs:element name='foo' type='ct' />
                <xs:complexType name='ct'>
                  <xs:simpleContent>
                    <xs:extension base='xs:integer'>
                      <xs:attribute name='attr' />
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
                </xs:schema>"));
            DataSetAssertion.AssertDataSet("005", ds, "NewDataSet", 1, 0);
            DataTable dt = ds.Tables[0];

            DataSetAssertion.AssertDataTable("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
            DataSetAssertion.AssertDataColumn("attr", dt.Columns[0], "attr", true, false, 0, 1, "attr", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("text", dt.Columns[1], "foo_text", false, false, 0, 1, "foo_text", MappingType.SimpleContent, typeof(long), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);

            ds = new DataSet();
            ds.Tables.Add(new DataTable("foo"));
            ds.Tables[0].ReadXmlSchema(new StringReader(
                                           @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
                    <xs:element name='foo' type='st' />
                    <xs:complexType name='st'>
                      <xs:attribute name='att1' />
                      <xs:attribute name='att2' type='xs:int' default='2' />
                    </xs:complexType>
                </xs:schema>"));
            DataSetAssertion.AssertDataSet("006", ds, "NewDataSet", 1, 0);
            dt = ds.Tables[0];
            DataSetAssertion.AssertDataTable("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
            DataSetAssertion.AssertDataColumn("att1", dt.Columns["att1"], "att1", true, false, 0, 1, "att1", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, /*0*/ -1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("att2", dt.Columns["att2"], "att2", true, false, 0, 1, "att2", MappingType.Attribute, typeof(int), 2, string.Empty, -1, string.Empty, /*1*/ -1, string.Empty, false, false);
        }
Beispiel #8
0
        public void ConflictColumnTable()
        {
            DataSet ds = GetDataSet(_xml19, null);

            DataSetAssertion.AssertDataSet("ds", ds, "set", 2, 1);

            DataTable dt = ds.Tables[0];

            DataSetAssertion.AssertDataTable("dt", dt, "table", 1, 0, 0, 1, 1, 1);
            DataSetAssertion.AssertDataColumn("table_Id", dt.Columns[0], "table_Id", false, true, 0, 1, "table_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, true);

            dt = ds.Tables[1];
            DataSetAssertion.AssertDataTable("dt", dt, "col", 2, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("table_refId", dt.Columns["table_Id"], "table_Id", true, false, 0, 1, "table_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, /*0*/ -1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("another_col", dt.Columns["another_col"], "another_col", true, false, 0, 1, "another_col", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, /*1*/ -1, string.Empty, false, false);

            DataRelation dr = ds.Relations[0];

            DataSetAssertion.AssertDataRelation("rel", dr, "table_col", true, new string[] { "table_Id" }, new string[] { "table_Id" }, true, true);
            DataSetAssertion.AssertUniqueConstraint("uniq", dr.ParentKeyConstraint, "Constraint1", true, new string[] { "table_Id" });
            DataSetAssertion.AssertForeignKeyConstraint("fkey", dr.ChildKeyConstraint, "table_col", AcceptRejectRule.None, Rule.Cascade, Rule.Cascade, new string[] { "table_Id" }, new string[] { "table_Id" });
        }
Beispiel #9
0
        public void ComplexElementAttributeTable1()
        {
            // FIXME: Also test ReadXml (, XmlReadMode.InferSchema) and
            // make sure that ReadXml() stores DataRow to el1 (and maybe to others)
            DataSet ds = GetDataSet(_xml9, null);

            DataSetAssertion.AssertDataSet("ds", ds, "NewDataSet", 4, 3);
            DataTable dt = ds.Tables[0];

            DataSetAssertion.AssertDataTable("dt1", dt, "el1", 3, 0, 0, 1, 1, 1);
            DataSetAssertion.AssertDataColumn("el1_Id", dt.Columns[0], "el1_Id", false, true, 0, 1, "el1_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, true);
            DataSetAssertion.AssertDataColumn("el1_attr1", dt.Columns[1], "attr1", true, false, 0, 1, "attr1", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el1_attrA", dt.Columns[2], "attrA", true, false, 0, 1, "attrA", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 2, string.Empty, false, false);

            dt = ds.Tables[1];
            DataSetAssertion.AssertDataTable("dt2", dt, "el2", 6, 0, 1, 2, 2, 1);
            DataSetAssertion.AssertDataColumn("el2_Id", dt.Columns[0], "el2_Id", false, true, 0, 1, "el2_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, true);
            DataSetAssertion.AssertDataColumn("el2_col2", dt.Columns[1], "column2", true, false, 0, 1, "column2", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el2_col3", dt.Columns[2], "column3", true, false, 0, 1, "column3", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 2, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el2_attr2", dt.Columns[3], "attr2", true, false, 0, 1, "attr2", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 3, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el2_attrB", dt.Columns[4], "attrB", true, false, 0, 1, "attrB", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 4, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el2_el1Id", dt.Columns[5], "el1_Id", true, false, 0, 1, "el1_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 5, string.Empty, false, false);

            dt = ds.Tables[2];
            DataSetAssertion.AssertDataTable("dt3", dt, "el3", 4, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("el3_attr3", dt.Columns[0], "attr3", true, false, 0, 1, "attr3", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el3_attrC", dt.Columns[1], "attrC", true, false, 0, 1, "attrC", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el3_Text", dt.Columns[2], "el3_Text", true, false, 0, 1, "el3_Text", MappingType.SimpleContent, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 2, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el3_el2Id", dt.Columns[3], "el2_Id", true, false, 0, 1, "el2_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 3, string.Empty, false, false);

            dt = ds.Tables[3];
            DataSetAssertion.AssertDataTable("dt4", dt, "el4", 4, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("el3_attr4", dt.Columns[0], "attr4", true, false, 0, 1, "attr4", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el4_attrD", dt.Columns[1], "attrD", true, false, 0, 1, "attrD", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el4_Text", dt.Columns[2], "el4_Text", true, false, 0, 1, "el4_Text", MappingType.SimpleContent, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 2, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("el4_el2Id", dt.Columns[3], "el2_Id", true, false, 0, 1, "el2_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 3, string.Empty, false, false);
        }
Beispiel #10
0
        public void TestMoreThanOneRepeatableColumns()
        {
            var ds = new DataSet();

            ds.ReadXmlSchema(new StringReader(
                                 @"<xsd:schema xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
                    <xsd:element name=""root"">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name=""x"" maxOccurs=""2"" />
                                <xsd:element ref=""y"" maxOccurs=""unbounded"" />
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name=""y"" />
                </xsd:schema>"));
            DataSetAssertion.AssertDataSet("014", ds, "NewDataSet", 3, 2);

            DataTable dt = ds.Tables[0];

            DataSetAssertion.AssertDataTable("parent", dt, "root", 1, 0, 0, 2, 1, 1);
            DataSetAssertion.AssertDataColumn("key", dt.Columns[0], "root_Id", false, true, 0, 1, "root_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, true);

            dt = ds.Tables[1];
            DataSetAssertion.AssertDataTable("repeated", dt, "x", 2, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("data_1", dt.Columns[0], "x_Column", false, false, 0, 1, "x_Column", MappingType.SimpleContent, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("refkey_1", dt.Columns[1], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);

            dt = ds.Tables[2];
            DataSetAssertion.AssertDataTable("repeated", dt, "y", 2, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("data", dt.Columns[0], "y_Column", false, false, 0, 1, "y_Column", MappingType.SimpleContent, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("refkey", dt.Columns[1], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);

            DataSetAssertion.AssertDataRelation("rel", ds.Relations[0], "root_x", true, new string[] { "root_Id" }, new string[] { "root_Id" }, true, true);

            DataSetAssertion.AssertDataRelation("rel", ds.Relations[1], "root_y", true, new string[] { "root_Id" }, new string[] { "root_Id" }, true, true);
        }
Beispiel #11
0
        public void UnusedComplexTypesIgnored()
        {
            string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
    <xs:element name='Root'>
        <xs:complexType>
            <xs:sequence>
                <xs:element name='Child' type='xs:string' />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name='unusedType'>
        <xs:sequence>
            <xs:element name='Orphan' type='xs:string' />
        </xs:sequence>
    </xs:complexType>
</xs:schema>";

            var ds = new DataSet();

            ds.ReadXmlSchema(new StringReader(xs));
            // Here "unusedType" table is never imported.
            DataSetAssertion.AssertDataSet("ds", ds, "hoge", 1, 0);
            DataSetAssertion.AssertDataTable("dt", ds.Tables[0], "Root", 1, 0, 0, 0, 0, 0);
        }
Beispiel #12
0
        public void SuspiciousDataSetElement()
        {
            string schema = @"<?xml version='1.0'?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
    <xsd:attribute name='foo' type='xsd:string'/>
    <xsd:attribute name='bar' type='xsd:string'/>
    <xsd:complexType name='attRef'>
        <xsd:attribute name='att1' type='xsd:int'/>
        <xsd:attribute name='att2' type='xsd:string'/>
    </xsd:complexType>
    <xsd:element name='doc'>
        <xsd:complexType>
            <xsd:choice>
                <xsd:element name='elem' type='attRef'/>
            </xsd:choice>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>";
            var    ds     = new DataSet();

            ds.ReadXmlSchema(new StringReader(schema));
            DataSetAssertion.AssertDataSet("ds", ds, "doc", 1, 0);
            DataSetAssertion.AssertDataTable("table", ds.Tables[0], "elem", 2, 0, 0, 0, 0, 0);
        }
Beispiel #13
0
        public void IgnoreSchemaShouldFillData()
        {
            // no such dataset
            string xml1 = "<set><tab><col>test</col></tab></set>";
            // no wrapper element
            string xml2 = "<tab><col>test</col></tab>";
            // no such table
            string xml3 = "<tar><col>test</col></tar>";
            var ds = new DataSet();
            DataTable dt = new DataTable("tab");
            ds.Tables.Add(dt);
            dt.Columns.Add("col");
            ds.ReadXml(new StringReader(xml1), XmlReadMode.IgnoreSchema);
            DataSetAssertion.AssertDataSet("ds", ds, "NewDataSet", 1, 0);
            Assert.Equal(1, dt.Rows.Count);
            dt.Clear();

            ds.ReadXml(new StringReader(xml2), XmlReadMode.IgnoreSchema);
            Assert.Equal(1, dt.Rows.Count);
            dt.Clear();

            ds.ReadXml(new StringReader(xml3), XmlReadMode.IgnoreSchema);
            Assert.Equal(0, dt.Rows.Count);
        }
Beispiel #14
0
        public void TestSampleFileComplexTables()
        {
            // Nested simple type element
            var ds = new DataSet();

            ds.ReadXmlSchema(new StringReader(
                                 @"<!-- nested tables, root references to complex type -->
                <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:foo' xmlns:x='urn:foo'>
                  <xs:element name='uno' type='x:t' />
                  <xs:complexType name='t'>
                    <xs:sequence>
                      <xs:element name='des'>
                        <xs:complexType>
                          <xs:sequence>
                            <xs:element name='tres' />
                          </xs:sequence>
                        </xs:complexType>
                      </xs:element>
                    </xs:sequence>
                  </xs:complexType>
                </xs:schema>"));
            DataSetAssertion.AssertDataSet("007", ds, "NewDataSet", 2, 1);
            DataTable dt = ds.Tables[0];

            DataSetAssertion.AssertDataTable("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);
            DataSetAssertion.AssertDataColumn("id", dt.Columns[0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, "urn:foo", 0, string.Empty, false, true);

            dt = ds.Tables[1];
            DataSetAssertion.AssertDataTable("tab2", dt, "des", 2, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("child", dt.Columns[0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("id", dt.Columns[1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);

            // External simple type element
            ds = new DataSet();
            ds.ReadXmlSchema(new StringReader(
                                 @"<!-- reference to external simple element -->
                <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:foo' xmlns:x='urn:foo'>
                  <xs:element name='uno' type='x:t' />
                  <xs:element name='tres' type='xs:string' />
                  <xs:complexType name='t'>
                    <xs:sequence>
                      <xs:element name='des'>
                        <xs:complexType>
                          <xs:sequence>
                            <xs:element ref='x:tres' />
                          </xs:sequence>
                        </xs:complexType>
                      </xs:element>
                    </xs:sequence>
                  </xs:complexType>
                </xs:schema>"));
            DataSetAssertion.AssertDataSet("008", ds, "NewDataSet", 2, 1);
            dt = ds.Tables[0];
            DataSetAssertion.AssertDataTable("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);
            DataSetAssertion.AssertDataColumn("id", dt.Columns[0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, "urn:foo", 0, string.Empty, false, true);

            dt = ds.Tables[1];
            DataSetAssertion.AssertDataTable("tab2", dt, "des", 2, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("child", dt.Columns[0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof(string), DBNull.Value, string.Empty, -1, "urn:foo", 0, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("id", dt.Columns[1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 1, string.Empty, false, false);
        }
Beispiel #15
0
        public void SingleElementTreatmentDifference()
        {
            // This is one of the most complicated case. When the content
            // type particle of 'Root' element is a complex element, it
            // is DataSet element. Otherwise, it is just a data table.
            //
            // But also note that there is another test named
            // LocaleOnRootWithoutIsDataSet(), that tests if locale on
            // the (mere) data table modifies *DataSet's* locale.

            // Moreover, when the schema contains another element
            // (regardless of its schema type), the elements will
            // never be treated as a DataSet.
            string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
    <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
        <xs:complexType>
            <xs:choice>
                {0}
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>";

            string xsbase2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
    <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
        <xs:complexType>
            <xs:choice>
                {0}
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:element name='more' type='xs:string' />
</xs:schema>";

            string simple  = "<xs:element name='Child' type='xs:string' />";
            string complex = @"<xs:element name='Child'>
    <xs:complexType>
        <xs:attribute name='a1' />
        <xs:attribute name='a2' type='xs:integer' />
    </xs:complexType>
</xs:element>";
            string elref   = "<xs:element ref='more' />";

            string xs2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
    <xs:element name='Root' type='RootType' />
    <xs:complexType name='RootType'>
        <xs:choice>
            <xs:element name='Child'>
                <xs:complexType>
                    <xs:attribute name='a1' />
                    <xs:attribute name='a2' type='xs:integer' />
                </xs:complexType>
            </xs:element>
        </xs:choice>
    </xs:complexType>
</xs:schema>";

            var ds = new DataSet();

            string xs = string.Format(xsbase, simple);

            ds.ReadXmlSchema(new StringReader(xs));
            DataSetAssertion.AssertDataSet("simple", ds, "hoge", 1, 0);
            DataSetAssertion.AssertDataTable("simple", ds.Tables[0], "Root", 1, 0, 0, 0, 0, 0);

            // reference to global complex type
            ds = new DataSet();
            ds.ReadXmlSchema(new StringReader(xs2));
            DataSetAssertion.AssertDataSet("external complexType", ds, "hoge", 2, 1);
            DataSetAssertion.AssertDataTable("external Tab1", ds.Tables[0], "Root", 1, 0, 0, 1, 1, 1);
            DataSetAssertion.AssertDataTable("external Tab2", ds.Tables[1], "Child", 3, 0, 1, 0, 1, 0);

            // xsbase2 + complex -> datatable
            ds = new DataSet();
            xs = string.Format(xsbase2, complex);
            ds.ReadXmlSchema(new StringReader(xs));
            DataSetAssertion.AssertDataSet("complex", ds, "hoge", 2, 1);
            DataSetAssertion.AssertDataTable("complex", ds.Tables[0], "Root", 1, 0, 0, 1, 1, 1);
            DataTable dt = ds.Tables[1];

            DataSetAssertion.AssertDataTable("complex", dt, "Child", 3, 0, 1, 0, 1, 0);
            DataSetAssertion.AssertDataColumn("a1", dt.Columns["a1"], "a1", true, false, 0, 1, "a1", MappingType.Attribute, typeof(string), DBNull.Value, string.Empty, -1, string.Empty, /*0*/ -1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("a2", dt.Columns["a2"], "a2", true, false, 0, 1, "a2", MappingType.Attribute, typeof(long), DBNull.Value, string.Empty, -1, string.Empty, /*1*/ -1, string.Empty, false, false);
            DataSetAssertion.AssertDataColumn("Root_Id", dt.Columns[2], "Root_Id", true, false, 0, 1, "Root_Id", MappingType.Hidden, typeof(int), DBNull.Value, string.Empty, -1, string.Empty, 2, string.Empty, false, false);

            // xsbase + complex -> dataset
            ds = new DataSet();
            xs = string.Format(xsbase, complex);
            ds.ReadXmlSchema(new StringReader(xs));
            DataSetAssertion.AssertDataSet("complex", ds, "Root", 1, 0);

            ds = new DataSet();
            xs = string.Format(xsbase2, elref);
            ds.ReadXmlSchema(new StringReader(xs));
            DataSetAssertion.AssertDataSet("complex", ds, "hoge", 1, 0);
            DataSetAssertion.AssertDataTable("complex", ds.Tables[0], "Root", 1, 0, 0, 0, 0, 0);
        }