Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DeserializeTests.cs « System.Xml.Serialization « Test « System.XML « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1651d4f26ddc9e575094de105ba439d999ceb5ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
//
// System.Xml.DeserializationTests
//
// Author:
//	Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
//
// (C) 2003 Atsushi Enomoto
//
//
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using NUnit.Framework;
using MonoTests.System.Xml.TestClasses;

namespace MonoTests.System.XmlSerialization
{
	public class Sample
	{
		public string Text;
		public string [] ArrayText;
	}

	[TestFixture]
	public class DeserializationTests
	{
		object result;

		private object Deserialize (Type t, string xml)
		{
			StringReader sr = new StringReader (xml);
			XmlReader xr = new XmlTextReader (sr);
			return Deserialize (t, xr);
		}

		private object DeserializeEncoded (Type t, string xml)
		{
			StringReader sr = new StringReader (xml);
			XmlReader xr = new XmlTextReader (sr);
			return DeserializeEncoded (t, xr);
		}

		private object Deserialize (Type t, XmlReader xr)
		{
			XmlSerializer ser = new XmlSerializer (t);
			result = ser.Deserialize (xr);
			return result;
		}

		private object DeserializeEncoded (Type t, XmlReader xr)
		{
			SoapReflectionImporter im = new SoapReflectionImporter ();
			XmlTypeMapping tm = im.ImportTypeMapping (t);
			XmlSerializer ser = new XmlSerializer (tm);
			result = ser.Deserialize (xr);
			return result;
		}

		[Test]
		public void SimpleDeserialize ()
		{
			Deserialize (typeof (Sample), "<Sample><Text>Test.</Text></Sample>");
			Assertion.AssertEquals (typeof (Sample), result.GetType ());
			Sample sample = result as Sample;
			Assertion.AssertEquals ("Test.", sample.Text);
		}

		[Test]
		public void DeserializeInt ()
		{
			Deserialize (typeof (int), "<int>10</int>");
			Assertion.AssertEquals (typeof (int), result.GetType ());
			Assertion.AssertEquals (10, result);
		}

		[Test]
		public void DeserializeSimpleArray ()
		{
			Deserialize (typeof (Sample), "<Sample><ArrayText><string>Test1</string><string>Test2</string></ArrayText></Sample>");
			Assertion.AssertEquals (typeof (Sample), result.GetType ());
			Sample sample = result as Sample;
			Assertion.AssertEquals ("Test1", sample.ArrayText [0]);
			Assertion.AssertEquals ("Test2", sample.ArrayText [1]);
		}

		[Test]
		public void DeserializeEmptyEnum ()
		{
			Field f = Deserialize (typeof (Field), "<field modifiers=\"\" />") as Field;
			Assertion.AssertEquals (MapModifiers.Public, f.Modifiers);
		}
		
		[Test]
		public void DeserializePrivateCollection ()
		{
			MemoryStream ms = new MemoryStream ();
			Container c = new Container();
			c.Items.Add(1);
			
			XmlSerializer serializer = new XmlSerializer(typeof(Container));
			serializer.Serialize(ms, c);
			
			ms.Position = 0;
			c = (Container) serializer.Deserialize (ms);
			Assertion.AssertEquals (1, c.Items[0]);
		}
		
		[Test]
		[Category("NotDotNet")]
		[ExpectedException (typeof (InvalidOperationException))]
		public void DeserializeEmptyPrivateCollection ()
		{
			MemoryStream ms = new MemoryStream ();
			Container2 c = new Container2(true);
			c.Items.Add(1);
			
			XmlSerializer serializer = new XmlSerializer(typeof(Container2));
			serializer.Serialize(ms, c);
			
			ms.Position = 0;
			c = (Container2) serializer.Deserialize (ms);
		}
		
