System.Data.Tests.DataSetReadXmlSchemaTest.SingleElementTreatmentDifference C# (CSharp) Метод

SingleElementTreatmentDifference() приватный Метод

private SingleElementTreatmentDifference ( ) : void
Результат void
        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));
            AssertDataSet("simple", ds, "hoge", 1, 0);
            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));
            AssertDataSet("external complexType", ds, "hoge", 2, 1);
            AssertDataTable("external Tab1", ds.Tables[0], "Root", 1, 0, 0, 1, 1, 1);
            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));
            AssertDataSet("complex", ds, "hoge", 2, 1);
            AssertDataTable("complex", ds.Tables[0], "Root", 1, 0, 0, 1, 1, 1);
            DataTable dt = ds.Tables[1];
            AssertDataTable("complex", dt, "Child", 3, 0, 1, 0, 1, 0);
            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);
            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);
            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));
            AssertDataSet("complex", ds, "Root", 1, 0);

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