2 // System.Xml.XmlUrlResolver.cs
\r
5 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
\r
7 // (C) 2003 Atsushi Enomoto
\r
12 using NUnit.Framework;
\r
13 using System.Reflection;
\r
15 namespace MonoTests.System.Xml
\r
18 public class XmlUrlResolverTests
\r
20 XmlUrlResolver resolver;
\r
23 public void GetReady ()
\r
25 resolver = new XmlUrlResolver ();
\r
29 public void FileUri ()
\r
31 Uri resolved = resolver.ResolveUri (null, "Test/XmlFiles/xsd/xml.xsd");
\r
32 Assert.AreEqual ("file", resolved.Scheme);
\r
33 Stream s = resolver.GetEntity (resolved, null, typeof (Stream)) as Stream;
\r
37 public void FileUri2 ()
\r
39 Assert.AreEqual (resolver.ResolveUri (new Uri ("file://usr/local/src"), null).ToString (), "file://usr/local/src");
\r
40 // MS.NET returns the Uri.ToString() as
\r
41 // file://usr/local/src, but it is apparently
\r
42 // incorrect in the context of Unix path.
\r
43 Assert.AreEqual (resolver.ResolveUri (new Uri ("file:///usr/local/src"), null).ToString (), "file:///usr/local/src");
\r
47 public void HttpUri ()
\r
49 Assert.AreEqual (resolver.ResolveUri (null, "http://test.xml").ToString (), "http://test.xml/");
\r
53 public void HttpUri2 ()
\r
55 Assert.AreEqual (resolver.ResolveUri (new Uri ("http://go-mono.com"), null).ToString (), "http://go-mono.com/");
\r
59 [Category ("NotDotNet")] // It should throw ArgumentNullException.
\r
60 [Ignore(".NET implementation does not throw ArgumentNullException.")]
\r
61 [ExpectedException (typeof (ArgumentNullException))]
\r
62 public void ResolveUriWithNullArgs ()
\r
64 resolver.ResolveUri (null, null);
\r
65 Assert.Fail ("Should be error (MS.NET throws ArgumentException here).");
\r
68 // [Test] Uncomment if you want to test.
\r
69 public void GetEntityWithNullArgs ()
\r
71 Uri uri = new Uri ("http://www.go-mono.com/index.rss");
\r
72 resolver.GetEntity (uri, null, null);
\r
76 [ExpectedException (typeof (InvalidOperationException))]
\r
77 public void GetEntityWithRelativeFileUri ()
\r
79 resolver.GetEntity (new Uri ("file.txt", UriKind.Relative), null, typeof (Stream));
\r
83 [ExpectedException (typeof (XmlException))]
\r
84 public void GetEntityWithNonStreamReturnType ()
\r
86 resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));
\r
90 public void NullAbsoluteUriWithCustomSchemedRelativeUri ()
\r
92 XmlResolver res = new XmlUrlResolver ();
\r
93 var uri = res.ResolveUri (null, "view:Standard.xslt");
\r
94 Assert.AreEqual ("view", uri.Scheme, "#1");
\r
95 Assert.AreEqual ("Standard.xslt", uri.AbsolutePath, "#2");
\r
96 Assert.AreEqual ("view:Standard.xslt", uri.AbsoluteUri, "#2");
\r
100 public void TestAsync ()
\r
102 var loc = Assembly.GetExecutingAssembly ().Location;
\r
103 Uri resolved = resolver.ResolveUri (null, loc);
\r
104 Assert.AreEqual ("file", resolved.Scheme);
\r
105 var task = resolver.GetEntityAsync (resolved, null, typeof (Stream));
\r
106 Assert.IsTrue (task.Wait (3000));
\r
107 Assert.IsTrue (task.Result is Stream);
\r
111 public void TestAsyncError ()
\r
113 var loc = Assembly.GetExecutingAssembly ().Location;
\r
114 Uri resolved = resolver.ResolveUri (null, loc);
\r
115 Assert.AreEqual ("file", resolved.Scheme);
\r
116 var task = resolver.GetEntityAsync (resolved, null, typeof (File));
\r
119 Assert.Fail ("#1");
\r
120 } catch (Exception ex) {
\r
121 if (ex is AggregateException)
\r
122 ex = ((AggregateException) ex).InnerException;
\r
123 Assert.IsTrue (ex is XmlException);
\r