		[Test]
		[Category("NotDotNet")]
		public void DeserializeArrayReferences ()
		{
			string s = "<Sample xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
			s += "<ArrayText xmlns:n3=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"n3:Array\" n3:arrayType=\"xsd:string[2]\">";
			s += "<item href=\"#id-606830706\"></item>";
			s += "<item xsi:type=\"xsd:string\">Hola</item>";
			s += "</ArrayText>";
			s += "<string id=\"id-606830706\" xsi:type=\"xsd:string\">Adeu</string>";
			s += "</Sample>";
			DeserializeEncoded (typeof(Sample), s);
		}
		
		
		[Test]
		public void TestDeserializeXmlNodeArray ()
		{
			object ob = Deserialize (typeof(object), "<anyType at=\"1\"><elem1/><elem2/></anyType>");
			Assertion.Assert ("Is node array", ob is XmlNode[]);
			
			XmlNode[] nods = (XmlNode[]) ob; 
			Assertion.AssertEquals ("lengh", 3, nods.Length);
			Assertion.Assert ("#1", nods[0] is XmlAttribute);
			Assertion.AssertEquals ("#2", "at", ((XmlAttribute)nods[0]).LocalName);
			Assertion.AssertEquals ("#3", "1", ((XmlAttribute)nods[0]).Value);
			Assertion.Assert ("#4", nods[1] is XmlElement);
			Assertion.AssertEquals ("#5", "elem1", ((XmlElement)nods[1]).LocalName);
			Assertion.Assert ("#6", nods[2] is XmlElement);
			Assertion.AssertEquals ("#7", "elem2", ((XmlElement)nods[2]).LocalName);
		}
		
		[Test]
		public void TestDeserializeXmlElement ()
		{
			object ob = Deserialize (typeof(XmlElement), "<elem/>");
			Assertion.Assert ("#1", ob is XmlElement);
			Assertion.AssertEquals ("#2", "elem", ((XmlElement)ob).LocalName);
		}
		
		[Test]
		public void TestDeserializeXmlCDataSection ()
		{
			CDataContainer c = (CDataContainer) Deserialize (typeof(CDataContainer), "<CDataContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><cdata><![CDATA[data section contents]]></cdata></CDataContainer>");
			Assertion.AssertNotNull ("#1", c.cdata);
			Assertion.AssertEquals ("#2", "data section contents", c.cdata.Value);
		}
		
		[Test]
		public void TestDeserializeXmlNode ()
		{
			NodeContainer c = (NodeContainer) Deserialize (typeof(NodeContainer), "<NodeContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><node>text</node></NodeContainer>");
			Assertion.Assert ("#1", c.node is XmlText);
			Assertion.AssertEquals ("#2", "text", c.node.Value);
		}
		
		[Test]
		public void TestDeserializeChoices ()
		{
			Choices ch = (Choices) Deserialize (typeof(Choices), "<Choices><ChoiceZero>choice text</ChoiceZero></Choices>");
			Assertion.AssertEquals ("#1", "choice text", ch.MyChoice);
			Assertion.AssertEquals ("#2", ItemChoiceType.ChoiceZero, ch.ItemType);
			
			ch = (Choices) Deserialize (typeof(Choices), "<Choices><ChoiceOne>choice text</ChoiceOne></Choices>");
			Assertion.AssertEquals ("#1", "choice text", ch.MyChoice);
			Assertion.AssertEquals ("#2", ItemChoiceType.StrangeOne, ch.ItemType);
			
			ch = (Choices) Deserialize (typeof(Choices), "<Choices><ChoiceTwo>choice text</ChoiceTwo></Choices>");
			Assertion.AssertEquals ("#1", "choice text", ch.MyChoice);
			Assertion.AssertEquals ("#2", ItemChoiceType.ChoiceTwo, ch.ItemType);
		}
		
		[Test]
		public void TestDeserializeNamesWithSpaces ()
		{
			TestSpace ts = (TestSpace) Deserialize (typeof(TestSpace), "<Type_x0020_with_x0020_space xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' Attribute_x0020_with_x0020_space='5'><Element_x0020_with_x0020_space>4</Element_x0020_with_x0020_space></Type_x0020_with_x0020_space>");
			Assertion.AssertEquals ("#1", 4, ts.elem);
			Assertion.AssertEquals ("#2", 5, ts.attr);
		}
		
		[Test]
		public void TestDeserializeDefaults ()
		{
			ListDefaults d2 = (ListDefaults) Deserialize (typeof(ListDefaults), "<root/>");
	        
	        Assertion.AssertNotNull ("list2", d2.list2);
	        Assertion.AssertNull ("list3", d2.list3);
	        Assertion.AssertNull ("list4", d2.list4);
	        Assertion.AssertNotNull ("list5", d2.list5);
	        Assertion.AssertNotNull ("ed", d2.ed);
	        Assertion.AssertNotNull ("str", d2.str);
	        
			d2 = (ListDefaults) Deserialize (typeof(ListDefaults), "<root></root>");
	        
	        Assertion.AssertNotNull ("2 list2", d2.list2);
	        Assertion.AssertNull ("2 list3", d2.list3);
	        Assertion.AssertNull ("2 list4", d2.list4);
	        Assertion.AssertNotNull ("2 list5", d2.list5);
	        Assertion.AssertNotNull ("2 ed", d2.ed);
	        Assertion.AssertNotNull ("2 str", d2.str);
		}
		
