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
14 using System.Reflection;
\r
17 namespace MonoTests.System.Xml
\r
20 public class XmlUrlResolverTests
\r
22 XmlUrlResolver resolver;
\r
25 public void GetReady ()
\r
27 resolver = new XmlUrlResolver ();
\r
31 public void FileUri ()
\r
33 Uri resolved = resolver.ResolveUri (null, "Test/XmlFiles/xsd/xml.xsd");
\r
34 Assert.AreEqual ("file", resolved.Scheme);
\r
35 Stream s = resolver.GetEntity (resolved, null, typeof (Stream)) as Stream;
\r
39 [Category ("NotDotNet")]
\r
40 public void FileUri2 ()
\r
42 Assert.AreEqual (resolver.ResolveUri (new Uri ("file://usr/local/src"), null).ToString (), "file://usr/local/src");
\r
43 // MS.NET returns the Uri.ToString() as
\r
44 // file://usr/local/src, but it is apparently
\r
45 // incorrect in the context of Unix path.
\r
46 Assert.AreEqual (resolver.ResolveUri (new Uri ("file:///usr/local/src"), null).ToString (), "file:///usr/local/src");
\r
50 public void HttpUri ()
\r
52 Assert.AreEqual (resolver.ResolveUri (null, "http://test.xml").ToString (), "http://test.xml/");
\r
56 public void HttpUri2 ()
\r
58 Assert.AreEqual (resolver.ResolveUri (new Uri ("http://go-mono.com"), null).ToString (), "http://go-mono.com/");
\r
63 [Category ("NotDotNet")] // It should throw ArgumentNullException.
\r
65 [ExpectedException (typeof (ArgumentNullException))]
\r
66 public void ResolveUriWithNullArgs ()
\r
68 resolver.ResolveUri (null, null);
\r
69 Assert.Fail ("Should be error (MS.NET throws ArgumentException here).");
\r
72 // [Test] Uncomment if you want to test.
\r
73 public void GetEntityWithNullArgs ()
\r
75 Uri uri = new Uri ("http://www.go-mono.com/index.rss");
\r
76 resolver.GetEntity (uri, null, null);
\r
81 [ExpectedException (typeof (ArgumentException))]
\r
82 public void GetEntityWithRelativeFileUri ()
\r
84 resolver.GetEntity (new Uri ("file.txt", UriKind.Relative), null, typeof (Stream));
\r
89 [ExpectedException (typeof (XmlException))]
\r
90 public void GetEntityWithNonStreamReturnType ()
\r
92 resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));
\r
96 public void NullAbsoluteUriWithCustomSchemedRelativeUri ()
\r
98 XmlResolver res = new XmlUrlResolver ();
\r
99 var uri = res.ResolveUri (null, "view:Standard.xslt");
\r
100 Assert.AreEqual ("view", uri.Scheme, "#1");
\r
101 Assert.AreEqual ("Standard.xslt", uri.AbsolutePath, "#2");
\r
102 Assert.AreEqual ("view:Standard.xslt", uri.AbsoluteUri, "#2");
\r
107 [Category("Async")]
\r
108 public void TestAsync ()
\r
110 var loc = Assembly.GetExecutingAssembly ().Location;
\r
111 Uri resolved = resolver.ResolveUri (null, loc);
\r
112 Assert.AreEqual ("file", resolved.Scheme);
\r
113 var task = resolver.GetEntityAsync (resolved, null, typeof (Stream));
\r
114 Assert.That (task.Wait (3000));
\r
115 Assert.IsInstanceOfType (typeof (Stream), task.Result);
\r
119 [Category("Async")]
\r
120 public void TestAsyncError ()
\r
122 var loc = Assembly.GetExecutingAssembly ().Location;
\r
123 Uri resolved = resolver.ResolveUri (null, loc);
\r
124 Assert.AreEqual ("file", resolved.Scheme);
\r
125 var task = resolver.GetEntityAsync (resolved, null, typeof (File));
\r
128 Assert.Fail ("#1");
\r
129 } catch (Exception ex) {
\r
130 if (ex is AggregateException)
\r
131 ex = ((AggregateException) ex).InnerException;
\r
132 Assert.IsInstanceOfType (typeof (XmlException), ex);
\r