System.Data.Tests.DataSetReadXmlSchemaTest.ElementHasIdentityConstraint C# (CSharp) Method

ElementHasIdentityConstraint() private method

private ElementHasIdentityConstraint ( ) : void
return void
        public void ElementHasIdentityConstraint()
        {
            string constraints = @"
		<xs:key name='key'>
			<xs:selector xpath='./any/string_is_OK/R1'/>
			<xs:field xpath='Child2'/>
		</xs:key>
		<xs:keyref name='kref' refer='key'>
			<xs:selector xpath='.//R2'/>
			<xs:field xpath='Child2'/>
		</xs:keyref>";
            string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
	<xs:element name='DS' msdata:IsDataSet='true'>
		<xs:complexType>
			<xs:choice>
				<xs:element ref='R1' />
				<xs:element ref='R2' />
			</xs:choice>
		</xs:complexType>
		{0}
	</xs:element>
	<xs:element name='R1' type='RootType'>
	      {1}
	</xs:element>
	<xs:element name='R2' type='RootType'>
	</xs:element>
	<xs:complexType name='RootType'>
		<xs:choice>
			<xs:element name='Child1' type='xs:string'>
				{2}
			</xs:element>
			<xs:element name='Child2' type='xs:string' />
		</xs:choice>
		<xs:attribute name='Attr' type='xs:integer' />
	</xs:complexType>
</xs:schema>";

            // Constraints on DataSet element.
            // Note that in xs:key xpath is crazy except for the last step
            string xs = string.Format(xsbase, constraints, string.Empty, string.Empty);
            var ds = new DataSet();
            ds.ReadXmlSchema(new StringReader(xs));
            Assert.Equal(1, ds.Relations.Count);

            // Constraints on another global element - just ignored
            xs = string.Format(xsbase, string.Empty, constraints, string.Empty);
            ds = new DataSet();
            ds.ReadXmlSchema(new StringReader(xs));
            Assert.Equal(0, ds.Relations.Count);

            // Constraints on local element - just ignored
            xs = string.Format(xsbase, string.Empty, string.Empty, constraints);
            ds = new DataSet();
            ds.ReadXmlSchema(new StringReader(xs));
            Assert.Equal(0, ds.Relations.Count);
        }