		[Test]
		public void TestDeserializeChoiceArray ()
		{
			CompositeValueType v = (CompositeValueType) Deserialize (typeof(CompositeValueType), "<?xml version=\"1.0\" encoding=\"utf-16\"?><CompositeValueType xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><In>1</In><Es>2</Es></CompositeValueType>");
	        Assertion.AssertNotNull ("v.Items", v.Items);
	        Assertion.AssertNotNull ("v.ItemsElementName", v.ItemsElementName);
			Assertion.AssertEquals ("v.Items.Length", 2, v.Items.Length);
			Assertion.AssertEquals ("v.ItemsElementName.Length", 2, v.ItemsElementName.Length);
			Assertion.AssertEquals ("v.Items[0]", 1, v.Items[0]);
			Assertion.AssertEquals ("v.Items[1]", 2, v.Items[1]);
			Assertion.AssertEquals ("v.ItemsElementName[0]", ItemsChoiceType.In, v.ItemsElementName[0]);
			Assertion.AssertEquals ("v.ItemsElementName[1]", ItemsChoiceType.Es, v.ItemsElementName[1]);
		}
		
		[Test]
		public void TestDeserializeCollection ()
		{
			string s0 = "";
			s0+="	<ArrayOfEntity xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s0+="		<Entity Name='node1'/>";
			s0+="		<Entity Name='node2'/>";
			s0+="	</ArrayOfEntity>";
			
			EntityCollection col = (EntityCollection) Deserialize (typeof(EntityCollection), s0);
	        Assertion.AssertNotNull ("col", col);
			Assertion.AssertEquals ("col.Count", 2, col.Count);
	        Assertion.AssertNull ("col[0]", col[0].Parent);
	        Assertion.AssertNull ("col[1]", col[1].Parent);
		}
		
		[Test]
		public void TestDeserializeEmptyCollection ()
		{
			string s1 = "";
			s1+="	<ArrayOfEntity xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			
			EntityCollection col = (EntityCollection) Deserialize (typeof(EntityCollection), s1);
	        Assertion.AssertNotNull ("col", col);
			Assertion.AssertEquals ("col.Count", 0, col.Count);
			
			string s1_1 = "";
			s1_1+="	<ArrayOfEntity xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s1_1+="	</ArrayOfEntity>";
			
			col = (EntityCollection) Deserialize (typeof(EntityCollection), s1_1);
	        Assertion.AssertNotNull ("col", col);
			Assertion.AssertEquals ("col.Count", 0, col.Count);
		}
		
		[Test]
		public void TestDeserializeNilCollectionIsNotNull ()
		{
			string s2 = "";
			s2+="	<ArrayOfEntity xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/>";
			
			EntityCollection col = (EntityCollection) Deserialize (typeof(EntityCollection), s2);
	        Assertion.AssertNotNull ("col", col);
			Assertion.AssertEquals ("col.Count", 0, col.Count);
		}
		
