2 // DataSetReadXmlSchemaTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Globalization;
37 using System.Threading;
39 using NUnit.Framework;
41 namespace MonoTests.System.Data
44 public class DataSetReadXmlSchemaTest : DataSetAssertion
46 private DataSet CreateTestSet ()
48 DataSet ds = new DataSet ();
49 ds.Tables.Add ("Table1");
50 ds.Tables.Add ("Table2");
51 ds.Tables [0].Columns.Add ("Column1_1");
52 ds.Tables [0].Columns.Add ("Column1_2");
53 ds.Tables [0].Columns.Add ("Column1_3");
54 ds.Tables [1].Columns.Add ("Column2_1");
55 ds.Tables [1].Columns.Add ("Column2_2");
56 ds.Tables [1].Columns.Add ("Column2_3");
57 ds.Tables [0].Rows.Add (new object [] {"ppp", "www", "xxx"});
58 ds.Relations.Add ("Rel1", ds.Tables [0].Columns [2], ds.Tables [1].Columns [0]);
62 CultureInfo currentCultureBackup;
67 currentCultureBackup = Thread.CurrentThread.CurrentCulture;
68 Thread.CurrentThread.CurrentCulture = new CultureInfo ("fi-FI");
72 public void Teardown ()
74 Thread.CurrentThread.CurrentCulture = currentCultureBackup;
78 public void SingleElementTreatmentDifference ()
80 // This is one of the most complicated case. When the content
81 // type particle of 'Root' element is a complex element, it
82 // is DataSet element. Otherwise, it is just a data table.
84 // But also note that there is another test named
85 // LocaleOnRootWithoutIsDataSet(), that tests if locale on
86 // the (mere) data table modifies *DataSet's* locale.
88 // Moreover, when the schema contains another element
89 // (regardless of its schema type), the elements will
90 // never be treated as a DataSet.
91 string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
92 <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
101 string xsbase2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
102 <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
109 <xs:element name='more' type='xs:string' />
112 string simple = "<xs:element name='Child' type='xs:string' />";
113 string complex = @"<xs:element name='Child'>
115 <xs:attribute name='a1' />
116 <xs:attribute name='a2' type='xs:integer' />
119 string elref = "<xs:element ref='more' />";
121 string xs2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
122 <xs:element name='Root' type='RootType' />
123 <xs:complexType name='RootType'>
125 <xs:element name='Child'>
127 <xs:attribute name='a1' />
128 <xs:attribute name='a2' type='xs:integer' />
135 DataSet ds = new DataSet ();
137 string xs = String.Format (xsbase, simple);
138 ds.ReadXmlSchema (new StringReader (xs));
139 AssertDataSet ("simple", ds, "hoge", 1, 0);
140 AssertDataTable ("simple", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
142 // reference to global complex type
144 ds.ReadXmlSchema (new StringReader (xs2));
145 AssertDataSet ("external complexType", ds, "hoge", 2, 1);
146 AssertDataTable ("external Tab1", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);
147 AssertDataTable ("external Tab2", ds.Tables [1], "Child", 3, 0, 1, 0, 1, 0);
149 // xsbase2 + complex -> datatable
151 xs = String.Format (xsbase2, complex);
152 ds.ReadXmlSchema (new StringReader (xs));
153 AssertDataSet ("complex", ds, "hoge", 2, 1);
154 AssertDataTable ("complex", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);
155 DataTable dt = ds.Tables [1];
156 AssertDataTable ("complex", dt, "Child", 3, 0, 1, 0, 1, 0);
157 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);
158 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);
159 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);
161 // xsbase + complex -> dataset
163 xs = String.Format (xsbase, complex);
164 ds.ReadXmlSchema (new StringReader (xs));
165 AssertDataSet ("complex", ds, "Root", 1, 0);
168 xs = String.Format (xsbase2, elref);
169 ds.ReadXmlSchema (new StringReader (xs));
170 AssertDataSet ("complex", ds, "hoge", 1, 0);
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.ReadXmlSchema (new StringReader (schema));
195 AssertDataSet ("ds", ds, "doc", 1, 0);
196 AssertDataTable ("table", ds.Tables [0], "elem", 2, 0, 0, 0, 0, 0);
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.ReadXmlSchema (new StringReader (xs));
219 // Here "unusedType" table is never imported.
220 AssertDataSet ("ds", ds, "hoge", 1, 0);
221 AssertDataTable ("dt", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
225 public void SimpleTypeComponentsIgnored ()
227 string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
228 <xs:element name='Root' type='xs:string'/>
229 <xs:attribute name='Attr' type='xs:string'/>
232 DataSet ds = new DataSet ();
233 ds.ReadXmlSchema (new StringReader (xs));
234 // nothing is imported.
235 AssertDataSet ("ds", ds, "NewDataSet", 0, 0);
239 public void IsDataSetAndTypeIgnored ()
241 string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
242 <xs:element name='Root' type='unusedType' msdata:IsDataSet='{0}'>
244 <xs:complexType name='unusedType'>
246 <xs:element name='Child' type='xs:string' />
251 // Even if a global element uses a complexType, it will be
252 // ignored if the element has msdata:IsDataSet='true'
253 string xs = String.Format (xsbase, "true");
255 DataSet ds = new DataSet ();
256 ds.ReadXmlSchema (new StringReader (xs));
257 AssertDataSet ("ds", ds, "Root", 0, 0); // name is "Root"
259 // But when explicit msdata:IsDataSet value is "false", then
261 xs = String.Format (xsbase, "false");
264 ds.ReadXmlSchema (new StringReader (xs));
265 AssertDataSet ("ds", ds, "NewDataSet", 1, 0);
269 [ExpectedException (typeof (ArgumentException))]
270 public void NestedReferenceNotAllowed ()
272 string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
273 <xs:element name='Root' type='unusedType' msdata:IsDataSet='true'>
275 <xs:complexType name='unusedType'>
277 <xs:element name='Child' type='xs:string' />
280 <xs:element name='Foo'>
283 <xs:element ref='Root' />
289 // DataSet element cannot be converted into a DataTable.
290 // (i.e. cannot be referenced in any other elements)
291 DataSet ds = new DataSet ();
292 ds.ReadXmlSchema (new StringReader (xs));
296 public void IsDataSetOnLocalElementIgnored ()
298 string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
299 <xs:element name='Root' type='unusedType'>
301 <xs:complexType name='unusedType'>
303 <xs:element name='Child' type='xs:string' msdata:IsDataSet='True' />
308 // msdata:IsDataSet does not affect even if the value is invalid
309 string xs = String.Format (xsbase, "true");
311 DataSet ds = new DataSet ();
312 ds.ReadXmlSchema (new StringReader (xs));
313 // Child should not be regarded as DataSet element
314 AssertDataSet ("ds", ds, "NewDataSet", 1, 0);
318 public void LocaleOnRootWithoutIsDataSet ()
320 string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
321 <xs:element name='Root' msdata:Locale='ja-JP'>
324 <xs:element name='Child' type='xs:string' />
326 <xs:attribute name='Attr' type='xs:integer' />
331 DataSet ds = new DataSet ();
332 ds.ReadXmlSchema (new StringReader (xs));
333 AssertDataSet ("ds", ds, "NewDataSet", 1, 0);
334 Assert.AreEqual ("fi-FI", ds.Locale.Name); // DataSet's Locale comes from current thread
335 DataTable dt = ds.Tables [0];
336 AssertDataTable ("dt", dt, "Root", 2, 0, 0, 0, 0, 0);
337 Assert.AreEqual ("ja-JP", dt.Locale.Name); // DataTable's Locale comes from msdata:Locale
338 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);
339 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);
344 public void ElementHasIdentityConstraint ()
346 string constraints = @"
348 <xs:selector xpath='./any/string_is_OK/R1'/>
349 <xs:field xpath='Child2'/>
351 <xs:keyref name='kref' refer='key'>
352 <xs:selector xpath='.//R2'/>
353 <xs:field xpath='Child2'/>
355 string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
356 <xs:element name='DS' msdata:IsDataSet='true'>
359 <xs:element ref='R1' />
360 <xs:element ref='R2' />
365 <xs:element name='R1' type='RootType'>
368 <xs:element name='R2' type='RootType'>
370 <xs:complexType name='RootType'>
372 <xs:element name='Child1' type='xs:string'>
375 <xs:element name='Child2' type='xs:string' />
377 <xs:attribute name='Attr' type='xs:integer' />
381 // Constraints on DataSet element.
382 // Note that in xs:key xpath is crazy except for the last step
383 string xs = String.Format (xsbase, constraints, String.Empty, String.Empty);
384 DataSet ds = new DataSet ();
385 ds.ReadXmlSchema (new StringReader (xs));
386 Assert.AreEqual (1, ds.Relations.Count);
388 // Constraints on another global element - just ignored
389 xs = String.Format (xsbase, String.Empty, constraints, String.Empty);
391 ds.ReadXmlSchema (new StringReader (xs));
392 Assert.AreEqual (0, ds.Relations.Count);
394 // Constraints on local element - just ignored
395 xs = String.Format (xsbase, String.Empty, String.Empty, constraints);
397 ds.ReadXmlSchema (new StringReader (xs));
398 Assert.AreEqual (0, ds.Relations.Count);
402 public void PrefixedTargetNS ()
404 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'>
405 <xs:element name='DS' msdata:IsDataSet='true'>
408 <xs:element ref='x:R1' />
409 <xs:element ref='x:R2' />
413 <xs:selector xpath='./any/string_is_OK/x:R1'/>
414 <xs:field xpath='x:Child2'/>
416 <xs:keyref name='kref' refer='x:key'>
417 <xs:selector xpath='.//x:R2'/>
418 <xs:field xpath='x:Child2'/>
421 <xs:element name='R3' type='x:RootType' />
422 <xs:complexType name='extracted'>
424 <xs:element ref='x:R1' />
425 <xs:element ref='x:R2' />
428 <xs:element name='R1' type='x:RootType'>
429 <xs:unique name='Rkey'>
430 <xs:selector xpath='.//x:Child1'/>
431 <xs:field xpath='.'/>
433 <xs:keyref name='Rkref' refer='x:Rkey'>
434 <xs:selector xpath='.//x:Child2'/>
435 <xs:field xpath='.'/>
438 <xs:element name='R2' type='x:RootType'>
440 <xs:complexType name='RootType'>
442 <xs:element name='Child1' type='xs:string'>
444 <xs:element name='Child2' type='xs:string' />
446 <xs:attribute name='Attr' type='xs:integer' />
449 // No prefixes on tables and columns
450 DataSet ds = new DataSet ();
451 ds.ReadXmlSchema (new StringReader (xs));
452 AssertDataSet ("ds", ds, "DS", 3, 1);
453 DataTable dt = ds.Tables [0];
454 AssertDataTable ("R3", dt, "R3", 3, 0, 0, 0, 0, 0);
455 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);
459 public void ReadTest1 ()
461 DataSet ds = CreateTestSet ();
463 StringWriter sw = new StringWriter ();
464 ds.WriteXmlSchema (sw);
466 string schema = sw.ToString ();
470 ds.ReadXmlSchema (new XmlTextReader (schema, XmlNodeType.Document, null));
473 // ReadXml() should also be the same
475 ds.ReadXml (new XmlTextReader (schema, XmlNodeType.Document, null));
479 private void ReadTest1Check (DataSet ds)
481 AssertDataSet ("dataset", ds, "NewDataSet", 2, 1);
482 AssertDataTable ("tbl1", ds.Tables [0], "Table1", 3, 0, 0, 1, 1, 0);
483 AssertDataTable ("tbl2", ds.Tables [1], "Table2", 3, 0, 1, 0, 1, 0);
485 DataRelation rel = ds.Relations [0];
486 AssertDataRelation ("rel", rel, "Rel1", false,
487 new string [] {"Column1_3"},
488 new string [] {"Column2_1"}, true, true);
489 AssertUniqueConstraint ("uc", rel.ParentKeyConstraint,
490 "Constraint1", false, new string [] {"Column1_3"});
491 AssertForeignKeyConstraint ("fk", rel.ChildKeyConstraint, "Rel1",
492 AcceptRejectRule.None, Rule.Cascade, Rule.Cascade,
493 new string [] {"Column2_1"},
494 new string [] {"Column1_3"});
499 public void TestSampleFileNoTables ()
501 DataSet ds = new DataSet ();
502 ds.ReadXmlSchema ("Test/System.Data/schemas/test001.xsd");
503 AssertDataSet ("001", ds, "NewDataSet", 0, 0);
506 ds.ReadXmlSchema ("Test/System.Data/schemas/test002.xsd");
507 AssertDataSet ("002", ds, "NewDataSet", 0, 0);
510 ds.ReadXmlSchema ("Test/System.Data/schemas/test003.xsd");
511 AssertDataSet ("003", ds, "NewDataSet", 0, 0);
514 ds.ReadXmlSchema ("Test/System.Data/schemas/test004.xsd");
515 AssertDataSet ("004", ds, "NewDataSet", 0, 0);
519 public void TestSampleFileSimpleTables ()
521 DataSet ds = new DataSet ();
522 ds.ReadXmlSchema ("Test/System.Data/schemas/test005.xsd");
523 AssertDataSet ("005", ds, "NewDataSet", 1, 0);
524 DataTable dt = ds.Tables [0];
525 AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
526 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);
527 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);
530 ds.ReadXmlSchema ("Test/System.Data/schemas/test006.xsd");
531 AssertDataSet ("006", ds, "NewDataSet", 1, 0);
533 AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
534 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);
535 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);
539 public void TestSampleFileComplexTables ()
541 // Nested simple type element
542 DataSet ds = new DataSet ();
543 ds.ReadXmlSchema ("Test/System.Data/schemas/test007.xsd");
544 AssertDataSet ("007", ds, "NewDataSet", 2, 1);
545 DataTable dt = ds.Tables [0];
546 AssertDataTable ("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);
547 AssertDataColumn ("id", dt.Columns [0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, true);
550 AssertDataTable ("tab2", dt, "des", 2, 0, 1, 0, 1, 0);
551 AssertDataColumn ("child", dt.Columns [0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
552 AssertDataColumn ("id", dt.Columns [1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
554 // External simple type element
556 ds.ReadXmlSchema ("Test/System.Data/schemas/test008.xsd");
557 AssertDataSet ("008", ds, "NewDataSet", 2, 1);
559 AssertDataTable ("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);
560 AssertDataColumn ("id", dt.Columns [0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, true);
563 AssertDataTable ("tab2", dt, "des", 2, 0, 1, 0, 1, 0);
564 AssertDataColumn ("child", dt.Columns [0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, false);
565 AssertDataColumn ("id", dt.Columns [1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
570 [Category ("NotDotNet")]
571 // MS.NET has a bug on handling default value of referenced
573 public void TestSampleFileValueConstraints ()
575 DataSet ds = new DataSet ();
576 ds.ReadXmlSchema ("Test/System.Data/schemas/test009.xsd");
577 AssertDataSet ("009", ds, "NewDataSet", 2, 1);
579 DataTable dt = ds.Tables [0];
580 AssertDataTable ("tab1", dt, "uno", 2, 0, 0, 1, 1, 1);
581 AssertDataColumn ("global", dt.Columns [0], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "er", String.Empty, -1, "urn:foo", 0, String.Empty, false, false);
582 AssertDataColumn ("id", dt.Columns [1], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 1, String.Empty, false, true);
584 // Here "XmlSchemaComplexType.AttributeUses" does not
585 // always return attribute uses in a certain order, thus
586 // here Columns indexer is accessed by name (actually
587 // MS.NET returns "global" in prior to "local" for
588 // Columns[0], even though "local" is defined in prior.
590 AssertDataTable ("dos", dt, "des", 4, 0, 1, 0, 1, 0);
591 AssertDataColumn ("dos.child", dt.Columns ["local"], "local", true, false, 0, 1, "local", MappingType.Attribute, typeof (string), "san", String.Empty, -1, String.Empty, /*0*/-1, String.Empty, false, false);
592 // LAMESPEC: (MS BUG) default value is overwritten, but MS.NET is ignorant of that.
593 #if BUGGY_MS_COMPATIBLE
594 AssertDataColumn ("dos.global", dt.Columns ["global"], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "er", String.Empty, -1, "urn:foo", /*1*/-1, String.Empty, false, false);
596 AssertDataColumn ("dos.global", dt.Columns ["global"], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "si", String.Empty, -1, "urn:foo", /*1*/-1, String.Empty, false, false);
598 AssertDataColumn ("dos.tres", dt.Columns [2], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), "yi", String.Empty, -1, "urn:foo", 2, String.Empty, false, false);
599 AssertDataColumn ("uno.id", dt.Columns [3], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 3, String.Empty, false, false);
601 AssertDataRelation ("rel", ds.Relations [0], "uno_des", true, new string [] {"uno_Id"}, new string [] {"uno_Id"}, true, true);
605 [Category ("NotWorking")]
606 public void TestSampleFileImportSimple ()
608 DataSet ds = new DataSet ();
609 XmlTextReader xtr = null;
611 xtr = new XmlTextReader ("Test/System.Data/schemas/test010.xsd");
612 xtr.XmlResolver = null;
613 ds.ReadXmlSchema (xtr);
618 AssertDataSet ("010", ds, "NewDataSet", 1, 0);
620 DataTable dt = ds.Tables [0];
621 AssertDataTable ("root", dt, "foo", 1, 0, 0, 0, 0, 0);
622 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);
626 [Category ("NotWorking")]
627 public void TestSampleFileComplexTables2 ()
629 DataSet ds = new DataSet ();
630 ds.ReadXmlSchema ("Test/System.Data/schemas/test011.xsd");
631 AssertDataSet ("011", ds, "NewDataSet", 2, 1);
633 DataTable dt = ds.Tables [0];
634 AssertDataTable ("root", dt, "e", 3, 0, 1, 0, 1, 0);
635 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);
636 AssertDataColumn ("simple", dt.Columns [1], "e_text", false, false, 0, 1, "e_text", MappingType.SimpleContent, typeof (decimal), DBNull.Value, String.Empty, -1, "http://xsdtesting", 1, String.Empty, false, false);
637 AssertDataColumn ("hidden", dt.Columns [2], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "http://xsdtesting", 2, String.Empty, false, false);
640 AssertDataTable ("root", dt, "root", 1, 0, 0, 1, 1, 1);
641 AssertDataColumn ("elem", dt.Columns [0], "root_Id", false, true, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "http://xsdtesting", 0, String.Empty, false, true);
643 AssertDataRelation ("rel", ds.Relations [0], "root_e", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
647 public void TestSampleFileComplexTables3 ()
649 DataSet ds = new DataSet ();
650 ds.ReadXmlSchema ("Test/System.Data/schemas/test013.xsd");
651 AssertDataSet ("013", ds, "root", 1, 0);
653 DataTable dt = ds.Tables [0];
654 AssertDataTable ("root", dt, "e", 2, 0, 0, 0, 0, 0);
655 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);
656 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);
661 public void TestSampleFileXPath ()
663 DataSet ds = new DataSet ();
664 ds.ReadXmlSchema ("Test/System.Data/schemas/test103.xsd");
668 public void TestAnnotatedRelation1 ()
670 DataSet ds = new DataSet ();
671 ds.ReadXmlSchema ("Test/System.Data/schemas/test101.xsd");
672 AssertDataSet ("101", ds, "root", 2, 1);
673 DataTable dt = ds.Tables [0];
674 AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);
675 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);
678 AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);
679 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);
681 AssertDataRelation ("rel", ds.Relations [0], "rel", false, new string [] {"pk"}, new string [] {"fk"}, false, false);
685 public void TestAnnotatedRelation2 ()
687 DataSet ds = new DataSet ();
688 ds.ReadXmlSchema ("Test/System.Data/schemas/test102.xsd");
689 AssertDataSet ("102", ds, "ds", 2, 1);
690 DataTable dt = ds.Tables [0];
691 AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);
692 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);
695 AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);
696 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);
698 AssertDataRelation ("rel", ds.Relations [0], "rel", true, new string [] {"pk"}, new string [] {"fk"}, false, false);
702 public void RepeatableSimpleElement ()
704 DataSet ds = new DataSet ();
705 ds.ReadXmlSchema ("Test/System.Data/schemas/test012.xsd");
706 AssertDataSet ("012", ds, "NewDataSet", 2, 1);
707 DataTable dt = ds.Tables [0];
708 AssertDataTable ("parent", dt, "Foo", 1, 0, 0, 1, 1, 1);
709 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);
712 AssertDataTable ("repeated", dt, "Bar", 2, 0, 1, 0, 1, 0);
713 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);
714 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);
716 AssertDataRelation ("rel", ds.Relations [0], "Foo_Bar", true, new string [] {"Foo_Id"}, new string [] {"Foo_Id"}, true, true);
720 public void TestMoreThanOneRepeatableColumns ()
722 DataSet ds = new DataSet ();
723 ds.ReadXmlSchema ("Test/System.Data/schemas/test014.xsd");
724 AssertDataSet ("014", ds, "NewDataSet", 3, 2);
726 DataTable dt = ds.Tables [0];
727 AssertDataTable ("parent", dt, "root", 1, 0, 0, 2, 1, 1);
728 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);
731 AssertDataTable ("repeated", dt, "x", 2, 0, 1, 0, 1, 0);
732 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);
733 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);
736 AssertDataTable ("repeated", dt, "y", 2, 0, 1, 0, 1, 0);
737 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);
738 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);
740 AssertDataRelation ("rel", ds.Relations [0], "root_x", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
742 AssertDataRelation ("rel", ds.Relations [1], "root_y", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
746 public void AutoIncrementStep ()
748 DataSet ds = new DataSet("testds");
749 DataTable tbl = ds.Tables.Add("testtbl");
750 DataColumn col = tbl.Columns.Add("id", typeof(int));
751 col.AutoIncrement = true;
752 col.AutoIncrementSeed = -1;
753 col.AutoIncrementStep = -1;
754 tbl.Columns.Add("data", typeof(string));
755 Assert.IsTrue (ds.GetXmlSchema ().IndexOf ("AutoIncrementStep") > 0);
759 public void ReadConstraints ()
761 DataSet ds = new DataSet ();
762 ds.ReadXmlSchema ("Test/System.Data/schemas/test015.xsd");
764 Assert.AreEqual (0, ds.Relations.Count, "#1");
765 Assert.AreEqual (1, ds.Tables [0].Constraints.Count, "#2" );
766 Assert.AreEqual (1, ds.Tables [1].Constraints.Count, "#3" );
767 Assert.AreEqual ("fk1", ds.Tables [1].Constraints [0].ConstraintName, "#4");
771 public void ReadAnnotatedRelations_MultipleColumns ()
773 DataSet ds = new DataSet ();
774 ds.ReadXmlSchema ("Test/System.Data/schemas/test016.xsd");
776 Assert.AreEqual (1, ds.Relations.Count, "#1");
777 Assert.AreEqual ("rel", ds.Relations [0].RelationName, "#2");
778 Assert.AreEqual (2, ds.Relations [0].ParentColumns.Length, "#3");
779 Assert.AreEqual (2, ds.Relations [0].ChildColumns.Length, "#4");
780 Assert.AreEqual (0, ds.Tables [0].Constraints.Count, "#5" );
781 Assert.AreEqual (0, ds.Tables [1].Constraints.Count, "#6" );
783 AssertDataRelation ("TestRel", ds.Relations [0], "rel", false, new String[] {"col 1","col2"},
784 new String[] {"col1","col 2"}, false, false);