Turn eval test into normal test case
[mono.git] / mcs / class / System.Runtime.Serialization / Test / System.Runtime.Serialization / XsdDataContractImporterTest.cs
1 //
2 // XsdDataContractImporterTest.cs
3 //
4 // Author:
5 //      Ankit Jain <jankit@novell.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.com
8
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 //
31 // This test code contains tests for both DataContractSerializer and
32 // NetDataContractSerializer. The code could be mostly common.
33 //
34
35 using System;
36 using System.CodeDom;
37 using System.CodeDom.Compiler;
38 using System.Collections.Generic;
39 using System.IO;
40 using System.Runtime.Serialization;
41 using System.ServiceModel.Description;
42 using System.Xml;
43 using System.Xml.Schema;
44 using System.Xml.Serialization;
45 using Microsoft.CSharp;
46 using NUnit.Framework;
47
48 namespace MonoTests.System.Runtime.Serialization
49 {
50         [TestFixture]
51         public class XsdContractImporterTest
52         {
53                 MetadataSet metadata;
54                 XmlSchemaSet xss;
55
56                 [SetUp]
57                 public void Setup ()
58                 {
59                         XmlReader xr = XmlTextReader.Create ("Test/System.Runtime.Serialization/one.xml");
60                         metadata = MetadataSet.ReadFrom (xr);
61                         NewXmlSchemaSet ();
62                 }
63
64                 private XmlSchemaSet NewXmlSchemaSet ()
65                 {
66                         xss = new XmlSchemaSet ();
67                         foreach (MetadataSection section in metadata.MetadataSections)
68                                 if (section.Metadata is XmlSchema)
69                                         xss.Add (section.Metadata as XmlSchema);
70
71                         return xss;
72                 }
73
74                 private XsdDataContractImporter GetImporter ()
75                 {
76                         CodeCompileUnit ccu = new CodeCompileUnit ();
77                         return new XsdDataContractImporter (ccu);
78                 }
79
80                 [Test]
81                 public void CtorTest ()
82                 {
83                         XsdDataContractImporter xi = new XsdDataContractImporter ();
84                         Assert.IsNotNull (xi.CodeCompileUnit, "#c01");
85
86                         xi = new XsdDataContractImporter (null);
87                         Assert.IsNotNull (xi.CodeCompileUnit, "#c02");
88
89                         xi = new XsdDataContractImporter (new CodeCompileUnit ());
90                 }
91
92
93                 [Test]
94                 [ExpectedException (typeof (InvalidOperationException))]
95                 [Category ("NotWorking")]
96                 public void GetCodeTypeReferenceTest ()
97                 {
98                         XsdDataContractImporter xsdi = GetImporter ();
99                         xsdi.GetCodeTypeReference (new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
100                 }
101
102                 [Test]
103                 [Category ("NotWorking")]
104                 public void GetCodeTypeReferenceTest2 ()
105                 {
106                         NewXmlSchemaSet ();
107
108                         Assert.IsFalse (xss.IsCompiled, "#g01");
109
110                         XsdDataContractImporter xsdi = GetImporter ();
111                         xsdi.Import (xss, new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
112                         Assert.IsTrue (xss.IsCompiled, "#g02");
113
114                         CodeTypeReference type = xsdi.GetCodeTypeReference (new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
115
116                         //FIXME: How should this type ref be checked?
117                         Assert.IsNotNull (type, "#g03");
118                         Assert.AreEqual (type.BaseType, "dc", "#g04");
119                 }
120
121                 [Test]
122                 [Category ("NotWorking")]
123                 public void CanImportTest ()
124                 {
125                         NewXmlSchemaSet ();
126                         XsdDataContractImporter xsdi = GetImporter ();
127
128                         Assert.IsFalse (xss.IsCompiled, "#ci01");
129
130                         Assert.IsTrue (xsdi.CanImport (xss, new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/")), "#ci02");
131                         Assert.IsTrue (xss.IsCompiled, "#ci03");
132
133                         Assert.IsFalse (xsdi.CanImport (xss, new XmlQualifiedName ("Echo", "http://myns/echo")), "#ci04");
134                         Assert.IsTrue (xsdi.CanImport (xss, new XmlQualifiedName ("int", "http://www.w3.org/2001/XMLSchema")), "#ci05");
135
136                         Assert.IsTrue (xsdi.CanImport (xss), "#ci06");
137
138                         Assert.IsTrue (xsdi.CanImport (xss, 
139                                 xss.GlobalElements [new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/")] as XmlSchemaElement), 
140                                 "#ci07");
141
142                         Assert.IsTrue (xsdi.CanImport (xss,
143                                 xss.GlobalElements [new XmlQualifiedName ("Echo", "http://myns/echo")] as XmlSchemaElement),
144                                 "#ci08");
145                 }
146
147                 [Test]
148                 [Category ("NotWorking")]
149                 public void CanImportTest2 ()
150                 {
151                         NewXmlSchemaSet ();
152                         XsdDataContractImporter xsdi = GetImporter ();
153
154                         List<XmlQualifiedName> names = new List<XmlQualifiedName> ();
155                         names.Add (new XmlQualifiedName ("Echo", "http://myns/echo"));
156                         Assert.IsFalse (xsdi.CanImport (xss, names), "#ci20");
157
158                         names.Add (new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
159                         Assert.IsFalse (xsdi.CanImport (xss, names), "#ci21");
160
161                         names.Clear ();
162                         names.Add (new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
163                         Assert.IsTrue (xsdi.CanImport (xss, names), "#ci22");
164                 }
165
166                 [Test]
167                 [ExpectedException (typeof (ArgumentNullException))]
168                 [Category ("NotWorking")]
169                 public void CanImportNullTest1 ()
170                 {
171                         XsdDataContractImporter xsdi = GetImporter ();
172                         xsdi.CanImport (null);
173                 }
174
175                 [Test]
176                 [Category ("NotWorking")]
177                 [ExpectedException (typeof (ArgumentNullException))]
178                 public void CanImportNullTest2 ()
179                 {
180                         XsdDataContractImporter xsdi = GetImporter ();
181                         xsdi.CanImport (xss, (XmlQualifiedName) null);
182                 }
183
184                 [Test]
185                 [Category ("NotWorking")]
186                 [ExpectedException (typeof (ArgumentNullException))]
187                 public void CanImportNullTest3 ()
188                 {
189                         XsdDataContractImporter xsdi = GetImporter ();
190                         xsdi.CanImport (xss, (XmlSchemaElement) null);
191                 }
192
193                 [Test]
194                 [ExpectedException (typeof (ArgumentNullException))]
195                 public void ImportTestNullSchemas ()
196                 {
197                         XsdDataContractImporter xsdi = GetImporter ();
198                         xsdi.Import (null);
199                 }
200
201                 [Test]
202                 [ExpectedException (typeof (ArgumentNullException))]
203                 public void ImportTestNullSchemas2 ()
204                 {
205                         XsdDataContractImporter xsdi = GetImporter ();
206                         xsdi.Import (null, new XmlQualifiedName ("foo"));
207                 }
208
209                 [Test]
210                 [ExpectedException (typeof (ArgumentNullException))]
211                 public void ImportTestNullSchemas3 ()
212                 {
213                         XsdDataContractImporter xsdi = GetImporter ();
214                         xsdi.Import (null, new List<XmlQualifiedName> ());
215                 }
216
217                 [Test]
218                 [ExpectedException (typeof (ArgumentNullException))]
219                 public void ImportTestNullTypeName ()
220                 {
221                         XsdDataContractImporter xsdi = GetImporter ();
222                         xsdi.Import (new XmlSchemaSet (), (XmlQualifiedName) null);
223                 }
224
225                 [Test]
226                 [ExpectedException (typeof (ArgumentNullException))]
227                 public void ImportTestNullElement ()
228                 {
229                         XsdDataContractImporter xsdi = GetImporter ();
230                         xsdi.Import (new XmlSchemaSet (), (XmlSchemaElement) null);
231                 }
232
233                 [Test]
234                 [ExpectedException (typeof (ArgumentNullException))]
235                 public void ImportTestNullCollection ()
236                 {
237                         XsdDataContractImporter xsdi = GetImporter ();
238                         xsdi.Import (new XmlSchemaSet (), (ICollection<XmlQualifiedName>) null);
239                 }
240
241                 [Test]
242                 [Category ("NotWorking")]
243                 public void ImportTest ()
244                 {
245                         XsdDataContractImporter xsdi = GetImporter ();
246                         XmlSchemaElement element = new XmlSchemaElement();
247                         //Assert.IsTrue (xsdi.CanImport (xss, element));
248                         Assert.AreEqual (new XmlQualifiedName ("anyType", XmlSchema.Namespace), xsdi.Import (xss, element), "#i02");
249
250                         CodeCompileUnit ccu = xsdi.CodeCompileUnit;
251                         Assert.AreEqual (1, ccu.Namespaces.Count, "#i03");
252                         Assert.AreEqual ("", ccu.Namespaces [0].Name, "#i04");
253
254                         Assert.AreEqual (1, ccu.Namespaces [0].Types.Count, "#i05");
255
256                         Dictionary<string, string> mbrs = new Dictionary<string, string> ();
257                         mbrs.Add ("foo", "System.String");
258                         CheckDC (ccu.Namespaces [0].Types [0], "dc", mbrs, "#i06");
259                 }
260
261                 [Test]
262                 [Category ("NotWorking")]
263                 public void ImportDataContract1 ()
264                 {
265                         NewXmlSchemaSet ();
266                         Assert.IsFalse (xss.IsCompiled, "#i20");
267
268                         XsdDataContractImporter xsdi = GetImporter ();
269
270                         xsdi.Import (xss, new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
271                         Assert.IsTrue (xss.IsCompiled, "#i21");
272                         CodeCompileUnit ccu = xsdi.CodeCompileUnit;
273
274                         Assert.AreEqual (1, ccu.Namespaces.Count, "#i22");
275                         Assert.AreEqual ("", ccu.Namespaces [0].Name, "#i23");
276
277                         Assert.AreEqual (1, ccu.Namespaces [0].Types.Count, "#i24");
278
279                         Dictionary<string, string> mbrs = new Dictionary<string, string> ();
280                         mbrs.Add ("foo", "System.String");
281                         CheckDC (ccu.Namespaces [0].Types [0], "dc", mbrs, "#i25");
282
283                         ccu.Namespaces.Clear ();
284                         xsdi.Import (xss, new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
285                         //Importing same data contract again with same importer
286                         Assert.AreEqual (0, ccu.Namespaces.Count, "#i26");
287                 }
288
289                 [Test]
290                 [Category ("NotWorking")]
291                 public void ImportDataContract2 ()
292                 {
293                         NewXmlSchemaSet ();
294                         XsdDataContractImporter xsdi = GetImporter ();
295
296                         xss.Compile ();
297                         xsdi.Import (xss, xss.GlobalElements [new XmlQualifiedName ("Echo", "http://myns/echo")] as XmlSchemaElement);
298                         CodeCompileUnit ccu = xsdi.CodeCompileUnit;
299
300                         Assert.AreEqual (2, ccu.Namespaces.Count, "#i29");
301                         Dictionary<string, string> args = new Dictionary<string, string> ();
302                         args.Add ("msg", "System.String");
303                         args.Add ("num", "System.Int32");
304                         args.Add ("d", "dc");
305
306                         CheckDC (ccu.Namespaces [0].Types [0], "Echo", args, "#i30");
307
308                         args.Clear ();
309                         args.Add ("foo", "System.String");
310                         CheckDC (ccu.Namespaces [1].Types [0], "dc", args, "#i31");
311
312                         ccu.Namespaces.Clear ();
313                         xsdi.Import (xss, new XmlQualifiedName ("dc", "http://schemas.datacontract.org/2004/07/"));
314                         Assert.AreEqual (0, ccu.Namespaces.Count);
315                 }
316
317                 [Test]
318                 [ExpectedException (typeof (InvalidDataContractException))]
319                 [Category ("NotWorking")]
320                 public void ImportMessageEcho ()
321                 {
322                         XsdDataContractImporter xsdi = GetImporter ();
323                         xsdi.Import (xss, new XmlQualifiedName ("Echo", "http://myns/echo"));
324                 }
325
326                 [Test]
327                 [Category ("NotWorking")]
328                 public void ImportAll ()
329                 {
330                         NewXmlSchemaSet ();
331                         XsdDataContractImporter xsdi = GetImporter ();
332
333                         CodeCompileUnit ccu = xsdi.CodeCompileUnit;
334                         xsdi.Import (xss);
335
336                         Assert.AreEqual (2, ccu.Namespaces.Count, "#i40");
337                         Assert.AreEqual ("myns.echo", ccu.Namespaces [0].Name, "#i41");
338                         Assert.AreEqual ("", ccu.Namespaces [1].Name, "#i42");
339
340                         Assert.AreEqual (4, ccu.Namespaces [0].Types.Count, "#i43");
341
342                         /* ns : myns.echo
343                          * Messages */
344                         Dictionary <string, string> args = new Dictionary <string, string> ();
345                         args.Add ("msg", "System.String");
346                         args.Add ("num", "System.Int32");
347                         args.Add ("d", "dc");
348                         
349                         CheckDC (ccu.Namespaces [0].Types [0], "Echo", args, "#i44");
350
351                         args.Clear ();
352                         args.Add ("EchoResult", "System.String");
353                         CheckDC (ccu.Namespaces [0].Types [1], "EchoResponse", args, "#i45");
354
355                         args.Clear ();
356                         args.Add ("it", "System.Int32");
357                         args.Add ("prefix", "System.String");
358                         CheckDC (ccu.Namespaces [0].Types [2], "DoubleIt", args, "#i46");
359
360                         args.Clear ();
361                         args.Add ("DoubleItResult", "System.String");
362                         CheckDC (ccu.Namespaces [0].Types [3], "DoubleItResponse", args, "#i47");
363
364                         /* ns: "" */
365                         args.Clear ();
366                         args.Add ("foo", "System.String");
367                         CheckDC (ccu.Namespaces [1].Types [0], "dc", args, "#i48");
368
369                         ccu.Namespaces.Clear ();
370                         xsdi.Import (xss);
371                         //Importing same data contract again with same importer
372                         Assert.AreEqual (0, ccu.Namespaces.Count, "#i49");
373                 }
374
375                 [Test]
376                 public void ImportSkipArrayOfPrimitives ()
377                 {
378                         var ccu = new CodeCompileUnit ();
379                         var xdi = new XsdDataContractImporter (ccu);
380                         var xss = new XmlSchemaSet ();
381                         xss.Add (null, "Test/Resources/Schemas/schema1.xsd");
382                         xss.Add (null, "Test/Resources/Schemas/schema2.xsd");
383                         xdi.Import (xss);
384                         var sw = new StringWriter ();
385                         new CSharpCodeProvider ().GenerateCodeFromCompileUnit (ccu, sw, null);
386                         Assert.IsTrue (sw.ToString ().IndexOf ("ArrayOfint") < 0, "#1");
387                 }
388
389                 [Test]
390                 public void ImportGivesAppropriateNamespaces ()
391                 {
392                         var ccu = new CodeCompileUnit ();
393                         var xdi = new XsdDataContractImporter (ccu);
394                         var xss = new XmlSchemaSet ();
395                         xss.Add (null, "Test/Resources/Schemas/schema1.xsd");
396                         xss.Add (null, "Test/Resources/Schemas/schema2.xsd");
397                         xss.Add (null, "Test/Resources/Schemas/schema3.xsd");
398                         xdi.Import (xss);
399                         var sw = new StringWriter ();
400                         bool t = false, te = false;
401                         foreach (CodeNamespace cns in ccu.Namespaces) {
402                                 if (cns.Name == "tempuri.org")
403                                         t = true;
404                                 else if (cns.Name == "tempuri.org.ext")
405                                         te = true;
406                                 Assert.AreEqual ("GetSearchDataResponse", cns.Types [0].Name, "#1." + cns.Name);
407                         }
408                         Assert.IsTrue (t, "t");
409                         Assert.IsTrue (t, "te");
410                 }
411
412                 CodeCompileUnit DoImport (params string [] schemaFiles)
413                 {
414                         var ccu = new CodeCompileUnit ();
415                         var xdi = new XsdDataContractImporter (ccu);
416                         var xss = new XmlSchemaSet ();
417                         foreach (var schemaFile in schemaFiles)
418                                 xss.Add (null, schemaFile);
419                         xdi.Import (xss);
420
421                         return ccu;
422                 }
423
424                 // FIXME: this set of tests need further assertion in each test case. Right now it just checks if things import or fail just fine.
425
426                 [Test]
427                 public void ImportTestX0 ()
428                 {
429                         DoImport ("Test/Resources/Schemas/ns0.xsd");
430                 }
431
432                 [Test]
433                 public void ImportTestX1 ()
434                 {
435                         DoImport ("Test/Resources/Schemas/ns1.xsd");
436                 }
437
438                 [Test]
439                 public void ImportTestX2 ()
440                 {
441                         DoImport ("Test/Resources/Schemas/ns2.xsd");
442                 }
443
444                 [Test]
445                 [ExpectedException (typeof (InvalidDataContractException))]
446                 public void ImportTestX3 ()
447                 {
448                         DoImport ("Test/Resources/Schemas/ns3.xsd");
449                 }
450
451                 [Test]
452                 [ExpectedException (typeof (InvalidDataContractException))]
453                 public void ImportTestX4 ()
454                 {
455                         DoImport ("Test/Resources/Schemas/ns4.xsd");
456                 }
457
458                 [Test]
459                 [ExpectedException (typeof (InvalidDataContractException))]
460                 public void ImportTestX5 ()
461                 {
462                         DoImport ("Test/Resources/Schemas/ns5.xsd");
463                 }
464
465                 [Test]
466                 public void ImportTestX6 ()
467                 {
468                         DoImport ("Test/Resources/Schemas/ns6.xsd",
469                                   "Test/Resources/Schemas/ns0.xsd");
470                 }
471
472                 [Test]
473                 [ExpectedException (typeof (InvalidDataContractException))]
474                 public void ImportTestX7 ()
475                 {
476                         DoImport ("Test/Resources/Schemas/ns7.xsd",
477                                   "Test/Resources/Schemas/ns0.xsd");
478                 }
479
480                 [Test]
481                 [ExpectedException (typeof (InvalidDataContractException))]
482                 public void ImportTestX8 ()
483                 {
484                         DoImport ("Test/Resources/Schemas/ns8.xsd");
485                 }
486
487                 [Test]
488                 [ExpectedException (typeof (InvalidDataContractException))]
489                 public void ImportTestX9 ()
490                 {
491                         DoImport ("Test/Resources/Schemas/ns9.xsd");
492                 }
493
494                 [Test]
495                 public void ImportTestX10 ()
496                 {
497                         DoImport ("Test/Resources/Schemas/ns10.xsd");
498                 }
499
500                 [Test]
501                 [ExpectedException (typeof (InvalidDataContractException))]
502                 public void ImportTestX11 ()
503                 {
504                         DoImport ("Test/Resources/Schemas/ns11.xsd");
505                 }
506
507                 [Test]
508                 [ExpectedException (typeof (InvalidDataContractException))]
509                 public void ImportTestX12 ()
510                 {
511                         DoImport ("Test/Resources/Schemas/ns12.xsd");
512                 }
513
514                 [Test]
515                 [ExpectedException (typeof (InvalidDataContractException))]
516                 public void ImportTestX13 ()
517                 {
518                         DoImport ("Test/Resources/Schemas/ns13.xsd");
519                 }
520
521                 [Test]
522                 public void ImportTestX14 ()
523                 {
524                         DoImport ("Test/Resources/Schemas/ns14.xsd");
525                 }
526
527                 [Test]
528                 [ExpectedException (typeof (InvalidDataContractException))]
529                 public void ImportTestX15 ()
530                 {
531                         DoImport ("Test/Resources/Schemas/ns15.xsd");
532                 }
533
534                 [Test]
535                 public void ImportTestX16 ()
536                 {
537                         DoImport ("Test/Resources/Schemas/ns16.xsd");
538                 }
539
540                 [Test]
541                 [ExpectedException (typeof (InvalidDataContractException))]
542                 public void ImportTestX17 ()
543                 {
544                         DoImport ("Test/Resources/Schemas/ns17.xsd");
545                 }
546
547                 [Test]
548                 public void ImportTestX18 ()
549                 {
550                         DoImport ("Test/Resources/Schemas/ns18.xsd");
551                 }
552
553                 [Test]
554                 [ExpectedException (typeof (InvalidDataContractException))]
555                 public void ImportTestX19 ()
556                 {
557                         DoImport ("Test/Resources/Schemas/ns19.xsd");
558                 }
559
560                 [Test]
561                 [ExpectedException (typeof (InvalidDataContractException))]
562                 public void ImportTestX20 ()
563                 {
564                         DoImport ("Test/Resources/Schemas/ns20.xsd");
565                 }
566
567                 [Test]
568                 public void ImportTestX21 ()
569                 {
570                         DoImport ("Test/Resources/Schemas/ns21.xsd");
571                 }
572
573                 [Test]
574                 public void ImportTestX22 ()
575                 {
576                         DoImport ("Test/Resources/Schemas/ns22.xsd");
577                 }
578
579                 [Test]
580                 public void ImportTestX23 ()
581                 {
582                         DoImport ("Test/Resources/Schemas/ns23.xsd");
583                 }
584
585                 [ExpectedException (typeof (InvalidDataContractException))]
586                 [Test]
587                 public void ImportTestX24 ()
588                 {
589                         DoImport ("Test/Resources/Schemas/ns24.xsd");
590                 }
591
592                 [Test]
593                 public void ImportTestX25 ()
594                 {
595                         DoImport ("Test/Resources/Schemas/ns25.xsd");
596                 }
597
598                 [Test]
599                 public void ImportTestX26 ()
600                 {
601                         DoImport ("Test/Resources/Schemas/ns26.xsd");
602                 }
603
604                 [Test]
605                 public void ImportTestX27 ()
606                 {
607                         DoImport ("Test/Resources/Schemas/ns27.xsd");
608                 }
609
610                 [Test]
611                 public void ImportTestX28 ()
612                 {
613                         DoImport ("Test/Resources/Schemas/ns28.xsd");
614                 }
615
616                 [Test]
617                 [ExpectedException (typeof (InvalidDataContractException))]
618                 public void ImportTestX29 ()
619                 {
620                         DoImport ("Test/Resources/Schemas/ns29.xsd");
621                 }
622
623                 [Test]
624                 public void ImportTestX30 ()
625                 {
626                         DoImport ("Test/Resources/Schemas/ns30.xsd");
627                 }
628
629                 [Test]
630                 public void ImportTestX31 ()
631                 {
632                         DoImport ("Test/Resources/Schemas/ns31.xsd");
633                 }
634
635                 /* Helper methods */
636                 private void CheckDC (CodeTypeDeclaration type, string name, Dictionary<string, string> members, string msg)
637                 {
638                         // "dc" DataContract
639                         Assert.AreEqual (name, type.Name, msg + "d");
640                         //FIXME: Assert.AreEqual (MemberAttributes.Public, type.Attributes);
641                         Assert.IsTrue (type.IsClass, msg + "e");
642                         Assert.IsTrue (type.IsPartial, msg + "f");
643
644                         CheckDataContractAttribute (type, msg);
645                         CheckExtensionData (type, msg);
646
647                         foreach (KeyValuePair<string, string> pair in members)
648                                 CheckDataMember (type, pair.Key, pair.Value, true, msg);
649                 }
650
651                 private void CheckExtensionData (CodeTypeDeclaration type, string msg)
652                 {
653                         CheckDataMember (type, "extensionDataField", "ExtensionData", "System.Runtime.Serialization.ExtensionDataObject", false, msg);
654                 }
655
656                 private void CheckDataMember (CodeTypeDeclaration type, string name, string type_name, bool check_attr, string msg)
657                 {
658                         CheckDataMember (type, name + "Field", name, type_name, check_attr, msg);
659                 }
660                  
661                 private void CheckDataMember (CodeTypeDeclaration type, string field_name, string prop_name, string type_name, bool check_attr, string msg)
662                 {
663                         // "field"
664                         CodeMemberProperty p = FindMember (type, prop_name) as CodeMemberProperty;
665                         Assert.IsNotNull (p, msg + "-dm0");
666                         Assert.IsTrue (p.HasGet, msg + "-dm1");
667                         Assert.IsTrue (p.HasSet, msg + "-dm2");
668                         Assert.AreEqual (type_name, p.Type.BaseType, msg + "-dm3");
669
670                         CodeMemberField f = FindMember (type, field_name) as CodeMemberField;
671                         Assert.IsNotNull (f, msg + "-dm4");
672                         Assert.AreEqual (type_name, f.Type.BaseType, "-dm5");
673
674                         if (check_attr)
675                                 CheckDataContractAttribute (type, msg);
676                 }
677
678                 private void CheckDataContractAttribute (CodeTypeDeclaration type, string msg)
679                 {
680                         Assert.AreEqual (3, type.CustomAttributes.Count, msg + "a");
681
682                         // DebuggerStepThroughAttribute - skip it
683
684                         //GeneratedCodeAttribute
685                         CodeAttributeDeclaration ca = type.CustomAttributes [1];
686                         Assert.AreEqual ("System.CodeDom.Compiler.GeneratedCodeAttribute", ca.Name, msg + "b");
687
688                         ca = type.CustomAttributes [2];
689                         Assert.AreEqual ("System.Runtime.Serialization.DataContractAttribute", ca.Name, msg + "c");
690                         Assert.AreEqual (2, ca.Arguments.Count, msg + "d");
691                 }
692
693                 CodeTypeMember FindMember (CodeTypeDeclaration type, string name)
694                 {
695                         foreach (CodeTypeMember m in type.Members)
696                                 if (m.Name == name)
697                                         return m;
698                         return null;
699                 }
700
701         }
702
703 }