		[Test]
		public void TestDeserializeObjectCollections ()
		{
			string s3 = "";
			s3+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="	<Collection1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="		<Entity Name='node1'/>";
			s3+="		<Entity Name='node2'/>";
			s3+="	</Collection1>";
			s3+="	<Collection2 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="		<Entity Name='node1'/>";
			s3+="		<Entity Name='node2'/>";
			s3+="	</Collection2>";
			s3+="	<Collection3 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="		<Entity Name='node1'/>";
			s3+="		<Entity Name='node2'/>";
			s3+="	</Collection3>";
			s3+="	<Collection4 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="		<Entity Name='node1'/>";
			s3+="		<Entity Name='node2'/>";
			s3+="	</Collection4>";
			s3+="</Container>";
			
			EntityContainer cont = (EntityContainer) Deserialize (typeof(EntityContainer), s3);
	        Assertion.AssertNotNull ("cont", cont);
	        
	        Assertion.AssertNotNull ("cont.Collection1", cont.Collection1);
			Assertion.AssertEquals ("cont.Collection1", 2, cont.Collection1.Count);
			Assertion.AssertEquals ("cont.Collection1.Container", "assigned", cont.Collection1.Container);
			Assertion.AssertEquals ("cont.Collection1[0].Parent", "assigned", cont.Collection1[0].Parent);
			Assertion.AssertEquals ("cont.Collection1[1].Parent", "assigned", cont.Collection1[1].Parent);
			
	        Assertion.AssertNotNull ("cont.Collection2", cont.Collection2);
			Assertion.AssertEquals ("cont.Collection2", 2, cont.Collection2.Count);
			Assertion.AssertEquals ("cont.Collection2.Container", "assigned", cont.Collection2.Container);
			Assertion.AssertEquals ("cont.Collection2[0].Parent", "assigned", cont.Collection2[0].Parent);
			Assertion.AssertEquals ("cont.Collection2[1].Parent", "assigned", cont.Collection2[1].Parent);
			
	        Assertion.AssertNotNull ("cont.Collection3", cont.Collection3);
			Assertion.AssertEquals ("cont.Collection3", 2, cont.Collection3.Count);
			Assertion.AssertEquals ("cont.Collection3.Container", "root", cont.Collection3.Container);
			Assertion.AssertEquals ("cont.Collection3[0].Parent", "root", cont.Collection3[0].Parent);
			Assertion.AssertEquals ("cont.Collection3[1].Parent", "root", cont.Collection3[1].Parent);
			
	        Assertion.AssertNotNull ("cont.Collection4", cont.Collection4);
			Assertion.AssertEquals ("cont.Collection4", 2, cont.Collection4.Count);
			Assertion.AssertEquals ("cont.Collection4.Container", "root", cont.Collection4.Container);
			Assertion.AssertEquals ("cont.Collection4[0].Parent", "root", cont.Collection4[0].Parent);
			Assertion.AssertEquals ("cont.Collection4[1].Parent", "root", cont.Collection4[1].Parent);
		}
		
		[Test]
		public void TestDeserializeEmptyObjectCollections ()
		{
			string s4 = "";
			s4+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s4+="</Container>";
			
			EntityContainer cont = (EntityContainer) Deserialize (typeof(EntityContainer), s4);
	        Assertion.AssertNotNull ("cont", cont);
	        
	        Assertion.AssertNotNull ("cont.Collection1", cont.Collection1);
			Assertion.AssertEquals ("cont.Collection1", 0, cont.Collection1.Count);
			Assertion.AssertEquals ("cont.Collection1.Container", "assigned", cont.Collection1.Container);
			
	        Assertion.AssertNotNull ("cont.Collection2", cont.Collection2);
			Assertion.AssertEquals ("cont.Collection2", 0, cont.Collection2.Count);
			Assertion.AssertEquals ("cont.Collection2.Container", "assigned", cont.Collection2.Container);
			
	        Assertion.AssertNotNull ("cont.Collection3", cont.Collection3);
			Assertion.AssertEquals ("cont.Collection3", 0, cont.Collection3.Count);
			Assertion.AssertEquals ("cont.Collection3.Container", "root", cont.Collection3.Container);
			
	        Assertion.AssertNotNull ("cont.Collection4", cont.Collection4);
			Assertion.AssertEquals ("cont.Collection4", 0, cont.Collection4.Count);
			Assertion.AssertEquals ("cont.Collection4.Container", "root", cont.Collection4.Container);
		}
		
