2009-06-12 Bill Holmes <billholmes54@gmail.com>
[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                         AssertEquals (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 (fooValidated);
52                         Assert (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                         AssertNotNull (el);
62                         AssertEquals (XmlSchemaDerivationMethod.Extension, el.Block);
63
64                         el = schema.Items [1] as XmlSchemaElement;
65                         AssertNotNull (el);
66                         AssertEquals (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 (!schema.IsCompiled);
89                         schema.Compile (null);
90                         Assert (schema.IsCompiled);
91                         string ns = "urn:bar";
92
93                         XmlSchemaElement foo = (XmlSchemaElement) schema.Elements [QName ("Foo", ns)];
94                         AssertNotNull (foo);
95                         XmlSchemaDatatype stringDatatype = foo.ElementType as XmlSchemaDatatype;
96                         AssertNotNull (stringDatatype);
97
98                         // HogeType
99                         qname = QName ("HogeType", ns);
100                         cType = schema.SchemaTypes [qname] as XmlSchemaComplexType;
101                         AssertNotNull (cType);
102                         AssertNull (cType.ContentModel);
103                         AssertCompiledComplexType (cType, qname, 0, 0,
104                                 false, null, true, XmlSchemaContentType.ElementOnly);
105                         seq = cType.ContentTypeParticle as XmlSchemaSequence;
106                         AssertNotNull (seq);
107                         AssertEquals (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                         AssertNotNull (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                         AssertNotNull (cType.BaseSchemaType);
123
124                         seq = xccx.Particle as XmlSchemaSequence;
125                         AssertNotNull (seq);
126                         AssertEquals (1, seq.Items.Count);
127                         XmlSchemaElement refBaz = seq.Items [0] as XmlSchemaElement;
128                         AssertNotNull (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 (!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                         AssertEquals ("urn:foo", schema.TargetNamespace);
163                         XmlSchemaImport import = schema.Includes [0] as XmlSchemaImport;
164                         AssertNotNull (import);
165
166                         schema.Compile (null);
167                         AssertEquals (4, schema.Elements.Count);
168                         AssertNotNull (schema.Elements [QName ("Foo", "urn:foo")]);
169                         AssertNotNull (schema.Elements [QName ("Bar", "urn:foo")]);
170                         AssertNotNull (schema.Elements [QName ("Foo", "urn:bar")]);
171                         AssertNotNull (schema.Elements [QName ("Bar", "urn:bar")]);
172                         
173                 }
174
175                 [Test]
176                 public void TestSimpleMutualImport ()
177                 {
178                         XmlReader r = new XmlTextReader ("Test/XmlFiles/xsd/inter-inc-1.xsd");
179                         try {
180                                 XmlSchema.Read (r, null).Compile (null);
181                         } finally {
182                                 r.Close ();
183                         }
184                 }
185
186                 [Test]
187                 public void TestQualification ()
188                 {
189                         XmlSchema schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/xsd/5.xsd"), null);
190                         schema.Compile (null);
191                         XmlSchemaElement el = schema.Elements [QName ("Foo", "urn:bar")] as XmlSchemaElement;
192                         AssertNotNull (el);
193                         XmlSchemaComplexType ct = el.ElementType as XmlSchemaComplexType;
194                         XmlSchemaSequence seq = ct.ContentTypeParticle as XmlSchemaSequence;
195                         XmlSchemaElement elp = seq.Items [0] as XmlSchemaElement;
196                         AssertEquals (QName ("Bar", ""), elp.QualifiedName);
197
198                         schema = XmlSchema.Read (new XmlTextReader ("Test/XmlFiles/xsd/6.xsd"), null);
199                         schema.Compile (null);
200                         el = schema.Elements [QName ("Foo", "urn:bar")] as XmlSchemaElement;
201                         AssertNotNull (el);
202                         ct = el.ElementType as XmlSchemaComplexType;
203                         seq = ct.ContentTypeParticle as XmlSchemaSequence;
204                         elp = seq.Items [0] as XmlSchemaElement;
205                         AssertEquals (QName ("Bar", "urn:bar"), elp.QualifiedName);
206                 }
207
208                 [Test]
209                 public void TestWriteNamespaces ()
210                 {
211                         XmlDocument doc = new XmlDocument ();
212                         XmlSchema xs;
213                         StringWriter sw;
214                         XmlTextWriter xw;
215
216                         // empty
217                         xs = new XmlSchema ();
218                         sw = new StringWriter ();
219                         xw = new XmlTextWriter (sw);
220                         xs.Write (xw);
221                         doc.LoadXml (sw.ToString ());
222                         AssertEquals ("#1", "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
223
224                         // TargetNamespace
225                         xs = new XmlSchema ();
226                         sw = new StringWriter ();
227                         xw = new XmlTextWriter (sw);
228                         xs.TargetNamespace = "urn:foo";
229                         xs.Write (xw);
230                         doc.LoadXml (sw.ToString ());
231                         AssertEquals ("#2", "<xs:schema xmlns:tns=\"urn:foo\" targetNamespace=\"urn:foo\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
232
233                         // Zero-length TargetNamespace
234                         xs = new XmlSchema ();
235                         sw = new StringWriter ();
236                         xw = new XmlTextWriter (sw);
237                         xs.TargetNamespace = string.Empty;
238                         xs.Write (xw);
239                         doc.LoadXml (sw.ToString ());
240                         AssertEquals ("#2b", "<xs:schema targetNamespace=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
241
242                         // XmlSerializerNamespaces
243                         xs = new XmlSchema ();
244                         sw = new StringWriter ();
245                         xw = new XmlTextWriter (sw);
246                         xs.Namespaces.Add ("hoge", "urn:hoge");
247                         xs.Write (xw);
248                         doc.LoadXml (sw.ToString ());
249                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
250                         // AssertEquals ("#3", "<schema xmlns:hoge=\"urn:hoge\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
251
252                         // TargetNamespace + XmlSerializerNamespaces
253                         xs = new XmlSchema ();
254                         sw = new StringWriter ();
255                         xw = new XmlTextWriter (sw);
256                         xs.TargetNamespace = "urn:foo";
257                         xs.Namespaces.Add ("hoge", "urn:hoge");
258                         xs.Write (xw);
259                         doc.LoadXml (sw.ToString ());
260                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
261                         // AssertEquals ("#4", "<schema xmlns:hoge=\"urn:hoge\" targetNamespace=\"urn:foo\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
262
263                         // Add XmlSchema.Namespace to XmlSerializerNamespaces
264                         xs = new XmlSchema ();
265                         sw = new StringWriter ();
266                         xw = new XmlTextWriter (sw);
267                         xs.Namespaces.Add ("a", XmlSchema.Namespace);
268                         xs.Write (xw);
269                         doc.LoadXml (sw.ToString ());
270                         AssertEquals ("#5", "<a:schema xmlns:a=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
271
272                         // UnhandledAttributes + XmlSerializerNamespaces
273                         xs = new XmlSchema ();
274                         sw = new StringWriter ();
275                         xw = new XmlTextWriter (sw);
276                         XmlAttribute attr = doc.CreateAttribute ("hoge");
277                         xs.UnhandledAttributes = new XmlAttribute [] {attr};
278                         xs.Namespaces.Add ("hoge", "urn:hoge");
279                         xs.Write (xw);
280                         doc.LoadXml (sw.ToString ());
281                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
282                         // AssertEquals ("#6", "<schema xmlns:hoge=\"urn:hoge\" hoge=\"\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
283
284                         // Adding xmlns to UnhandledAttributes -> no output
285                         xs = new XmlSchema ();
286                         sw = new StringWriter ();
287                         xw = new XmlTextWriter (sw);
288                         attr = doc.CreateAttribute ("xmlns");
289                         attr.Value = "urn:foo";
290                         xs.UnhandledAttributes = new XmlAttribute [] {attr};
291                         xs.Write (xw);
292                         doc.LoadXml (sw.ToString ());
293                         AssertEquals ("#7", "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
294                 }
295
296                 [Category ("NotWorking")]
297                 [Test]
298                 public void TestWriteNamespaces2 ()
299                 {
300                         string xmldecl = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
301                         XmlSchema xs = new XmlSchema ();
302                         XmlSerializerNamespaces nss =
303                                 new XmlSerializerNamespaces ();
304                         StringWriter sw;
305                         sw = new StringWriter ();
306                         xs.Write (new XmlTextWriter (sw));
307                         AssertEquals ("#1", xmldecl + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString ());
308
309                         xs.Namespaces = nss;
310                         sw = new StringWriter ();
311                         xs.Write (new XmlTextWriter (sw));
312                         AssertEquals ("#2", xmldecl + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString ());
313
314                         nss.Add ("foo", "urn:foo");
315                         sw = new StringWriter ();
316                         xs.Write (new XmlTextWriter (sw));
317                         // commenting out. .NET 2.0 outputs xs:schema instead of schema, that also makes sense.
318                         // AssertEquals ("#3", xmldecl + "<schema xmlns:foo=\"urn:foo\" xmlns=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString ());
319
320                         nss.Add ("", "urn:foo");
321                         sw = new StringWriter ();
322                         xs.Write (new XmlTextWriter (sw));
323                         // commenting out. .NET 2.0 outputs xs:schema instead of q1:schema, that also makes sense.
324                         // AssertEquals ("#4", xmldecl + "<q1:schema xmlns:foo=\"urn:foo\" xmlns=\"urn:foo\" xmlns:q1=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString ());
325
326                         nss.Add ("q1", "urn:q1");
327                         sw = new StringWriter ();
328                         xs.Write (new XmlTextWriter (sw));
329                         //Not sure if testing for exact order of these name spaces is
330                         // relevent, so using less strict test that passes on MS.NET
331                         //AssertEquals (xmldecl + "<q2:schema xmlns:foo=\"urn:foo\" xmlns:q1=\"urn:q1\" xmlns=\"urn:foo\" xmlns:q2=\"http://www.w3.org/2001/XMLSchema\" />", sw.ToString ());
332                         Assert("q1", sw.ToString ().IndexOf ("xmlns:q1=\"urn:q1\"") != -1);
333                 }
334
335                 [Test]
336                 public void ReaderPositionAfterRead ()
337                 {
338                         string xsd = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' elementFormDefault='qualified'>  <xs:element name='test' type='xs:integer'/></xs:schema>";
339                         XmlTextReader xtr = new XmlTextReader (xsd, XmlNodeType.Document, null);
340                         xtr.Read ();
341                         XmlSchema xs = XmlSchema.Read (xtr, null);
342                         AssertEquals (XmlNodeType.EndElement, xtr.NodeType);
343                 }
344
345                 [Test]
346                 // bug #76865
347                 public void AmbiguityDetectionOnChameleonAnyOther ()
348                 {
349                         string xsd = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
350 <xs:complexType name='TestType'>
351   <xs:sequence>
352     <xs:any namespace='##other' minOccurs='0' />
353     <xs:element name='Item' /> 
354     <xs:any namespace='##other' minOccurs='0' />
355   </xs:sequence> 
356 </xs:complexType>
357 </xs:schema>";
358                         XmlSchema.Read (new XmlTextReader (xsd, XmlNodeType.Document, null), null);
359                 }
360
361                 [Test]
362                 // bug #77685
363                 public void ReadDoesNotIgnoreDocumentationEmptyElement ()
364                 {
365                         string schemaxml = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
366   <xs:element name='choice'>
367     <xs:annotation><xs:documentation /></xs:annotation>
368   </xs:element>
369 </xs:schema>";
370                         XmlTextReader tr = new XmlTextReader (
371                                 schemaxml, XmlNodeType.Document, null);
372                         XmlSchema schema = XmlSchema.Read (tr, null);
373                         XmlSchemaElement element =
374                                 schema.Items [0] as XmlSchemaElement;
375                         XmlSchemaAnnotation annotation = element.Annotation;
376                         XmlSchemaDocumentation doc =
377                                 annotation.Items [0] as XmlSchemaDocumentation;
378                         AssertEquals (0, doc.Markup.Length);
379                 }
380
381
382                 [Test]
383                 // bug #77687
384                 public void CompileFillsSchemaPropertyInExternal ()
385                 {
386                         string schemaFileName = "Test/XmlFiles/xsd/77687.xsd";
387                         XmlTextReader tr = new XmlTextReader (schemaFileName);
388
389                         XmlSchema schema = XmlSchema.Read (tr, null);
390                         XmlSchemaInclude inc = (XmlSchemaInclude) schema.Includes [0];
391                         AssertNull (inc.Schema);
392                         schema.Compile (null);
393                         tr.Close ();
394                         AssertNotNull (inc.Schema);
395                 }
396
397                 [Test]
398                 // bug #78985 (contains two identical field path "@key" in 
399                 // two different keys where one is in scope within another)
400                 public void DuplicateKeyFieldAttributePath ()
401                 {
402                         string schemaFileName = "Test/XmlFiles/xsd/78985.xsd";
403                         string xmlFileName = "Test/XmlFiles/xsd/78985.xml";
404                         XmlTextReader tr = new XmlTextReader (schemaFileName);
405
406                         XmlValidatingReader vr = new XmlValidatingReader (
407                                 new XmlTextReader (xmlFileName));
408                         vr.Schemas.Add (XmlSchema.Read (tr, null));
409                         while (!vr.EOF)
410                                 vr.Read ();
411                 }
412
413                 [Test]
414                 public void ThreeLevelNestedInclusion ()
415                 {
416                         XmlTextReader r = new XmlTextReader ("Test/XmlFiles/xsd/361818.xsd");
417                         try {
418                                 XmlSchema xs = XmlSchema.Read (r, null);
419                                 xs.Compile (null);
420                         } finally {
421                                 r.Close ();
422                         }
423                 }
424
425                 [Test] // bug #502115
426                 public void ExtensionRedefineAttribute1 ()
427                 {
428                         const string xml = "<Bar xmlns='foo'/>";
429
430                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/extension-attr-redefine-1.xsd");
431
432 #if NET_2_0
433                         XmlSchemaSet xss = new XmlSchemaSet ();
434                         xss.Add (schema);
435                         if (StrictMsCompliant) {
436                                 xss.Compile ();
437                         } else {
438                                 try {
439                                         xss.Compile ();
440                                         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 #else
453                         if (StrictMsCompliant) {
454                                 schema.Compile (null);
455                         } else {
456                                 try {
457                                         schema.Compile (null);
458                                         Fail ();
459                                 } catch (XmlSchemaException) {
460                                 }
461                         }
462
463                         XmlValidatingReader vr = new XmlValidatingReader (xml,
464                                 XmlNodeType.Document, null);
465                         vr.Schemas.Add (schema);
466                         vr.ValidationType = ValidationType.Schema;
467 #endif
468
469                         try {
470                                 vr.Read ();
471                                 Fail ();
472                         } catch (XmlSchemaException) {
473                         }
474                 }
475
476                 [Test] // bug #502115
477                 public void ExtensionRedefineAttribute2 ()
478                 {
479                         const string xml = "<Bar xmlns='foo'/>";
480
481                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/extension-attr-redefine-2.xsd");
482
483 #if NET_2_0
484                         XmlSchemaSet xss = new XmlSchemaSet ();
485                         xss.Add (schema);
486                         xss.Compile ();
487
488                         StringReader sr = new StringReader (xml);
489
490                         XmlReaderSettings settings = new XmlReaderSettings ();
491                         settings.ValidationType = ValidationType.Schema;
492                         settings.Schemas = xss;
493                         XmlReader vr = XmlReader.Create (sr, settings);
494 #else
495                         schema.Compile (null);
496
497                         XmlValidatingReader vr = new XmlValidatingReader (xml,
498                                 XmlNodeType.Document, null);
499                         vr.Schemas.Add (schema);
500                         vr.ValidationType = ValidationType.Schema;
501 #endif
502
503                         while (vr.Read ()) ;
504                 }
505
506                 [Test] // bug #502115
507                 public void ExtensionRedefineAttribute3 ()
508                 {
509                         const string xml = "<Bar xmlns='foo'/>";
510
511                         XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/extension-attr-redefine-3.xsd");
512
513 #if NET_2_0
514                         XmlSchemaSet xss = new XmlSchemaSet ();
515                         xss.Add (schema);
516                         if (StrictMsCompliant) {
517                                 xss.Compile ();
518                         } else {
519                                 try {
520                                         xss.Compile ();
521                                         Fail ();
522                                 } catch (XmlSchemaException) {
523                                 }
524                                 return;
525                         }
526
527                         StringReader sr = new StringReader ("<Bar xmlns='foo'/>");
528
529                         XmlReaderSettings settings = new XmlReaderSettings ();
530                         settings.ValidationType = ValidationType.Schema;
531                         settings.Schemas = xss;
532                         XmlReader vr = XmlReader.Create (sr, settings);
533 #else
534                         if (StrictMsCompliant) {
535                                 schema.Compile (null);
536                         } else {
537                                 try {
538                                         schema.Compile (null);
539                                         Fail ();
540                                 } catch (XmlSchemaException) {
541                                 }
542                         }
543
544                         XmlValidatingReader vr = new XmlValidatingReader (xml,
545                                 XmlNodeType.Document, null);
546                         vr.Schemas.Add (schema);
547                         vr.ValidationType = ValidationType.Schema;
548 #endif
549
550                         while (vr.Read ()) ;
551                 }
552
553 #if NET_2_0
554
555                 internal class XmlTestResolver : XmlResolver
556                 {                       
557                         Uri receivedUri;
558
559                         public override ICredentials Credentials
560                         {
561                             set { throw new NotSupportedException (); }
562                         }
563
564                         public override Uri ResolveUri (Uri baseUri, string relativeUri)
565                         {
566                             return new Uri (relativeUri);
567                         }
568                         
569                         public Uri ReceivedUri
570                         {
571                                 get { return receivedUri; }
572                         }
573
574                         public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
575                         {
576                                 receivedUri = absoluteUri;
577                                 
578                                 return null;
579                         }
580                 }       
581                 
582                 [Test]
583                 public void TestResolveUri ()
584                 {
585                         XmlSchemaSet schemaSet = new XmlSchemaSet ();
586                         FileStream stream = new FileStream ("Test/XmlFiles/xsd/resolveUriSchema.xsd", FileMode.Open);
587                         schemaSet.Add ("http://tempuri.org/resolveUriSchema.xsd", new XmlTextReader (stream));
588
589                         XmlTestResolver resolver = new XmlTestResolver ();              
590                         
591                         XmlReaderSettings settings = new XmlReaderSettings ();                  
592                         settings.Schemas.XmlResolver = resolver; 
593                         settings.Schemas.Add (schemaSet);
594                         settings.ValidationType = ValidationType.Schema;
595                         settings.ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation;
596                         XmlReader reader = XmlReader.Create (stream, settings);
597                         
598                         try
599                         {
600                                 reader.Read ();         
601                         }
602                         catch (XmlException)
603                         {
604                                 // do nothing - we are expecting this exception because the test xmlresolver returns null from its 
605                                 // GetEntity method.
606                         }
607                         
608                         AssertEquals ("assembly://MyAssembly.Name/MyProjectNameSpace/objects.xsd", resolver.ReceivedUri.OriginalString);
609                 }
610
611                 [Test]
612                 public void TestImportNoSchemaLocation()
613                 {
614                         XmlSchemaSet schemaSet = new XmlSchemaSet ();
615                         schemaSet.Add (GetSchema ("Test/XmlFiles/xsd/importNamespaceTest.xsd"));
616                         schemaSet.Add (GetSchema ("Test/XmlFiles/xsd/importedNamespace.xsd"));
617                         
618                         XmlReaderSettings settings = new XmlReaderSettings ();
619                         settings.Schemas.Add (schemaSet);
620                         settings.ValidationType = ValidationType.Schema;
621                         
622                         XmlReader reader = XmlReader.Create ("Test/XmlFiles/xsd/xsdimporttest.xml", settings);
623                         
624                         // Parse the file. 
625                         while (reader.Read()) {}
626                 }
627 #endif
628         }
629 }