2 // DataSetInferXmlSchemaTest.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.
33 using System
.Collections
;
37 using NUnit
.Framework
;
39 namespace MonoTests
.System
.Data
42 public class DataSetInferXmlSchemaTest
: DataSetAssertion
44 string xml1
= "<root/>";
45 string xml2
= "<root attr='value' />";
46 string xml3
= "<root attr='value' attr2='2' />";
47 string xml4
= "<root>simple.txt</root>";
48 string xml5
= "<root><child/></root>";
49 string xml6
= "<root><col1>sample</col1></root>";
50 string xml7
= @"<root>
51 <col1>column 1 test</col1>
52 <col2>column2test</col2>
62 string xml9
= @"<el1 attr1='val1' attrA='valA'>
63 <el2 attr2='val2' attrB='valB'>
64 <el3 attr3='val3' attrC='valC'>3</el3>
67 <el4 attr4='val4' attrD='valD'>4</el4>
71 string xml10
= "<root>Here is a <b>mixed</b> content.</root>";
73 string xml11
= @"<root xml:space='preserve'>
74 <child_after_significant_space />
76 // This is useless ... since xml:space becomes a DataColumn here.
77 // string xml12 = "<root xml:space='preserve'> </root>";
78 // The result is silly under MS.NET. It never ignores comment, so
80 // 1) <root>simple string.</root>
81 // 2) <root>simple <!-- comment -->string.</root>
82 // The same applies to PI.
83 // string xml13 = "<root><tab><col>test <!-- out --> comment</col></tab></root>";
85 // simple namespace/prefix support
86 string xml14
= "<p:root xmlns:p='urn:foo'>test string</p:root>";
87 // two tables that have the same content type.
88 string xml15
= @"<root>
90 <col1_1>test1</col1_1>
91 <col1_2>test2</col1_2>
94 <col2_1>test1</col2_1>
95 <col2_2>test2</col2_2>
98 // foo cannot be both table chikd and root child
99 string xml16
= @"<root>
102 <tableFooChild1>1</tableFooChild1>
103 <tableFooChild2>2</tableFooChild2>
110 // simple namespace support
111 string xml17
= @"<root xmlns='urn:foo' />";
112 // conflict between simple and complex type element col
113 string xml18
= @"<set>
118 <col>simple text here.</col>
121 // variant of xml18: complex column appeared latter
122 string xml19
=@"<set>
124 <col>simple text</col><!-- ignored -->
130 // conflict check (actually it is not conflict) on two "col" tables
131 string xml20
= @"<set>
139 // conflict between the attribute and the child element
140 string xml21
= @"<set>
148 string xml22
= "<set><table><col><descendant/></col></table><table2><col2>v2</col2></table2></set>";
150 string xml23
= @"<set>
151 <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
152 <xs:element name='table'>
161 xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'
162 xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1'>
169 string xml24
= "<p1><p2><p3><p4><p5><p6/></p5></p4></p3></p2></p1>";
172 private DataSet
GetDataSet (string xml
, string [] nss
)
174 DataSet ds
= new DataSet ();
175 ds
.InferXmlSchema (new XmlTextReader (xml
, XmlNodeType
.Document
, null), nss
);
180 public void NullFileName ()
182 DataSet ds
= new DataSet ();
183 ds
.InferXmlSchema ((XmlReader
) null, null);
184 AssertDataSet ("null", ds
, "NewDataSet", 0, 0);
188 public void SingleElement ()
190 DataSet ds
= GetDataSet (xml1
, null);
191 AssertDataSet ("xml1", ds
, "root", 0, 0);
193 ds
= GetDataSet (xml4
, null);
194 AssertDataSet ("xml4", ds
, "root", 0, 0);
197 ds
= GetDataSet (xml14
, null);
198 AssertDataSet ("xml14", ds
, "root", 0, 0);
199 AssertEquals ("p", ds
.Prefix
);
200 AssertEquals ("urn:foo", ds
.Namespace
);
202 ds
= GetDataSet (xml17
, null);
203 AssertDataSet ("xml17", ds
, "root", 0, 0);
204 AssertEquals ("urn:foo", ds
.Namespace
);
208 public void SingleElementWithAttribute ()
210 DataSet ds
= GetDataSet (xml2
, null);
211 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
212 DataTable dt
= ds
.Tables
[0];
213 AssertDataTable ("dt", dt
, "root", 1, 0, 0, 0, 0, 0);
214 AssertDataColumn ("col", 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);
218 public void SingleElementWithTwoAttribute ()
220 DataSet ds
= GetDataSet (xml3
, null);
221 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
222 DataTable dt
= ds
.Tables
[0];
223 AssertDataTable ("dt", dt
, "root", 2, 0, 0, 0, 0, 0);
224 AssertDataColumn ("col", 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);
225 AssertDataColumn ("col", dt
.Columns
[1], "attr2", true, false, 0, 1, "attr2", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
229 public void SingleChild ()
231 DataSet ds
= GetDataSet (xml5
, null);
232 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
233 DataTable dt
= ds
.Tables
[0];
234 AssertDataTable ("dt", dt
, "root", 1, 0, 0, 0, 0, 0);
235 AssertDataColumn ("col", dt
.Columns
[0], "child", true, false, 0, 1, "child", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
237 ds
= GetDataSet (xml6
, null);
238 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
240 AssertDataTable ("dt", dt
, "root", 1, 0, 0, 0, 0, 0);
241 AssertDataColumn ("col", dt
.Columns
[0], "col1", true, false, 0, 1, "col1", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
245 public void SimpleElementTable ()
247 DataSet ds
= GetDataSet (xml7
, null);
248 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
249 DataTable dt
= ds
.Tables
[0];
250 AssertDataTable ("dt", dt
, "root", 3, 0, 0, 0, 0, 0);
251 AssertDataColumn ("col", dt
.Columns
[0], "col1", true, false, 0, 1, "col1", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
252 AssertDataColumn ("col2", dt
.Columns
[1], "col2", true, false, 0, 1, "col2", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
253 AssertDataColumn ("col3", dt
.Columns
[2], "col3", true, false, 0, 1, "col3", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 2, String
.Empty
, false, false);
257 public void SimpleDataSet ()
259 DataSet ds
= GetDataSet (xml8
, null);
260 AssertDataSet ("ds", ds
, "set", 1, 0);
261 DataTable dt
= ds
.Tables
[0];
262 AssertDataTable ("dt", dt
, "tab", 3, 0, 0, 0, 0, 0);
263 AssertDataColumn ("col", dt
.Columns
[0], "col1", true, false, 0, 1, "col1", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
264 AssertDataColumn ("col2", dt
.Columns
[1], "col2", true, false, 0, 1, "col2", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
265 AssertDataColumn ("col3", dt
.Columns
[2], "col3", true, false, 0, 1, "col3", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 2, String
.Empty
, false, false);
269 public void ComplexElementAttributeTable1 ()
271 // FIXME: Also test ReadXml (, XmlReadMode.InferSchema) and
272 // make sure that ReadXml() stores DataRow to el1 (and maybe to others)
273 DataSet ds
= GetDataSet (xml9
, null);
274 AssertDataSet ("ds", ds
, "NewDataSet", 4, 3);
275 DataTable dt
= ds
.Tables
[0];
277 AssertDataTable ("dt1", dt
, "el1", 3, 0, 0, 1, 1, 1);
278 AssertDataColumn ("el1_Id", dt
.Columns
[0], "el1_Id", false, true, 0, 1, "el1_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, true);
279 AssertDataColumn ("el1_attr1", dt
.Columns
[1], "attr1", true, false, 0, 1, "attr1", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
280 AssertDataColumn ("el1_attrA", dt
.Columns
[2], "attrA", true, false, 0, 1, "attrA", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 2, String
.Empty
, false, false);
283 AssertDataTable ("dt2", dt
, "el2", 6, 0, 1, 2, 2, 1);
284 AssertDataColumn ("el2_Id", dt
.Columns
[0], "el2_Id", false, true, 0, 1, "el2_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, true);
285 AssertDataColumn ("el2_col2", dt
.Columns
[1], "column2", true, false, 0, 1, "column2", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
286 AssertDataColumn ("el2_col3", dt
.Columns
[2], "column3", true, false, 0, 1, "column3", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 2, String
.Empty
, false, false);
287 AssertDataColumn ("el2_attr2", dt
.Columns
[3], "attr2", true, false, 0, 1, "attr2", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 3, String
.Empty
, false, false);
288 AssertDataColumn ("el2_attrB", dt
.Columns
[4], "attrB", true, false, 0, 1, "attrB", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 4, String
.Empty
, false, false);
289 AssertDataColumn ("el2_el1Id", dt
.Columns
[5], "el1_Id", true, false, 0, 1, "el1_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 5, String
.Empty
, false, false);
292 AssertDataTable ("dt3", dt
, "el3", 4, 0, 1, 0, 1, 0);
293 AssertDataColumn ("el3_attr3", dt
.Columns
[0], "attr3", true, false, 0, 1, "attr3", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
294 AssertDataColumn ("el3_attrC", dt
.Columns
[1], "attrC", true, false, 0, 1, "attrC", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
295 AssertDataColumn ("el3_Text", dt
.Columns
[2], "el3_Text", true, false, 0, 1, "el3_Text", MappingType
.SimpleContent
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 2, String
.Empty
, false, false);
296 AssertDataColumn ("el3_el2Id", dt
.Columns
[3], "el2_Id", true, false, 0, 1, "el2_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 3, String
.Empty
, false, false);
299 AssertDataTable ("dt4", dt
, "el4", 4, 0, 1, 0, 1, 0);
300 AssertDataColumn ("el3_attr4", dt
.Columns
[0], "attr4", true, false, 0, 1, "attr4", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
301 AssertDataColumn ("el4_attrD", dt
.Columns
[1], "attrD", true, false, 0, 1, "attrD", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
302 AssertDataColumn ("el4_Text", dt
.Columns
[2], "el4_Text", true, false, 0, 1, "el4_Text", MappingType
.SimpleContent
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 2, String
.Empty
, false, false);
303 AssertDataColumn ("el4_el2Id", dt
.Columns
[3], "el2_Id", true, false, 0, 1, "el2_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 3, String
.Empty
, false, false);
307 public void MixedContent ()
309 // Note that text part is ignored.
311 DataSet ds
= GetDataSet (xml10
, null);
312 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
313 DataTable dt
= ds
.Tables
[0];
314 AssertDataTable ("dt", dt
, "root", 1, 0, 0, 0, 0, 0);
315 AssertDataColumn ("col", dt
.Columns
[0], "b", true, false, 0, 1, "b", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
319 public void SignificantWhitespaceIgnored ()
321 // Note that 1) significant whitespace is ignored, and
322 // 2) xml:space is treated as column (and also note namespaces).
323 DataSet ds
= GetDataSet (xml11
, null);
324 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
325 DataTable dt
= ds
.Tables
[0];
326 AssertDataTable ("dt", dt
, "root", 2, 0, 0, 0, 0, 0);
327 AssertDataColumn ("element", dt
.Columns
[0], "child_after_significant_space", true, false, 0, 1, "child_after_significant_space", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
328 AssertDataColumn ("xml:space", dt
.Columns
[1], "space", true, false, 0, 1, "space", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, "http://www.w3.org/XML/1998/namespace", 1, "xml", false, false);
332 public void SignificantWhitespaceIgnored2 ()
334 // To make sure, create pure significant whitespace element
335 // using XmlNodeReader (that does not have xml:space attribute
337 DataSet ds
= new DataSet ();
338 XmlDocument doc
= new XmlDocument ();
339 doc
.AppendChild (doc
.CreateElement ("root"));
340 doc
.DocumentElement
.AppendChild (doc
.CreateSignificantWhitespace
342 XmlReader xr
= new XmlNodeReader (doc
);
343 ds
.InferXmlSchema (xr
, null);
344 AssertDataSet ("pure_whitespace", ds
, "root", 0, 0);
348 public void TwoElementTable ()
350 // FIXME: Also test ReadXml (, XmlReadMode.InferSchema) and
351 // make sure that ReadXml() stores DataRow to el1 (and maybe to others)
352 DataSet ds
= GetDataSet (xml15
, null);
353 AssertDataSet ("ds", ds
, "root", 2, 0);
355 DataTable dt
= ds
.Tables
[0];
356 AssertDataTable ("dt", dt
, "table1", 2, 0, 0, 0, 0, 0);
357 AssertDataColumn ("col1_1", dt
.Columns
[0], "col1_1", true, false, 0, 1, "col1_1", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
358 AssertDataColumn ("col1_2", dt
.Columns
[1], "col1_2", true, false, 0, 1, "col1_2", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
361 AssertDataTable ("dt", dt
, "table2", 2, 0, 0, 0, 0, 0);
362 AssertDataColumn ("col2_1", dt
.Columns
[0], "col2_1", true, false, 0, 1, "col2_1", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
363 AssertDataColumn ("col2_2", dt
.Columns
[1], "col2_2", true, false, 0, 1, "col2_2", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
367 [ExpectedException (typeof (ArgumentException
))]
368 // The same table cannot be the child table in two nested relations.
369 public void ComplexElementTable1 ()
371 // TODO: Also test ReadXml (, XmlReadMode.InferSchema) and
372 // make sure that ReadXml() stores DataRow to el1 (and maybe to others)
373 DataSet ds
= GetDataSet (xml16
, null);
375 AssertDataSet ("ds", ds, "NewDataSet", 4, 0);
377 DataTable dt = ds.Tables [0];
378 AssertDataTable ("dt", dt, "root", 2, 0);
379 AssertDataColumn ("table#1_id", 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);
380 AssertDataColumn ("table#1_bar", dt.Columns [1], "bar", true, false, 0, 1, "bar", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
383 AssertDataTable ("dt2", dt, "table", 3, 0);
384 AssertDataColumn ("table#2_id", dt.Columns [0], "table_Id", false, true, 0, 1, "table_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, true);
385 AssertDataColumn ("table#2_bar", dt.Columns [1], "bar", true, false, 0, 1, "bar", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
386 AssertDataColumn ("table#2_refid", dt.Columns [0], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 2, String.Empty, false, false);
389 AssertDataTable ("dt3", dt, "foo", 3, 0);
390 AssertDataColumn ("table#3_col1", dt.Columns [0], "tableFooChild1", true, false, 0, 1, "tableFooChild1", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
391 AssertDataColumn ("table#3_col2", dt.Columns [0], "tableFooChild2", true, false, 0, 1, "tableFooChild2", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
392 AssertDataColumn ("table#3_refid", dt.Columns [0], "table_Id", true, false, 0, 1, "table_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 2, String.Empty, false, false);
397 public void ConflictSimpleComplexColumns ()
399 DataSet ds
= GetDataSet (xml18
, null);
400 AssertDataSet ("ds", ds
, "set", 2, 1);
402 DataTable dt
= ds
.Tables
[0];
403 AssertDataTable ("dt", dt
, "table", 1, 0, 0, 1, 1, 1);
404 AssertDataColumn ("table_Id", dt
.Columns
[0], "table_Id", false, true, 0, 1, "table_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, true);
407 AssertDataTable ("dt", dt
, "col", 2, 0, 1, 0, 1, 0);
408 AssertDataColumn ("another_col", dt
.Columns
[0], "another_col", true, false, 0, 1, "another_col", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
409 AssertDataColumn ("table_refId", dt
.Columns
[1], "table_Id", true, false, 0, 1, "table_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 1, String
.Empty
, false, false);
411 DataRelation dr
= ds
.Relations
[0];
412 AssertDataRelation ("rel", dr
, "table_col", true, new string [] {"table_Id"}
, new string [] {"table_Id"}
, true, true);
413 AssertUniqueConstraint ("uniq", dr
.ParentKeyConstraint
, "Constraint1", true, new string [] {"table_Id"}
);
414 AssertForeignKeyConstraint ("fkey", dr
.ChildKeyConstraint
, "table_col", AcceptRejectRule
.None
, Rule
.Cascade
, Rule
.Cascade
, new string [] {"table_Id"}
, new string [] {"table_Id"}
);
418 public void ConflictColumnTable ()
420 DataSet ds
= GetDataSet (xml19
, null);
421 AssertDataSet ("ds", ds
, "set", 2, 1);
423 DataTable dt
= ds
.Tables
[0];
424 AssertDataTable ("dt", dt
, "table", 1, 0, 0, 1, 1, 1);
425 AssertDataColumn ("table_Id", dt
.Columns
[0], "table_Id", false, true, 0, 1, "table_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, true);
428 AssertDataTable ("dt", dt
, "col", 2, 0, 1, 0, 1, 0);
429 AssertDataColumn ("table_refId", dt
.Columns
["table_Id"], "table_Id", true, false, 0, 1, "table_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, /*0*/-1, String
.Empty
, false, false);
430 AssertDataColumn ("another_col", dt
.Columns
["another_col"], "another_col", true, false, 0, 1, "another_col", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, /*1*/-1, String
.Empty
, false, false);
432 DataRelation dr
= ds
.Relations
[0];
433 AssertDataRelation ("rel", dr
, "table_col", true, new string [] {"table_Id"}
, new string [] {"table_Id"}
, true, true);
434 AssertUniqueConstraint ("uniq", dr
.ParentKeyConstraint
, "Constraint1", true, new string [] {"table_Id"}
);
435 AssertForeignKeyConstraint ("fkey", dr
.ChildKeyConstraint
, "table_col", AcceptRejectRule
.None
, Rule
.Cascade
, Rule
.Cascade
, new string [] {"table_Id"}
, new string [] {"table_Id"}
);
439 public void ConflictColumnTableAttribute ()
441 // Conflicts between a column and a table, additionally an attribute.
442 DataSet ds
= GetDataSet (xml20
, null);
443 AssertDataSet ("ds", ds
, "set", 2, 1);
445 DataTable dt
= ds
.Tables
[0];
446 AssertDataTable ("dt", dt
, "table", 1, 0, 0, 1, 1, 1);
447 AssertDataColumn ("table_Id", dt
.Columns
[0], "table_Id", false, true, 0, 1, "table_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, true);
450 AssertDataTable ("dt", dt
, "col", 3, 0, 1, 0, 1, 0);
451 AssertDataColumn ("another_col", dt
.Columns
[0], "another_col", true, false, 0, 1, "another_col", MappingType
.Element
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, 0, String
.Empty
, false, false);
452 AssertDataColumn ("table_refId", dt
.Columns
["table_Id"], "table_Id", true, false, 0, 1, "table_Id", MappingType
.Hidden
, typeof (int), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, /*1*/-1, String
.Empty
, false, false);
453 AssertDataColumn ("attr", dt
.Columns
["attr"], "attr", true, false, 0, 1, "attr", MappingType
.Attribute
, typeof (string), DBNull
.Value
, String
.Empty
, -1, String
.Empty
, /*2*/-1, String
.Empty
, false, false);
455 DataRelation dr
= ds
.Relations
[0];
456 AssertDataRelation ("rel", dr
, "table_col", true, new string [] {"table_Id"}
, new string [] {"table_Id"}
, true, true);
457 AssertUniqueConstraint ("uniq", dr
.ParentKeyConstraint
, "Constraint1", true, new string [] {"table_Id"}
);
458 AssertForeignKeyConstraint ("fkey", dr
.ChildKeyConstraint
, "table_col", AcceptRejectRule
.None
, Rule
.Cascade
, Rule
.Cascade
, new string [] {"table_Id"}
, new string [] {"table_Id"}
);
462 [ExpectedException (typeof (DataException
))]
463 public void ConflictAttributeDataTable ()
465 // attribute "data" becomes DataTable, and when column "data"
466 // appears, it cannot be DataColumn, since the name is
467 // already allocated for DataTable.
468 DataSet ds
= GetDataSet (xml21
, null);
472 [ExpectedException (typeof (ConstraintException
))]
473 public void ConflictExistingPrimaryKey ()
475 // The 'col' DataTable tries to create another primary key (and fails)
476 DataSet ds
= new DataSet ();
477 ds
.Tables
.Add (new DataTable ("table"));
478 DataColumn c
= new DataColumn ("pk");
479 ds
.Tables
[0].Columns
.Add (c
);
480 ds
.Tables
[0].PrimaryKey
= new DataColumn
[] {c}
;
481 XmlTextReader xtr
= new XmlTextReader (xml22
, XmlNodeType
.Document
, null);
483 ds
.ReadXml (xtr
, XmlReadMode
.InferSchema
);
487 public void IgnoredNamespaces ()
489 string xml
= "<root attr='val' xmlns:a='urn:foo' a:foo='hogehoge' />";
490 DataSet ds
= new DataSet ();
491 ds
.InferXmlSchema (new StringReader (xml
), null);
492 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
493 AssertDataTable ("dt", ds
.Tables
[0], "root", 2, 0, 0, 0, 0, 0);
496 ds
.InferXmlSchema (new StringReader (xml
), new string [] {"urn:foo"}
);
497 AssertDataSet ("ds", ds
, "NewDataSet", 1, 0);
499 AssertDataTable ("dt", ds
.Tables
[0], "root", 1, 0, 0, 0, 0, 0);
503 public void ContainsSchema ()
505 DataSet ds
= new DataSet();
506 DataTable dt1
= new DataTable();
508 DataColumn dc1
= new DataColumn("Col1");
509 dt1
.Columns
.Add(dc1
);
510 dt1
.Rows
.Add(new string[] { "aaa" }
);
511 DataTable dt2
= new DataTable();
513 DataColumn dc2
= new DataColumn("Col2");
514 dt2
.Columns
.Add(dc2
);
515 dt2
.Rows
.Add(new string[] { "bbb" }
);
517 DataRelation rel
= new DataRelation("Rel1",dc1
,dc2
,false);
518 ds
.Relations
.Add(rel
);
520 StringWriter sw
= new StringWriter ();
521 ds
.WriteXml(sw
, XmlWriteMode
.WriteSchema
);
524 ds
.ReadXml(new StringReader (sw
.ToString ()));
525 sw
= new StringWriter ();
527 XmlDocument doc
= new XmlDocument ();
528 doc
.LoadXml (sw
.ToString ());
529 AssertEquals (2, doc
.DocumentElement
.ChildNodes
.Count
);