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