2 // DataTableReadXmlSchemaTest.cs
5 // Hagit Yidov <hagity@mainsoft.com>
6 // [DataSetReadXmlSchemaTest.cs: Atsushi Enomoto <atsushi@ximian.com>]
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
36 using System.Globalization;
38 using System.Threading;
40 using NUnit.Framework;
42 namespace MonoTests.System.Data
45 public class DataTableReadXmlSchemaTest : DataSetAssertion
47 private DataSet CreateTestSet ()
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]);
63 CultureInfo currentCultureBackup;
68 currentCultureBackup = Thread.CurrentThread.CurrentCulture;
69 Thread.CurrentThread.CurrentCulture = new CultureInfo ("fi-FI");
73 public void Teardown ()
75 Thread.CurrentThread.CurrentCulture = currentCultureBackup;
79 [Category ("NotWorking")]
80 public void SingleElementTreatmentDifference ()
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.
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.
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 -->
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 -->
111 <xs:element name='more' type='xs:string' />
114 string simple = "<xs:element name='Child' type='xs:string' />";
115 string complex = @"<xs:element name='Child'>
117 <xs:attribute name='a1' />
118 <xs:attribute name='a2' type='xs:integer' />
121 string elref = "<xs:element ref='more' />";
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'>
127 <xs:element name='Child'>
129 <xs:attribute name='a1' />
130 <xs:attribute name='a2' type='xs:integer' />
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);
143 // reference to global complex type
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);
152 // xsbase2 + complex -> datatable
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);
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);
174 public void SuspiciousDataSetElement ()
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'/>
184 <xsd:element name='doc'>
187 <xsd:element name='elem' type='attRef'/>
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);
199 [ExpectedException (typeof (ArgumentException))]
200 public void UnusedComplexTypesIgnored ()
202 string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
203 <xs:element name='Root'>
206 <xs:element name='Child' type='xs:string' />
210 <xs:complexType name='unusedType'>
212 <xs:element name='Orphan' type='xs:string' />
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));
227 [ExpectedException (typeof (ArgumentException))]
228 public void IsDataSetAndTypeIgnored ()
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}'>
233 <xs:complexType name='unusedType'>
235 <xs:element name='Child' type='xs:string' />
239 // When explicit msdata:IsDataSet value is "false", then
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);
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");
251 ds.Tables.Add (new DataTable ("Root"));
252 ds.Tables[0].ReadXmlSchema (new StringReader (xs));
256 [ExpectedException (typeof (ArgumentException))]
257 public void NestedReferenceNotAllowed ()
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'>
262 <xs:complexType name='unusedType'>
264 <xs:element name='Child' type='xs:string' />
267 <xs:element name='Foo'>
270 <xs:element ref='Root' />
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));
284 public void LocaleOnRootWithoutIsDataSet ()
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'>
290 <xs:element name='Child' type='xs:string' />
292 <xs:attribute name='Attr' type='xs:integer' />
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);
309 public void PrefixedTargetNS ()
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'>
315 <xs:element ref='x:R1' />
316 <xs:element ref='x:R2' />
320 <xs:selector xpath='./any/string_is_OK/x:R1'/>
321 <xs:field xpath='x:Child2'/>
323 <xs:keyref name='kref' refer='x:key'>
324 <xs:selector xpath='.//x:R2'/>
325 <xs:field xpath='x:Child2'/>
328 <xs:element name='R3' type='x:RootType' />
329 <xs:complexType name='extracted'>
331 <xs:element ref='x:R1' />
332 <xs:element ref='x:R2' />
335 <xs:element name='R1' type='x:RootType'>
336 <xs:unique name='Rkey'>
337 <xs:selector xpath='.//x:Child1'/>
338 <xs:field xpath='.'/>
340 <xs:keyref name='Rkref' refer='x:Rkey'>
341 <xs:selector xpath='.//x:Child2'/>
342 <xs:field xpath='.'/>
345 <xs:element name='R2' type='x:RootType'>
347 <xs:complexType name='RootType'>
349 <xs:element name='Child1' type='xs:string'>
351 <xs:element name='Child2' type='xs:string' />
353 <xs:attribute name='Attr' type='xs:integer' />
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);
366 [Category ("NotWorking")]
367 public void ReadTest1 ()
369 DataSet ds = CreateTestSet ();
371 StringWriter sw = new StringWriter ();
372 ds.WriteXmlSchema (sw);
374 string schema = sw.ToString ();
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);
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);
393 private void ReadTest1Check (DataSet ds)
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);
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"});
412 public void TestSampleFileSimpleTables ()
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);
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);
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);
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");
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");
454 [Category ("NotWorking")]
455 public void TestSampleFileImportSimple ()
457 DataSet ds = new DataSet ();
458 ds.Tables.Add( new DataTable("foo"));
459 XmlTextReader xtr = null;
461 xtr = new XmlTextReader ("Test/System.Data/schemas/test010.xsd");
462 xtr.XmlResolver = null;
463 ds.Tables[0].ReadXmlSchema (xtr);
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);
475 [Category ("NotWorking")]
476 [ExpectedException (typeof (NullReferenceException))]
477 public void TestSampleFileComplexTables2 ()
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");
492 public void TestSampleFileComplexTables3 ()
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);
505 public void TestSampleFileXPath ()
507 DataSet ds = new DataSet ();
508 ds.Tables.Add (new DataTable ("Track"));
509 ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test103.xsd");
513 [Category ("NotWorking")]
514 public void TestAnnotatedRelation1 ()
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");
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);
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);
530 AssertDataRelation ("rel", ds.Relations [0], "rel", false, new string [] {"pk"}, new string [] {"fk"}, false, false);
534 [Category ("NotWorking")]
535 public void TestAnnotatedRelation2 ()
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");
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);
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);
551 AssertDataRelation ("rel", ds.Relations [0], "rel", true, new string [] {"pk"}, new string [] {"fk"}, false, false);
555 [Category ("NotWorking")]
556 public void RepeatableSimpleElement ()
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);
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);
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);
574 AssertDataRelation ("rel", ds.Relations [0], "Foo_Bar", true, new string [] {"Foo_Id"}, new string [] {"Foo_Id"}, true, true);
578 [Category ("NotWorking")]
579 public void TestMoreThanOneRepeatableColumns ()
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);
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);
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);
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);
604 AssertDataRelation ("rel", ds.Relations [0], "root_x", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
606 AssertDataRelation ("rel", ds.Relations [1], "root_y", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
610 public void ReadConstraints ()
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");
624 [Category ("NotWorking")]
625 public void ReadAnnotatedRelations_MultipleColumns ()
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);