		[Test]
		public void TestDeserializeObjectNilCollectionsAreNotNull ()
		{
			string s5 = "";
			s5+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s5+="	<Collection1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="	<Collection2 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="	<Collection3 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="	<Collection4 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="</Container>";
			
			EntityContainer cont = (EntityContainer) Deserialize (typeof(EntityContainer), s5);
	        Assertion.AssertNotNull ("cont", cont);
	        
	        Assertion.AssertNotNull ("cont.Collection1", cont.Collection1);
			Assertion.AssertEquals ("cont.Collection1", 0, cont.Collection1.Count);
			Assertion.AssertEquals ("cont.Collection1.Container", "assigned", cont.Collection1.Container);
			
	        Assertion.AssertNotNull ("cont.Collection2", cont.Collection2);
			Assertion.AssertEquals ("cont.Collection2", 0, cont.Collection2.Count);
			Assertion.AssertEquals ("cont.Collection2.Container", "assigned", cont.Collection2.Container);
			
	        Assertion.AssertNotNull ("cont.Collection3", cont.Collection3);
			Assertion.AssertEquals ("cont.Collection3", 0, cont.Collection3.Count);
			Assertion.AssertEquals ("cont.Collection3.Container", "root", cont.Collection3.Container);
			
	        Assertion.AssertNotNull ("cont.Collection4", cont.Collection4);
			Assertion.AssertEquals ("cont.Collection4", 0, cont.Collection4.Count);
			Assertion.AssertEquals ("cont.Collection4.Container", "root", cont.Collection4.Container);
		}
		
		[Test]
		public void TestDeserializeObjectEmptyCollections ()
		{
			string s6 = "";
			s6+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s6+="	<Collection1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="	<Collection2 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="	<Collection3 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="	<Collection4 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="</Container>";
			
			EntityContainer cont = (EntityContainer) Deserialize (typeof(EntityContainer), s6);
	        Assertion.AssertNotNull ("cont", cont);
	        
	        Assertion.AssertNotNull ("cont.Collection1", cont.Collection1);
			Assertion.AssertEquals ("cont.Collection1", 0, cont.Collection1.Count);
			Assertion.AssertEquals ("cont.Collection1.Container", "assigned", cont.Collection1.Container);
			
	        Assertion.AssertNotNull ("cont.Collection2", cont.Collection2);
			Assertion.AssertEquals ("cont.Collection2", 0, cont.Collection2.Count);
			Assertion.AssertEquals ("cont.Collection2.Container", "assigned", cont.Collection2.Container);
			
	        Assertion.AssertNotNull ("cont.Collection3", cont.Collection3);
			Assertion.AssertEquals ("cont.Collection3", 0, cont.Collection3.Count);
			Assertion.AssertEquals ("cont.Collection3.Container", "root", cont.Collection3.Container);
			
	        Assertion.AssertNotNull ("cont.Collection4", cont.Collection4);
			Assertion.AssertEquals ("cont.Collection4", 0, cont.Collection4.Count);
			Assertion.AssertEquals ("cont.Collection4.Container", "root", cont.Collection4.Container);
		}
		
		[Test]
		public void TestDeserializeObjectEmptyArrays ()
		{
			string s6 = "";
			s6+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s6+="	<Collection1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="	<Collection2 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="	<Collection3 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="	<Collection4 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			s6+="</Container>";
			
			ArrayEntityContainer cont = (ArrayEntityContainer) Deserialize (typeof(ArrayEntityContainer), s6);
	        Assertion.AssertNotNull ("cont", cont);
	        
	        Assertion.AssertNotNull ("cont.Collection1", cont.Collection1);
			Assertion.AssertEquals ("cont.Collection1.Length", 0, cont.Collection1.Length);
			
	        Assertion.AssertNotNull ("cont.Collection2", cont.Collection2);
			Assertion.AssertEquals ("cont.Collection2.Length", 0, cont.Collection2.Length);
			
	        Assertion.AssertNotNull ("cont.Collection3", cont.Collection3);
			Assertion.AssertEquals ("cont.Collection3.Length", 0, cont.Collection3.Length);
			
	        Assertion.AssertNotNull ("cont.Collection4", cont.Collection4);
			Assertion.AssertEquals ("cont.Collection4.Length", 0, cont.Collection4.Length);
		}
		
		[Test]
		public void TestDeserializeEmptyObjectArrays ()
		{
			string s4 = "";
			s4+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s4+="</Container>";
			
			ArrayEntityContainer cont = (ArrayEntityContainer) Deserialize (typeof(ArrayEntityContainer), s4);
	        Assertion.AssertNotNull ("cont", cont);
	        
	        Assertion.AssertNull ("cont.Collection1", cont.Collection1);
	        Assertion.AssertNull ("cont.Collection2", cont.Collection2);
			
	        Assertion.AssertNotNull ("cont.Collection3", cont.Collection3);
			Assertion.AssertEquals ("cont.Collection3.Length", 0, cont.Collection3.Length);
			
	        Assertion.AssertNotNull ("cont.Collection4", cont.Collection4);
			Assertion.AssertEquals ("cont.Collection4.Length", 0, cont.Collection4.Length);
		}
		
