[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.XML / Test / System.Xml.Schema / XmlSchemaTests.cs
1 //
2 // System.Xml.XmlSchemaTests.cs
3 //
4 // Author:
5 //   Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
6 //
7 // (C) 2002 Atsushi Enomoto
8 //
9
10 using System;
11 using System.IO;
12 using System.Net;
13 using System.Xml;
14 using System.Xml.Schema;
15 using System.Xml.Serialization;
16 using NUnit.Framework;
17
18 namespace MonoTests.System.Xml
19 {       
20         [TestFixture]
21         public class XmlSchemaTests : XmlSchemaAssertion
22         {
23                 static readonly bool StrictMsCompliant = Environment.GetEnvironmentVariable ("MONO_STRICT_MS_COMPLIANT") == "yes";
24
25                 [Test]
26                 public void TestRead ()
27                 {
28                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/1.xsd");
29                         Assert.AreEqual (6, schema.Items.Count);
30
31                         bool fooValidated = false;
32                         bool barValidated = false;
33                         string ns = "urn:bar";
34
35                         foreach (XmlSchemaObject obj in schema.Items) {
36                                 XmlSchemaElement element = obj as XmlSchemaElement;
37                                 if (element == null)
38                                         continue;
39                                 if (element.Name == "Foo") {
40                                         AssertElement (element, "Foo", 
41                                                 XmlQualifiedName.Empty, null,
42                                                 QName ("string", XmlSchema.Namespace), null);
43                                         fooValidated = true;
44                                 }
45                                 if (element.Name == "Bar") {
46                                         AssertElement (element, "Bar",
47                                                 XmlQualifiedName.Empty, null, QName ("FugaType", ns), null);
48                                         barValidated = true;
49                                 }
50                         }
51                         Assert.IsTrue (fooValidated);
52                         Assert.IsTrue (barValidated);
53                 }
54
55                 [Test]
56                 public void TestReadFlags ()
57                 {
58                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/2.xsd");
59                         schema.Compile (null);
60                         XmlSchemaElement el = schema.Items [0] as XmlSchemaElement;
61                         Assert.IsNotNull (el);
62                         Assert.AreEqual (XmlSchemaDerivationMethod.Extension, el.Block);
63
64                         el = schema.Items [1] as XmlSchemaElement;
65                         Assert.IsNotNull (el);
66                         Assert.AreEqual (XmlSchemaDerivationMethod.Extension |
67                                 XmlSchemaDerivationMethod.Restriction, el.Block);
68                 }
69
70                 [Test]
71                 public void TestWriteFlags ()
72                 {
73                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/2.xsd");
74                         StringWriter sw = new StringWriter ();
75                         XmlTextWriter xtw = new XmlTextWriter (sw);
76                         schema.Write (xtw);
77                 }
78
79                 [Test]
80                 public void TestCompile ()
81                 {
82                         XmlQualifiedName qname;
83                         XmlSchemaComplexContentExtension xccx;
84                         XmlSchemaComplexType cType;
85                         XmlSchemaSequence seq;
86
87                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/1.xsd");
88 //                      Assert.IsTrue (!schema.IsCompiled);
89                         schema.Compile (null);
90                         Assert.IsTrue (schema.IsCompiled);
91                         string ns = "urn:bar";
92
93                         XmlSchemaElement foo = (XmlSchemaElement) schema.Elements [QName ("Foo", ns)];
94                         Assert.IsNotNull (foo);
95                         XmlSchemaDatatype stringDatatype = foo.ElementType as XmlSchemaDatatype;
96                         Assert.IsNotNull (stringDatatype);
97
98                         // HogeType
99                         qname = QName ("HogeType", ns);
100                         cType = schema.SchemaTypes [qname] as XmlSchemaComplexType;
101                         Assert.IsNotNull (cType);
102                         Assert.IsNull (cType.ContentModel);
103                         AssertCompiledComplexType (cType, qname, 0, 0,
104                                 false, null, true, XmlSchemaContentType.ElementOnly);
105                         seq = cType.ContentTypeParticle as XmlSchemaSequence;
106                         Assert.IsNotNull (seq);
107                         Assert.AreEqual (2, seq.Items.Count);
108                         XmlSchemaElement refFoo = seq.Items [0] as XmlSchemaElement;
109                         AssertCompiledElement (refFoo, QName ("Foo", ns), stringDatatype);
110
111                         // FugaType
112                         qname = QName ("FugaType", ns);
113                         cType = schema.SchemaTypes [qname] as XmlSchemaComplexType;
114                         Assert.IsNotNull (cType);
115                         xccx = cType.ContentModel.Content as XmlSchemaComplexContentExtension;
116                         AssertCompiledComplexContentExtension (
117                                 xccx, 0, false, QName ("HogeType", ns));
118
119                         AssertCompiledComplexType (cType, qname, 0, 0,
120                                 false, typeof (XmlSchemaComplexContent),
121                                 true, XmlSchemaContentType.ElementOnly);
122                         Assert.IsNotNull (cType.BaseSchemaType);
123
124                         seq = xccx.Particle as XmlSchemaSequence;
125                         Assert.IsNotNull (seq);
126                         Assert.AreEqual (1, seq.Items.Count);
127                         XmlSchemaElement refBaz = seq.Items [0] as XmlSchemaElement;
128                         Assert.IsNotNull (refBaz);
129                         AssertCompiledElement (refBaz, QName ("Baz", ""), stringDatatype);
130
131                         qname = QName ("Bar", ns);
132                         XmlSchemaElement element = schema.Elements [qname] as XmlSchemaElement;
133                         AssertCompiledElement (element, qname, cType);
134                 }
135
136                 [Test]
137                 [ExpectedException (typeof (XmlSchemaException))]
138                 public void TestCompile_ZeroLength_TargetNamespace ()
139                 {
140                         XmlSchema schema = new XmlSchema ();
141                         schema.TargetNamespace = string.Empty;
142                         Assert.IsTrue (!schema.IsCompiled);
143
144                         // MS.NET 1.x: The Namespace '' is an invalid URI.
145                         // MS.NET 2.0: The targetNamespace attribute cannot have empty string as its value.
146                         schema.Compile (null);
147                 }
148
149                 [Test]
150                 [ExpectedException (typeof (XmlSchemaException))]
151                 public void TestCompileNonSchema ()
152                 {
153                         XmlTextReader xtr = new XmlTextReader ("<root/>", XmlNodeType.Document, null);
154                         XmlSchema schema = XmlSchema.Read (xtr, null);
155                         xtr.Close ();
156                 }
157
158                 [Test]
159                 public void TestSimpleImport ()
160                 {
161                         XmlSchema schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/xsd/3.xsd"), null);
162                         Assert.AreEqual ("urn:foo", schema.TargetNamespace);
163                         XmlSchemaImport import = schema.Includes [0] as XmlSchemaImport;
164                         Assert.IsNotNull (import);
165
166                         schema.Compile (null);
167                         Assert.AreEqual (4, schema.Elements.Count);
168                         Assert.IsNotNull (schema.Elements [QName ("Foo", "urn:foo")]);
169                         Assert.IsNotNull (schema.Elements [QName ("Bar", "urn:foo")]);
170                         Assert.IsNotNull (schema.Elements [QName ("Foo", "urn:bar")]);
171                         Assert.IsNotNull (schema.Elements [QName ("Bar", "urn:bar")]);
172                         
173                 }
174
175                 [Test]
176                 [Category ("MobileNotWorking")]
177                 public void TestSimpleMutualImport ()
178                 {
179                         XmlReader r = new XmlTextReader ("Test/XmlFiles/xsd/inter-inc-1.xsd");
180                         try {
181                                 XmlSchema.Read (r, null).Compile (null);
182                         } finally {
183                                 r.Close ();
184                         }
185                 }
186
187                 [Test]
188                 public void TestQualification ()
189                 {
190                         XmlSchema schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/xsd/5.xsd"), null);
191                         schema.Compile (null);
192                         XmlSchemaElement el = schema.Elements [QName ("Foo", "urn:bar")] as XmlSchemaElement;
193                         Assert.IsNotNull (el);
194                         XmlSchemaComplexType ct = el.ElementType as XmlSchemaComplexType;
195                         XmlSchemaSequence seq = ct.ContentTypeParticle as XmlSchemaSequence;
196                         XmlSchemaElement elp = seq.Items [0] as XmlSchemaElement;
197                         Assert.AreEqual (QName ("Bar", ""), elp.QualifiedName);
198
199                         schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/xsd/6.xsd"), null);
200                         schema.Compile (null);
201                         el = schema.Elements [QName ("Foo", "urn:bar")] as XmlSchemaElement;
202                         Assert.IsNotNull (el);
203                         ct = el.ElementType as XmlSchemaComplexType;
204                         seq = ct.ContentTypeParticle as XmlSchemaSequence;
205                         elp = seq.Items [0] as XmlSchemaElement;
206                         Assert.AreEqual (QName ("Bar", "urn:bar"), elp.QualifiedName);
207                 }
208
209                 [Test]
210                 public void TestWriteNamespaces ()
211                 {
212                         XmlDocument doc = new XmlDocument ();
213                         XmlSchema xs;
214                         StringWriter sw;
215                         XmlTextWriter xw;
216
217                         // empty
218                         xs = new XmlSchema ();
219                         sw = new StringWriter ();
220                         xw = new XmlTextWriter (sw);
221                         xs.Write (xw);
222                         doc.LoadXml (sw.ToString ());
223                         Assert.AreEqual ("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#1");
224
225                         // TargetNamespace
226                         xs = new XmlSchema ();
227                         sw = new StringWriter ();
228                         xw = new XmlTextWriter (sw);
229                         xs.TargetNamespace = "urn:foo";
230                         xs.Write (xw);
231                         doc.LoadXml (sw.ToString ());
232                         Assert.AreEqual ("<xs:schema xmlns:tns=\"urn:foo\" targetNamespace=\"urn:foo\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#2");
233
234                         // Zero-length TargetNamespace
235                         xs = new XmlSchema ();
236                         sw = new StringWriter ();
237                         xw = new XmlTextWriter (sw);
238                         xs.TargetNamespace = string.Empty;
239                         xs.Write (xw);
240                         doc.LoadXml (sw.ToString ());
241                         Assert.AreEqual ("<xs:schema targetNamespace=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#2b");
242
243                         // XmlSerializerNamespaces
244                         xs = new XmlSchema ();
245                         sw = new StringWriter ();
246                         xw = new XmlTextWriter (sw);
247                         xs.Namespaces.Add ("hoge", "urn:hoge");
248                         xs.Write (xw);
249                         doc.LoadXml (sw.ToString ());
250                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
251                         // Assert.AreEqual ("<schema xmlns:hoge=\"urn:hoge\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#3");
252
253                         // TargetNamespace + XmlSerializerNamespaces
254                         xs = new XmlSchema ();
255                         sw = new StringWriter ();
256                         xw = new XmlTextWriter (sw);
257                         xs.TargetNamespace = "urn:foo";
258                         xs.Namespaces.Add ("hoge", "urn:hoge");
259                         xs.Write (xw);
260                         doc.LoadXml (sw.ToString ());
261                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
262                         // Assert.AreEqual ("<schema xmlns:hoge=\"urn:hoge\" targetNamespace=\"urn:foo\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#4");
263
264                         // Add XmlSchema.Namespace to XmlSerializerNamespaces
265                         xs = new XmlSchema ();
266                         sw = new StringWriter ();
267                         xw = new XmlTextWriter (sw);
268                         xs.Namespaces.Add ("a", XmlSchema.Namespace);
269                         xs.Write (xw);
270                         doc.LoadXml (sw.ToString ());
271                         Assert.AreEqual ("<a:schema xmlns:a=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#5");
272
273                         // UnhandledAttributes + XmlSerializerNamespaces
274                         xs = new XmlSchema ();
275                         sw = new StringWriter ();
276                         xw = new XmlTextWriter (sw);
277                         XmlAttribute attr = doc.CreateAttribute ("hoge");
278                         xs.UnhandledAttributes = new XmlAttribute [] {attr};
279                         xs.Namespaces.Add ("hoge", "urn:hoge");
280                         xs.Write (xw);
281                         doc.LoadXml (sw.ToString ());
282                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
283                         // Assert.AreEqual ("<schema xmlns:hoge=\"urn:hoge\" hoge=\"\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#6");
284
285                         // Adding xmlns to UnhandledAttributes -> no output
286                         xs = new XmlSchema ();
287                         sw = new StringWriter ();
288                         xw = new XmlTextWriter (sw);
289                         attr = doc.CreateAttribute ("xmlns");
290                         attr.Value = "urn:foo";
291                         xs.UnhandledAttributes = new XmlAttribute [] {attr};
292                         xs.Write (xw);
293                         doc.LoadXml (sw.ToString ());
294                         Assert.AreEqual ("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml, "#7");
295                 }
296
297                 [Category ("NotWorking")]
298                 [Test]
299                 public void TestWriteNamespaces2 ()
300                 {
301                         string xmldecl = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
302                         XmlSchema xs = new XmlSchema ();
303                         XmlSerializerNamespaces nss =
304                                 new XmlSerializerNamespaces ();
305                         StringWriter sw;
306                         sw = new StringWriter ();
307                         xs.Write (new XmlTextWriter (sw));
308                         Assert.AreEqual (xmldecl + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString (), "#1");
309
310                         xs.Namespaces = nss;
311                         sw = new StringWriter ();
312                         xs.Write (new XmlTextWriter (sw));
313                         Assert.AreEqual (xmldecl + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString (), "#2");
314
315                         nss.Add ("foo", "urn:foo");
316                         sw = new StringWriter ();
317                         xs.Write (new XmlTextWriter (sw));
318                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
319                         // Assert.AreEqual (xmldecl + "<schema xmlns:foo=\"urn:foo\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString (), "#3");
320
321                         nss.Add ("", "urn:foo");
322                         sw = new StringWriter ();
323                         xs.Write (new XmlTextWriter (sw));
324                         // commenting out. .NET 2.0 outputs xs:schema instead of q1:schema, that also makes sense.
325                         // Assert.AreEqual (xmldecl + "<q1:schema xmlns:foo=\"urn:foo\" xmlns=\"urn:foo\" xmlns:q1=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString (), "#4");
326
327                         nss.Add ("q1", "urn:q1");
328                         sw = new StringWriter ();
329                         xs.Write (new XmlTextWriter (sw));
330                         //Not sure if testing for exact order of these name spaces is
331                         // relevent, so using less strict test that passes on MS.NET
332                         //Assert.AreEqual (xmldecl + "<q2:schema xmlns:foo=\"urn:foo\" xmlns:q1=\"urn:q1\" xmlns=\"urn:foo\" xmlns:q2=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString ());
333                         Assert.IsTrue (sw.ToString ().IndexOf ("xmlns:q1=\"urn:q1\"") != -1, "q1");
334                 }
335
336                 [Test]
337                 public void ReaderPositionAfterRead ()
338                 {
339                         string xsd = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>  <xs:element name='test' type='xs:integer'/></xs:schema>";
340                         XmlTextReader xtr = new XmlTextReader (xsd, XmlNodeType.Document, null);
341                         xtr.Read ();
342                         XmlSchema xs = XmlSchema.Read (xtr, null);
343                         Assert.AreEqual (XmlNodeType.EndElement, xtr.NodeType);
344                 }
345
346                 [Test]
347                 // bug #76865
348                 public void AmbiguityDetectionOnChameleonAnyOther ()
349                 {
350                         string xsd = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
351 <xs:complexType name='TestType'>
352   <xs:sequence>
353     <xs:any namespace='##other' minOccurs='0' />
354     <xs:element name='Item' /> 
355     <xs:any namespace='##other' minOccurs='0' />
356   </xs:sequence> 
357 </xs:complexType>
358 </xs:schema>";
359                         XmlSchema.Read (new XmlTextReader (xsd, XmlNodeType.Document, null), null);
360                 }
361
362                 [Test]
363                 // bug #77685
364                 public void ReadDoesNotIgnoreDocumentationEmptyElement ()
365                 {
366                         string schemaxml = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
367   <xs:element name='choice'>
368     <xs:annotation><xs:documentation /></xs:annotation>
369   </xs:element>
370 </xs:schema>";
371                         XmlTextReader tr = new XmlTextReader (
372                                 schemaxml, XmlNodeType.Document, null);
373                         XmlSchema schema = XmlSchema.Read (tr, null);
374                         XmlSchemaElement element =
375                                 schema.Items [0] as XmlSchemaElement;
376                         XmlSchemaAnnotation annotation = element.Annotation;
377                         XmlSchemaDocumentation doc =
378                                 annotation.Items [0] as XmlSchemaDocumentation;
379                         Assert.AreEqual (0, doc.Markup.Length);
380                 }
381
382
383                 [Test]
384                 // bug #77687
385                 public void CompileFillsSchemaPropertyInExternal ()
386                 {
387                         string schemaFileName = "Test/XmlFiles/xsd/77687.xsd";
388                         XmlTextReader tr = new XmlTextReader (schemaFileName);
389
390                         XmlSchema schema = XmlSchema.Read (tr, null);
391                         XmlSchemaInclude inc = (XmlSchemaInclude) schema.Includes [0];
392                         Assert.IsNull (inc.Schema);
393                         schema.Compile (null);
394                         tr.Close ();
395                         Assert.IsNotNull (inc.Schema);
396                 }
397
398                 [Test]
399                 // bug #78985 (contains two identical field path "@key" in 
400                 // two different keys where one is in scope within another)
401                 public void DuplicateKeyFieldAttributePath ()
402                 {
403                         string schemaFileName = "Test/XmlFiles/xsd/78985.xsd";
404                         string xmlFileName = "Test/XmlFiles/xsd/78985.xml";
405                         XmlTextReader tr = new XmlTextReader (schemaFileName);
406
407                         XmlValidatingReader vr = new XmlValidatingReader (
408                                 new XmlTextReader (xmlFileName));
409                         vr.Schemas.Add (XmlSchema.Read (tr, null));
410                         while (!vr.EOF)
411                                 vr.Read ();
412                 }
413
414                 [Test]
415                 public void ThreeLevelNestedInclusion ()
416                 {
417                         XmlTextReader r = new XmlTextReader ("Test/XmlFiles/xsd/361818.xsd");
418                         try {
419                                 XmlSchema xs = XmlSchema.Read (r, null);
420                                 xs.Compile (null);
421                         } finally {
422                                 r.Close ();
423                         }
424                 }
425
426                 [Test] // bug #502115
427                 public void ExtensionRedefineAttribute1 ()
428                 {
429                         const string xml = "<Bar xmlns='foo'/>";
430
431                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/extension-attr-redefine-1.xsd");
432
433                         XmlSchemaSet xss = new XmlSchemaSet ();
434                         xss.Add (schema);
435                         if (StrictMsCompliant) {
436                                 xss.Compile ();
437                         } else {
438                                 try {
439                                         xss.Compile ();
440                                         Assert.Fail ();
441                                 } catch (XmlSchemaException) {
442                                 }
443                                 return;
444                         }
445
446                         StringReader sr = new StringReader (xml);
447
448                         XmlReaderSettings settings = new XmlReaderSettings ();
449                         settings.ValidationType = ValidationType.Schema;
450                         settings.Schemas = xss;
451                         XmlReader vr = XmlReader.Create (sr, settings);
452
453                         try {
454                                 vr.Read ();
455                                 Assert.Fail ();
456                         } catch (XmlSchemaException) {
457                         }
458                 }
459
460                 [Test] // bug #502115
461                 public void ExtensionRedefineAttribute2 ()
462                 {
463                         const string xml = "<Bar xmlns='foo'/>";
464
465                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/extension-attr-redefine-2.xsd");
466
467                         XmlSchemaSet xss = new XmlSchemaSet ();
468                         xss.Add (schema);
469                         xss.Compile ();
470
471                         StringReader sr = new StringReader (xml);
472
473                         XmlReaderSettings settings = new XmlReaderSettings ();
474                         settings.ValidationType = ValidationType.Schema;
475                         settings.Schemas = xss;
476                         XmlReader vr = XmlReader.Create (sr, settings);
477
478                         while (vr.Read ()) ;
479                 }
480
481                 [Test] // bug #502115
482                 public void ExtensionRedefineAttribute3 ()
483                 {
484                         const string xml = "<Bar xmlns='foo'/>";
485
486                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/extension-attr-redefine-3.xsd");
487
488                         XmlSchemaSet xss = new XmlSchemaSet ();
489                         xss.Add (schema);
490                         if (StrictMsCompliant) {
491                                 xss.Compile ();
492                         } else {
493                                 try {
494                                         xss.Compile ();
495                                         Assert.Fail ();
496                                 } catch (XmlSchemaException) {
497                                 }
498                                 return;
499                         }
500
501                         StringReader sr = new StringReader ("<Bar xmlns='foo'/>");
502
503                         XmlReaderSettings settings = new XmlReaderSettings ();
504                         settings.ValidationType = ValidationType.Schema;
505                         settings.Schemas = xss;
506                         XmlReader vr = XmlReader.Create (sr, settings);
507
508                         while (vr.Read ()) ;
509                 }
510
511
512                 internal class XmlTestResolver : XmlResolver
513                 {                       
514                         Uri receivedUri;
515
516                         public override ICredentials Credentials
517                         {
518                             set { throw new NotSupportedException (); }
519                         }
520
521                         public override Uri ResolveUri (Uri baseUri, string relativeUri)
522                         {
523                             return new Uri (relativeUri);
524                         }
525                         
526                         public Uri ReceivedUri
527                         {
528                                 get { return receivedUri; }
529                         }
530
531                         public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
532                         {
533                                 receivedUri = absoluteUri;
534                                 
535                                 return null;
536                         }
537                 }       
538                 
539                 [Test]
540                 public void TestResolveUri ()
541                 {
542                         XmlSchemaSet schemaSet = new XmlSchemaSet ();
543                         FileStream stream = new FileStream ("Test/XmlFiles/xsd/resolveUriSchema.xsd", FileMode.Open, FileAccess.Read);
544                         schemaSet.Add ("http://tempuri.org/resolveUriSchema.xsd", new XmlTextReader (stream));
545
546                         XmlTestResolver resolver = new XmlTestResolver ();              
547                         
548                         XmlReaderSettings settings = new XmlReaderSettings ();                  
549                         settings.Schemas.XmlResolver = resolver; 
550                         settings.Schemas.Add (schemaSet);
551                         settings.ValidationType = ValidationType.Schema;
552                         settings.ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation;
553                         XmlReader reader = XmlReader.Create (stream, settings);
554                         
555                         try
556                         {
557                                 reader.Read ();         
558                         }
559                         catch (XmlException)
560                         {
561                                 // do nothing - we are expecting this exception because the test xmlresolver returns null from its 
562                                 // GetEntity method.
563                         }
564                         
565                         Assert.AreEqual ("assembly://MyAssembly.Name/MyProjectNameSpace/objects.xsd", resolver.ReceivedUri.OriginalString);
566                 }
567
568                 [Test]
569                 public void TestImportNoSchemaLocation()
570                 {
571                         XmlSchemaSet schemaSet = new XmlSchemaSet ();
572                         schemaSet.Add (GetSchema ("Test/XmlFiles/xsd/importNamespaceTest.xsd"));
573                         schemaSet.Add (GetSchema ("Test/XmlFiles/xsd/importedNamespace.xsd"));
574                         
575                         XmlReaderSettings settings = new XmlReaderSettings ();
576                         settings.Schemas.Add (schemaSet);
577                         settings.ValidationType = ValidationType.Schema;
578                         
579                         XmlReader reader = XmlReader.Create ("Test/XmlFiles/xsd/xsdimporttest.xml", settings);
580                         
581                         // Parse the file. 
582                         while (reader.Read()) {}
583                 }
584
585                 [Test]
586                 public void TestImportSchemaThatIncludesAnother ()
587                 {
588                         XmlSchema xs = GetSchema ("Test/XmlFiles/xsd/importNamespaceTest2.xsd");
589                         xs.Compile (null);
590                 }
591         }
592 }