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.
37 using System.Globalization;
39 using System.Threading;
41 using NUnit.Framework;
43 namespace MonoTests.System.Data
46 public class DataTableReadXmlSchemaTest : DataSetAssertion
48 private DataSet CreateTestSet ()
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]);
64 CultureInfo currentCultureBackup;
69 currentCultureBackup = Thread.CurrentThread.CurrentCulture;
70 Thread.CurrentThread.CurrentCulture = new CultureInfo ("fi-FI");
74 public void Teardown ()
76 Thread.CurrentThread.CurrentCulture = currentCultureBackup;
80 [Category ("NotWorking")]
81 public void SingleElementTreatmentDifference ()
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.
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.
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 -->
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 -->
112 <xs:element name='more' type='xs:string' />
115 string simple = "<xs:element name='Child' type='xs:string' />";
116 string complex = @"<xs:element name='Child'>
118 <xs:attribute name='a1' />
119 <xs:attribute name='a2' type='xs:integer' />
122 string elref = "<xs:element ref='more' />";
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'>
128 <xs:element name='Child'>
130 <xs:attribute name='a1' />
131 <xs:attribute name='a2' type='xs:integer' />
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);
144 // reference to global complex type
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);
153 // xsbase2 + complex -> datatable
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);
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);
175 public void SuspiciousDataSetElement ()
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'/>
185 <xsd:element name='doc'>
188 <xsd:element name='elem' type='attRef'/>
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);
200 [ExpectedException (typeof (ArgumentException))]
201 public void UnusedComplexTypesIgnored ()
203 string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
204 <xs:element name='Root'>
207 <xs:element name='Child' type='xs:string' />
211 <xs:complexType name='unusedType'>
213 <xs:element name='Orphan' type='xs:string' />
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));
228 [ExpectedException (typeof (ArgumentException))]
229 public void IsDataSetAndTypeIgnored ()
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}'>
234 <xs:complexType name='unusedType'>
236 <xs:element name='Child' type='xs:string' />
240 // When explicit msdata:IsDataSet value is "false", then
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);
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");
252 ds.Tables.Add (new DataTable ("Root"));
253 ds.Tables[0].ReadXmlSchema (new StringReader (xs));
257 [ExpectedException (typeof (ArgumentException))]
258 public void NestedReferenceNotAllowed ()
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'>
263 <xs:complexType name='unusedType'>
265 <xs:element name='Child' type='xs:string' />
268 <xs:element name='Foo'>
271 <xs:element ref='Root' />
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));
285 public void LocaleOnRootWithoutIsDataSet ()
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'>
291 <xs:element name='Child' type='xs:string' />
293 <xs:attribute name='Attr' type='xs:integer' />
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);
310 public void PrefixedTargetNS ()
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'>
316 <xs:element ref='x:R1' />
317 <xs:element ref='x:R2' />
321 <xs:selector xpath='./any/string_is_OK/x:R1'/>
322 <xs:field xpath='x:Child2'/>
324 <xs:keyref name='kref' refer='x:key'>
325 <xs:selector xpath='.//x:R2'/>
326 <xs:field xpath='x:Child2'/>
329 <xs:element name='R3' type='x:RootType' />
330 <xs:complexType name='extracted'>
332 <xs:element ref='x:R1' />
333 <xs:element ref='x:R2' />
336 <xs:element name='R1' type='x:RootType'>
337 <xs:unique name='Rkey'>
338 <xs:selector xpath='.//x:Child1'/>
339 <xs:field xpath='.'/>
341 <xs:keyref name='Rkref' refer='x:Rkey'>
342 <xs:selector xpath='.//x:Child2'/>
343 <xs:field xpath='.'/>
346 <xs:element name='R2' type='x:RootType'>
348 <xs:complexType name='RootType'>
350 <xs:element name='Child1' type='xs:string'>
352 <xs:element name='Child2' type='xs:string' />
354 <xs:attribute name='Attr' type='xs:integer' />
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);
367 [Category ("NotWorking")]
368 public void ReadTest1 ()
370 DataSet ds = CreateTestSet ();
372 StringWriter sw = new StringWriter ();
373 ds.WriteXmlSchema (sw);
375 string schema = sw.ToString ();
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);
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);
394 private void ReadTest1Check (DataSet ds)
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);
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"});
413 public void TestSampleFileSimpleTables ()
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);
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);
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);
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");
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");
455 [Category ("NotWorking")]
456 public void TestSampleFileImportSimple ()
458 DataSet ds = new DataSet ();
459 ds.Tables.Add( new DataTable("foo"));
460 XmlTextReader xtr = null;
462 xtr = new XmlTextReader ("Test/System.Data/schemas/test010.xsd");
463 xtr.XmlResolver = null;
464 ds.Tables[0].ReadXmlSchema (xtr);
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);
476 [Category ("NotWorking")]
477 [ExpectedException (typeof (NullReferenceException))]
478 public void TestSampleFileComplexTables2 ()
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");
493 public void TestSampleFileComplexTables3 ()
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);
506 public void TestSampleFileXPath ()
508 DataSet ds = new DataSet ();
509 ds.Tables.Add (new DataTable ("Track"));
510 ds.Tables[0].ReadXmlSchema ("Test/System.Data/schemas/test103.xsd");
514 [Category ("NotWorking")]
515 public void TestAnnotatedRelation1 ()
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");
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);
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);
531 AssertDataRelation ("rel", ds.Relations [0], "rel", false, new string [] {"pk"}, new string [] {"fk"}, false, false);
535 [Category ("NotWorking")]
536 public void TestAnnotatedRelation2 ()
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");
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);
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);
552 AssertDataRelation ("rel", ds.Relations [0], "rel", true, new string [] {"pk"}, new string [] {"fk"}, false, false);
556 [Category ("NotWorking")]
557 public void RepeatableSimpleElement ()
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);
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);
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);
575 AssertDataRelation ("rel", ds.Relations [0], "Foo_Bar", true, new string [] {"Foo_Id"}, new string [] {"Foo_Id"}, true, true);
579 [Category ("NotWorking")]
580 public void TestMoreThanOneRepeatableColumns ()
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);
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);
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);
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);
605 AssertDataRelation ("rel", ds.Relations [0], "root_x", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
607 AssertDataRelation ("rel", ds.Relations [1], "root_y", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
611 public void ReadConstraints ()
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");
625 [Category ("NotWorking")]
626 public void ReadAnnotatedRelations_MultipleColumns ()
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);