[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Data / Test / System.Data / DataTableReadXmlSchemaTest.cs
1 //
2 // DataTableReadXmlSchemaTest.cs
3 //
4 // Author:
5 //      Hagit Yidov <hagity@mainsoft.com>
6 //      [DataSetReadXmlSchemaTest.cs: Atsushi Enomoto <atsushi@ximian.com>]
7 //
8
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32
33 using System;
34 using System.IO;
35 using System.Data;
36 using System.Globalization;
37 using System.Text;
38 using System.Threading;
39 using System.Xml;
40 using NUnit.Framework;
41
42 namespace MonoTests.System.Data
43 {
44         [TestFixture]
45         public class DataTableReadXmlSchemaTest : DataSetAssertion
46         {
47                 private DataSet CreateTestSet ()
48                 {
49                         DataSet ds = new DataSet ();
50                         ds.Tables.Add ("Table1");
51                         ds.Tables.Add ("Table2");
52                         ds.Tables [0].Columns.Add ("Column1_1");
53                         ds.Tables [0].Columns.Add ("Column1_2");
54                         ds.Tables [0].Columns.Add ("Column1_3");
55                         ds.Tables [1].Columns.Add ("Column2_1");
56                         ds.Tables [1].Columns.Add ("Column2_2");
57                         ds.Tables [1].Columns.Add ("Column2_3");
58                         ds.Tables [0].Rows.Add (new object [] {"ppp", "www", "xxx"});
59                         ds.Relations.Add ("Rel1", ds.Tables [0].Columns [2], ds.Tables [1].Columns [0]);
60                         return ds;
61                 }
62
63                 CultureInfo currentCultureBackup;
64
65                 [SetUp]
66                 public void Setup ()
67                 {
68                         currentCultureBackup = Thread.CurrentThread.CurrentCulture;
69                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("fi-FI");
70                 }
71
72                 [TearDown]
73                 public void Teardown ()
74                 {
75                         Thread.CurrentThread.CurrentCulture = currentCultureBackup;
76                 }
77
78                 [Test]
79                 [Category ("NotWorking")]
80                 public void SingleElementTreatmentDifference ()
81                 {
82                         // This is one of the most complicated case. When the content
83                         // type particle of 'Root' element is a complex element, it
84                         // is DataSet element. Otherwise, it is just a data table.
85                         //
86                         // But also note that there is another test named
87                         // LocaleOnRootWithoutIsDataSet(), that tests if locale on
88                         // the (mere) data table modifies *DataSet's* locale.
89
90                         // Moreover, when the schema contains another element
91                         // (regardless of its schema type), the elements will
92                         // never be treated as a DataSet.
93                         string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
94         <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
95                 <xs:complexType>
96                         <xs:choice>
97                                 {0}
98                         </xs:choice>
99                 </xs:complexType>
100         </xs:element>
101 </xs:schema>";
102
103                         string xsbase2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
104         <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
105                 <xs:complexType>
106                         <xs:choice>
107                                 {0}
108                         </xs:choice>
109                 </xs:complexType>
110         </xs:element>
111         <xs:element name='more' type='xs:string' />
112 </xs:schema>";
113
114                         string simple = "<xs:element name='Child' type='xs:string' />";
115                         string complex = @"<xs:element name='Child'>
116         <xs:complexType>
117                 <xs:attribute name='a1' />
118                 <xs:attribute name='a2' type='xs:integer' />
119         </xs:complexType>
120 </xs:element>";
121                         string elref = "<xs:element ref='more' />";
122
123                         string xs2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
124         <xs:element name='Root' type='RootType' />
125         <xs:complexType name='RootType'>
126                 <xs:choice>
127                         <xs:element name='Child'>
128                                 <xs:complexType>
129                                         <xs:attribute name='a1' />
130                                         <xs:attribute name='a2' type='xs:integer' />
131                                 </xs:complexType>
132                         </xs:element>
133                 </xs:choice>
134         </xs:complexType>
135 </xs:schema>";
136
137                         DataSet ds = new DataSet ();
138                         ds.Tables.Add (new DataTable ("Root"));
139                         string xs = String.Format (xsbase, simple);
140                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
141                         AssertDataTable ("simple", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
142
143                         // reference to global complex type
144                         ds = new DataSet ();
145                         ds.Tables.Add (new DataTable ("Root"));
146                         ds.Tables.Add (new DataTable ("Child"));
147                         ds.Tables[0].ReadXmlSchema (new StringReader (xs2));
148                         ds.Tables[1].ReadXmlSchema (new StringReader (xs2));
149                         AssertDataTable ("external Tab1", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);
150                         AssertDataTable ("external Tab2", ds.Tables [1], "Child", 3, 0, 1, 0, 1, 0);
151
152                         // xsbase2 + complex -> datatable
153                         ds = new DataSet ();
154                         ds.Tables.Add (new DataTable ("Root"));
155                         ds.Tables.Add (new DataTable ("Child"));
156                         xs = String.Format (xsbase2, complex);
157                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
158                         ds.Tables[1].ReadXmlSchema (new StringReader (xs));
159                         AssertDataTable ("complex", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);
160                         DataTable dt = ds.Tables [1];
161                         AssertDataTable ("complex", dt, "Child", 3, 0, 1, 0, 1, 0);
162                         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);
163                         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);
164                         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);
165
166                         ds = new DataSet ();
167                         ds.Tables.Add (new DataTable ("Root"));
168                         xs = String.Format (xsbase2, elref);
169                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
170                         AssertDataTable ("complex", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
171                 }
172
173                 [Test]
174                 public void SuspiciousDataSetElement ()
175                 {
176                         string schema = @"<?xml version='1.0'?>
177 <xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
178         <xsd:attribute name='foo' type='xsd:string'/>
179         <xsd:attribute name='bar' type='xsd:string'/>
180         <xsd:complexType name='attRef'>
181                 <xsd:attribute name='att1' type='xsd:int'/>
182                 <xsd:attribute name='att2' type='xsd:string'/>
183         </xsd:complexType>
184         <xsd:element name='doc'>
185                 <xsd:complexType>
186                         <xsd:choice>
187                                 <xsd:element name='elem' type='attRef'/>
188                         </xsd:choice>
189                 </xsd:complexType>
190         </xsd:element>
191 </xsd:schema>";
192                         DataSet ds = new DataSet ();
193                         ds.Tables.Add (new DataTable ("elem"));
194                         ds.Tables[0].ReadXmlSchema (new StringReader (schema));
195                         AssertDataTable ("table", ds.Tables [0], "elem", 2, 0, 0, 0, 0, 0);
196                 }
197
198                 [Test]
199                 [ExpectedException (typeof (ArgumentException))]
200                 public void UnusedComplexTypesIgnored ()
201                 {
202                         string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
203         <xs:element name='Root'>
204                 <xs:complexType>
205                         <xs:sequence>
206                                 <xs:element name='Child' type='xs:string' />
207                         </xs:sequence>
208                 </xs:complexType>
209         </xs:element>
210         <xs:complexType name='unusedType'>
211                 <xs:sequence>
212                         <xs:element name='Orphan' type='xs:string' />
213                 </xs:sequence>
214         </xs:complexType>
215 </xs:schema>";
216
217                         DataSet ds = new DataSet ();
218                         ds.Tables.Add (new DataTable ("Root"));
219                         ds.Tables.Add (new DataTable ("unusedType"));
220                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
221                         AssertDataTable ("dt", ds.Tables[0], "Root", 1, 0, 0, 0, 0, 0);
222                         // Here "unusedType" table is never imported.
223                         ds.Tables[1].ReadXmlSchema (new StringReader (xs));
224                 }
225
226                 [Test]
227                 [ExpectedException (typeof (ArgumentException))]
228                 public void IsDataSetAndTypeIgnored ()
229                 {
230                         string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
231         <xs:element name='Root' type='unusedType' msdata:IsDataSet='{0}'>
232         </xs:element>
233         <xs:complexType name='unusedType'>
234                 <xs:sequence>
235                         <xs:element name='Child' type='xs:string' />
236                 </xs:sequence>
237         </xs:complexType>
238 </xs:schema>";
239                         // When explicit msdata:IsDataSet value is "false", then
240                         // treat as usual.
241                         string xs = String.Format (xsbase, "false");
242                         DataSet ds = new DataSet ();
243                         ds.Tables.Add (new DataTable ("Root"));
244                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
245                         AssertDataTable ("dt", ds.Tables[0], "Root", 1, 0, 0, 0, 0, 0);
246
247                         // Even if a global element uses a complexType, it will be
248                         // ignored if the element has msdata:IsDataSet='true'
249                         xs = String.Format (xsbase, "true");
250                         ds = new DataSet ();
251                         ds.Tables.Add (new DataTable ("Root"));
252                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
253                 }
254
255                 [Test]
256                 [ExpectedException (typeof (ArgumentException))]
257                 public void NestedReferenceNotAllowed ()
258                 {
259                         string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
260         <xs:element name='Root' type='unusedType' msdata:IsDataSet='true'>
261         </xs:element>
262         <xs:complexType name='unusedType'>
263                 <xs:sequence>
264                         <xs:element name='Child' type='xs:string' />
265                 </xs:sequence>
266         </xs:complexType>
267         <xs:element name='Foo'>
268                 <xs:complexType>
269                         <xs:sequence>
270                                 <xs:element ref='Root' />
271                         </xs:sequence>
272                 </xs:complexType>
273         </xs:element>
274 </xs:schema>";
275
276                         // DataSet element cannot be converted into a DataTable.
277                         // (i.e. cannot be referenced in any other elements)
278                         DataSet ds = new DataSet ();
279                         ds.Tables.Add (new DataTable ());
280                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
281                 }
282
283                 [Test]
284                 public void LocaleOnRootWithoutIsDataSet ()
285                 {
286                         string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
287         <xs:element name='Root' msdata:Locale='ja-JP'>
288                 <xs:complexType>
289                         <xs:sequence>
290                                 <xs:element name='Child' type='xs:string' />
291                         </xs:sequence>
292                         <xs:attribute name='Attr' type='xs:integer' />
293                 </xs:complexType>
294         </xs:element>
295 </xs:schema>";
296
297                         DataSet ds = new DataSet ();
298                         ds.Tables.Add ("Root");
299                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
300                         DataTable dt = ds.Tables [0];
301                         AssertDataTable ("dt", dt, "Root", 2, 0, 0, 0, 0, 0);
302                         Assert.AreEqual ("ja-JP", dt.Locale.Name); // DataTable's Locale comes from msdata:Locale
303                         AssertDataColumn ("col1", dt.Columns [0], "Attr", true, false, 0, 1, "Attr", MappingType.Attribute, typeof (Int64), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
304                         AssertDataColumn ("col2", dt.Columns [1], "Child", false, false, 0, 1, "Child", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
305                 }
306
307
308                 [Test]
309                 public void PrefixedTargetNS ()
310                 {
311                         string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' xmlns:x='urn:foo' targetNamespace='urn:foo' elementFormDefault='qualified'>
312         <xs:element name='DS' msdata:IsDataSet='true'>
313                 <xs:complexType>
314                         <xs:choice>
315                                 <xs:element ref='x:R1' />
316                                 <xs:element ref='x:R2' />
317                         </xs:choice>
318                 </xs:complexType>
319                 <xs:key name='key'>
320                         <xs:selector xpath='./any/string_is_OK/x:R1'/>
321                         <xs:field xpath='x:Child2'/>
322                 </xs:key>
323                 <xs:keyref name='kref' refer='x:key'>
324                         <xs:selector xpath='.//x:R2'/>
325                         <xs:field xpath='x:Child2'/>
326                 </xs:keyref>
327         </xs:element>
328         <xs:element name='R3' type='x:RootType' />
329         <xs:complexType name='extracted'>
330                 <xs:choice>
331                         <xs:element ref='x:R1' />
332                         <xs:element ref='x:R2' />
333                 </xs:choice>
334         </xs:complexType>
335         <xs:element name='R1' type='x:RootType'>
336                 <xs:unique name='Rkey'>
337                         <xs:selector xpath='.//x:Child1'/>
338                         <xs:field xpath='.'/>
339                 </xs:unique>
340                 <xs:keyref name='Rkref' refer='x:Rkey'>
341                         <xs:selector xpath='.//x:Child2'/>
342                         <xs:field xpath='.'/>
343                 </xs:keyref>
344         </xs:element>
345         <xs:element name='R2' type='x:RootType'>
346         </xs:element>
347         <xs:complexType name='RootType'>
348                 <xs:choice>
349                         <xs:element name='Child1' type='xs:string'>
350                         </xs:element>
351                         <xs:element name='Child2' type='xs:string' />
352                 </xs:choice>
353                 <xs:attribute name='Attr' type='xs:integer' />
354         </xs:complexType>
355 </xs:schema>";
356                         // No prefixes on tables and columns
357                         DataSet ds = new DataSet ();
358                         ds.Tables.Add(new DataTable("R3"));
359                         ds.Tables[0].ReadXmlSchema (new StringReader (xs));
360                         DataTable dt = ds.Tables [0];
361                         AssertDataTable ("R3", dt, "R3", 3, 0, 0, 0, 0, 0);
362                         AssertDataColumn ("col1", dt.Columns [0], "Attr", true, false, 0, 1, "Attr", MappingType.Attribute, typeof (Int64), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
363                 }
364
365                 [Test]
366                 [Category ("NotWorking")]
367                 public void ReadTest1 ()
368                 {
369                         DataSet ds = CreateTestSet ();
370
371                         StringWriter sw = new StringWriter ();
372                         ds.WriteXmlSchema (sw);
373
374                         string schema = sw.ToString ();
375
376                         // ReadXmlSchema()
377                         DataSet ds1 = new DataSet ();
378                         ds1.Tables.Add (new DataTable("Table1"));
379                         ds1.Tables.Add (new DataTable("Table2"));
380                         ds1.Tables[0].ReadXmlSchema (new XmlTextReader (schema, XmlNodeType.Document, null));
381                         ds1.Tables[1].ReadXmlSchema (new XmlTextReader (schema, XmlNodeType.Document, null));
382                         ReadTest1Check (ds1);
383
384                         // ReadXml() should also be the same
385                         DataSet ds2 = new DataSet ();
386                         ds2.Tables.Add (new DataTable ("Table1"));
387                         ds2.Tables.Add (new DataTable ("Table2"));
388                         ds2.Tables[0].ReadXml (new XmlTextReader (schema, XmlNodeType.Document, null));
389                         ds2.Tables[1].ReadXml (new XmlTextReader (schema, XmlNodeType.Document, null));
390                         ReadTest1Check (ds2);
391                 }
392
393                 private void ReadTest1Check (DataSet ds)
394                 {
395                         AssertDataSet ("dataset", ds, "NewDataSet", 2, 1);
396                         AssertDataTable ("tbl1", ds.Tables [0], "Table1", 3, 0, 0, 1, 1, 0);
397                         AssertDataTable ("tbl2", ds.Tables [1], "Table2", 3, 0, 1, 0, 1, 0);
398
399                         DataRelation rel = ds.Relations [0];
400                         AssertDataRelation ("rel", rel, "Rel1", false,
401                                 new string [] {"Column1_3"},
402                                 new string [] {"Column2_1"}, true, true);
403                         AssertUniqueConstraint ("uc", rel.ParentKeyConstraint, 
404                                 "Constraint1", false, new string [] {"Column1_3"});
405                         AssertForeignKeyConstraint ("fk", rel.ChildKeyConstraint, "Rel1",
406                                 AcceptRejectRule.None, Rule.Cascade, Rule.Cascade,
407                                 new string [] {"Column2_1"}, 
408                                 new string [] {"Column1_3"});
409                 }
410
411                 [Test]
412                 public void TestSampleFileSimpleTables ()
413                 {
414                         DataSet ds = new DataSet ();
415                         ds.Tables.Add (new DataTable ("foo"));
416                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test005.xsd");
417                         AssertDataSet ("005", ds, "NewDataSet", 1, 0);
418                         DataTable dt = ds.Tables [0];
419                         AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
420                         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);
421                         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);
422
423                         ds = new DataSet ();
424                         ds.Tables.Add (new DataTable ("foo"));
425                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test006.xsd");
426                         AssertDataSet ("006", ds, "NewDataSet", 1, 0);
427                         dt = ds.Tables [0];
428                         AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
429                         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);
430                         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);
431                 }
432
433                 [Test]
434                 [Category ("NotWorking")]
435                 [ExpectedException (typeof (NullReferenceException))]
436                 public void TestSampleFileComplexTablesExp1 () {
437                         // Nested simple type element
438                         DataSet ds = new DataSet ();
439                         ds.Tables.Add (new DataTable ("uno"));
440                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test007.xsd");
441                 }
442
443                 [Test]
444                 [Category ("NotWorking")]
445                 [ExpectedException (typeof (NullReferenceException))]
446                 public void TestSampleFileComplexTablesExp2 () {
447                         // External simple type element
448                         DataSet ds = new DataSet ();
449                         ds.Tables.Add (new DataTable ("uno"));
450                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test008.xsd");
451                 }
452
453                 [Test]
454                 [Category ("NotWorking")]
455                 public void TestSampleFileImportSimple ()
456                 {
457                         DataSet ds = new DataSet ();
458                         ds.Tables.Add( new DataTable("foo"));
459                         XmlTextReader xtr = null;
460                         try {
461                                 xtr = new XmlTextReader ("Test/System.Data/schemas/test010.xsd");
462                                 xtr.XmlResolver = null;
463                                 ds.Tables[0].ReadXmlSchema (xtr);
464                         } finally {
465                                 if (xtr != null)
466                                         xtr.Close ();
467                         }
468                         AssertDataSet ("010", ds, "NewDataSet", 1, 0);
469                         DataTable dt = ds.Tables [0];
470                         AssertDataTable ("root", dt, "foo", 1, 0, 0, 0, 0, 0);
471                         AssertDataColumn ("simple", dt.Columns [0], "bar", false, false, 0, 1, "bar", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
472                 }
473
474                 [Test]
475                 [Category ("NotWorking")]
476                 [ExpectedException (typeof (NullReferenceException))]
477                 public void TestSampleFileComplexTables2 ()
478                 {
479                         DataSet ds = new DataSet ();
480                         ds.Tables.Add (new DataTable ("e"));
481                         ds.Tables.Add (new DataTable ("root"));
482                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test011.xsd");
483                         DataTable dt = ds.Tables[0];
484                         AssertDataTable ("root", dt, "e", 3, 0, 0, 0, 0, 0);
485                         AssertDataColumn ("attr", dt.Columns [0], "a", true, false, 0, 1, "a", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, "http://xsdtesting", 0, String.Empty, false, false);
486                         AssertDataColumn ("simple", dt.Columns [1], "e_text", false, false, 0, 1, "e_text", MappingType.SimpleContent, typeof (decimal), DBNull.Value, String.Empty, -1, "", 1, String.Empty, false, false);
487                         AssertDataColumn ("hidden", dt.Columns [2], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "", 2, String.Empty, false, false);
488                         ds.Tables[1].ReadXmlSchema ("Test/System.Data/schemas/test011.xsd");
489                 }
490
491                 [Test]
492                 public void TestSampleFileComplexTables3 ()
493                 {
494                         DataSet ds = new DataSet ();
495                         ds.Tables.Add (new DataTable ("e"));
496                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test013.xsd");
497                         DataTable dt = ds.Tables [0];
498                         AssertDataTable ("root", dt, "e", 2, 0, 0, 0, 0, 0);
499                         AssertDataColumn ("attr", dt.Columns [0], "a", true, false, 0, 1, "a", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
500                         AssertDataColumn ("simple", dt.Columns [1], "e_text", false, false, 0, 1, "e_text", MappingType.SimpleContent, typeof (decimal), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
501                 }
502
503                 // bug #58744
504                 [Test]
505                 public void TestSampleFileXPath ()
506                 {
507                         DataSet ds = new DataSet ();
508                         ds.Tables.Add (new DataTable ("Track"));
509                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test103.xsd");
510                 }
511
512                 [Test]
513                 [Category ("NotWorking")]
514                 public void TestAnnotatedRelation1 ()
515                 {
516                         DataSet ds = new DataSet ();
517                         ds.Tables.Add (new DataTable ("p"));
518                         ds.Tables.Add (new DataTable ("c"));
519                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test101.xsd");
520                         ds.Tables[1].ReadXmlSchema ("Test/System.Data/schemas/test101.xsd");
521
522                         DataTable dt = ds.Tables [0];
523                         AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);
524                         AssertDataColumn ("pk", dt.Columns [0], "pk", false, false, 0, 1, "pk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
525
526                         dt = ds.Tables [1];
527                         AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);
528                         AssertDataColumn ("fk", dt.Columns [0], "fk", false, false, 0, 1, "fk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
529
530                         AssertDataRelation ("rel", ds.Relations [0], "rel", false, new string [] {"pk"}, new string [] {"fk"}, false, false);
531                 }
532
533                 [Test]
534                 [Category ("NotWorking")]
535                 public void TestAnnotatedRelation2 ()
536                 {
537                         DataSet ds = new DataSet ();
538                         ds.Tables.Add (new DataTable ("p"));
539                         ds.Tables.Add (new DataTable ("c"));
540                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test102.xsd");
541                         ds.Tables[1].ReadXmlSchema ("Test/System.Data/schemas/test102.xsd");
542
543                         DataTable dt = ds.Tables [0];
544                         AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);
545                         AssertDataColumn ("pk", dt.Columns [0], "pk", false, false, 0, 1, "pk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
546
547                         dt = ds.Tables [1];
548                         AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);
549                         AssertDataColumn ("fk", dt.Columns [0], "fk", false, false, 0, 1, "fk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
550
551                         AssertDataRelation ("rel", ds.Relations [0], "rel", true, new string [] {"pk"}, new string [] {"fk"}, false, false);
552                 }
553
554                 [Test]
555                 [Category ("NotWorking")]
556                 public void RepeatableSimpleElement ()
557                 {
558                         DataSet ds = new DataSet ();
559                         ds.Tables.Add (new DataTable ("Foo"));
560                         ds.Tables.Add (new DataTable ("Bar"));
561                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test012.xsd");
562                         ds.Tables[1].ReadXmlSchema ("Test/System.Data/schemas/test012.xsd");
563                         AssertDataSet ("012", ds, "NewDataSet", 2, 1);
564
565                         DataTable dt = ds.Tables [0];
566                         AssertDataTable ("parent", dt, "Foo", 1, 0, 0, 1, 1, 1);
567                         AssertDataColumn ("key", dt.Columns [0], "Foo_Id", false, true, 0, 1, "Foo_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, true);
568
569                         dt = ds.Tables [1];
570                         AssertDataTable ("repeated", dt, "Bar", 2, 0, 1, 0, 1, 0);
571                         AssertDataColumn ("data", dt.Columns [0], "Bar_Column", false, false, 0, 1, "Bar_Column", MappingType.SimpleContent, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
572                         AssertDataColumn ("refkey", dt.Columns [1], "Foo_Id", true, false, 0, 1, "Foo_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
573
574                         AssertDataRelation ("rel", ds.Relations [0], "Foo_Bar", true, new string [] {"Foo_Id"}, new string [] {"Foo_Id"}, true, true);
575                 }
576
577                 [Test]
578                 [Category ("NotWorking")]
579                 public void TestMoreThanOneRepeatableColumns ()
580                 {
581                         DataSet ds = new DataSet ();
582                         ds.Tables.Add (new DataTable ("root"));
583                         ds.Tables.Add (new DataTable ("x"));
584                         ds.Tables.Add (new DataTable ("y"));
585                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test014.xsd");
586                         ds.Tables[1].ReadXmlSchema ("Test/System.Data/schemas/test014.xsd");
587                         ds.Tables[2].ReadXmlSchema ("Test/System.Data/schemas/test014.xsd");
588                         AssertDataSet ("014", ds, "NewDataSet", 3, 2);
589
590                         DataTable dt = ds.Tables [0];
591                         AssertDataTable ("parent", dt, "root", 1, 0, 0, 2, 1, 1);
592                         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);
593
594                         dt = ds.Tables [1];
595                         AssertDataTable ("repeated", dt, "x", 2, 0, 1, 0, 1, 0);
596                         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);
597                         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);
598
599                         dt = ds.Tables [2];
600                         AssertDataTable ("repeated", dt, "y", 2, 0, 1, 0, 1, 0);
601                         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);
602                         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);
603
604                         AssertDataRelation ("rel", ds.Relations [0], "root_x", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
605
606                         AssertDataRelation ("rel", ds.Relations [1], "root_y", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
607                 }
608
609                 [Test]
610                 public void ReadConstraints ()
611                 {
612                         DataSet ds = new DataSet ();
613                         ds.Tables.Add (new DataTable ());
614                         ds.Tables.Add (new DataTable ());
615                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test015.xsd");
616                         ds.Tables[1].ReadXmlSchema ("Test/System.Data/schemas/test015.xsd");
617                         Assert.AreEqual (0, ds.Relations.Count, "#1");
618                         Assert.AreEqual (1, ds.Tables [0].Constraints.Count, "#2" );
619                         Assert.AreEqual (0, ds.Tables [1].Constraints.Count, "#3" );
620                         Assert.AreEqual ("Constraint1", ds.Tables [0].Constraints [0].ConstraintName, "#4");
621                 }
622
623                 [Test]
624                 [Category ("NotWorking")]
625                 public void ReadAnnotatedRelations_MultipleColumns ()
626                 {
627                         DataSet ds = new DataSet ();
628                         ds.Tables.Add (new DataTable ());
629                         ds.Tables.Add (new DataTable ());
630                         ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test016.xsd");
631                         ds.Tables[1].ReadXmlSchema ("Test/System.Data/schemas/test016.xsd");
632                         Assert.AreEqual (1, ds.Relations.Count, "#1");
633                         Assert.AreEqual ("rel", ds.Relations [0].RelationName, "#2");
634                         Assert.AreEqual (2, ds.Relations [0].ParentColumns.Length, "#3");
635                         Assert.AreEqual (2, ds.Relations [0].ChildColumns.Length, "#4");
636                         Assert.AreEqual(0, ds.Tables [0].Constraints.Count, "#5" );
637                         Assert.AreEqual(0, ds.Tables [1].Constraints.Count, "#6" );
638                         AssertDataRelation ("TestRel", ds.Relations [0], "rel", false, new String[] {"col 1","col2"},
639                                         new String[] {"col1","col  2"}, false, false);
640                 }
641         }
642 }
643