		[Test]
		public void TestDeserializeObjectNilArrays ()
		{
			string s5 = "";
			s5+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s5+="	<Collection1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="	<Collection2 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="	<Collection3 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="	<Collection4 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />";
			s5+="</Container>";
			
			ArrayEntityContainer cont = (ArrayEntityContainer) Deserialize (typeof(ArrayEntityContainer), s5);
	        Assertion.AssertNotNull ("cont", cont);
	        
	        Assertion.AssertNull ("cont.Collection1", cont.Collection1);
	        Assertion.AssertNull ("cont.Collection2", cont.Collection2);
	        Assertion.AssertNull ("cont.Collection3", cont.Collection3);
			
	        Assertion.AssertNotNull ("cont.Collection4", cont.Collection4);
			Assertion.AssertEquals ("cont.Collection4.Length", 0, cont.Collection4.Length);
		}
		
		[Test]
		public void TestDeserializeEmptyArray ()
		{
			string s1 = "";
			s1+="<ArrayOfEntity xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />";
			
			Entity[] col = (Entity[]) Deserialize (typeof(Entity[]), s1);
	        Assertion.AssertNotNull ("col", col);
			Assertion.AssertEquals ("col.Length", 0, col.Length);
			
			string s1_1 = "";
			s1_1+="	<ArrayOfEntity xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s1_1+="	</ArrayOfEntity>";
			
			col = (Entity[]) Deserialize (typeof(Entity[]), s1_1);
	        Assertion.AssertNotNull ("col", col);
			Assertion.AssertEquals ("col.Length", 0, col.Length);
		}
		
		[Test]
		public void TestDeserializeNilArray ()
		{
			string s2 = "";
			s2 += "<ArrayOfEntity xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true'/>";
			
			Entity[] col = (Entity[]) Deserialize (typeof(Entity[]), s2);
	        Assertion.AssertNull ("col", col);
		}
		
		[Test]
		public void TestDeserializeObjectWithReadonlyCollection ()
		{
			string s3 = "";
			s3+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="	<Collection1>";
			s3+="		<Entity Name='node1'/>";
			s3+="		<Entity Name='node2'/>";
			s3+="	</Collection1>";
			s3+="</Container>";
			
			ObjectWithReadonlyCollection cont = (ObjectWithReadonlyCollection) Deserialize (typeof(ObjectWithReadonlyCollection), s3);
	        Assertion.AssertNotNull ("cont", cont);
	        Assertion.AssertNotNull ("cont.Collection1", cont.Collection1);
			Assertion.AssertEquals ("cont.Collection1.Count", 2, cont.Collection1.Count);
			Assertion.AssertEquals ("cont.Collection1.Container", "root", cont.Collection1.Container);
			Assertion.AssertEquals ("cont.Collection1[0].Parent", "root", cont.Collection1[0].Parent);
			Assertion.AssertEquals ("cont.Collection1[1].Parent", "root", cont.Collection1[1].Parent);
		}
		
		[Test]
		[ExpectedException (typeof(InvalidOperationException))]
		public void TestDeserializeObjectWithReadonlyNulCollection ()
		{
			string s3 = "";
			s3+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="	<Collection1>";
			s3+="		<Entity Name='node1'/>";
			s3+="		<Entity Name='node2'/>";
			s3+="	</Collection1>";
			s3+="</Container>";
			
			Deserialize (typeof(ObjectWithReadonlyNulCollection), s3);
		}
		
		[Test]
		public void TestDeserializeObjectWithReadonlyArray ()
		{
			string s3 = "";
			s3+="<Container xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>";
			s3+="	<Collection1>";
			s3+="		<Entity Name='node1'/>";
			s3+="		<Entity Name='node2'/>";
			s3+="	</Collection1>";
			s3+="</Container>";
			
			ObjectWithReadonlyArray cont = (ObjectWithReadonlyArray) Deserialize (typeof(ObjectWithReadonlyArray), s3);
	        Assertion.AssertNotNull ("cont", cont);
	        Assertion.AssertNotNull ("cont.Collection1", cont.Collection1);
			Assertion.AssertEquals ("cont.Collection1.Length", 0, cont.Collection1.Length);
		}
	}
}