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
62 [ExpectedException (typeof (ArgumentNullException))]
\r
63 public void ResolveUriWithNullArgs ()
\r
65 resolver.ResolveUri (null, null);
\r
66 Assert.Fail ("Should be error (MS.NET throws ArgumentException here).");
\r
69 // [Test] Uncomment if you want to test.
\r
70 public void GetEntityWithNullArgs ()
\r
72 Uri uri = new Uri ("http://www.go-mono.com/index.rss");
\r
73 resolver.GetEntity (uri, null, null);
\r
77 [ExpectedException (typeof (ArgumentException))]
\r
78 public void GetEntityWithRelativeFileUri ()
\r
80 resolver.GetEntity (new Uri ("file.txt", UriKind.Relative), null, typeof (Stream));
\r
84 [ExpectedException (typeof (XmlException))]
\r
85 public void GetEntityWithNonStreamReturnType ()
\r
87 resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));
\r
91 public void NullAbsoluteUriWithCustomSchemedRelativeUri ()
\r
93 XmlResolver res = new XmlUrlResolver ();
\r
94 var uri = res.ResolveUri (null, "view:Standard.xslt");
\r
95 Assert.AreEqual ("view", uri.Scheme, "#1");
\r
96 Assert.AreEqual ("Standard.xslt", uri.AbsolutePath, "#2");
\r
97 Assert.AreEqual ("view:Standard.xslt", uri.AbsoluteUri, "#2");
\r
102 public void TestAsync ()
\r
104 var loc = Assembly.GetExecutingAssembly ().Location;
\r
105 Uri resolved = resolver.ResolveUri (null, loc);
\r
106 Assert.AreEqual ("file", resolved.Scheme);
\r
107 var task = resolver.GetEntityAsync (resolved, null, typeof (Stream));
\r
108 Assert.IsTrue (task.Wait (3000));
\r
109 Assert.IsTrue (task.Result is Stream);
\r
113 public void TestAsyncError ()
\r
115 var loc = Assembly.GetExecutingAssembly ().Location;
\r
116 Uri resolved = resolver.ResolveUri (null, loc);
\r
117 Assert.AreEqual ("file", resolved.Scheme);
\r
118 var task = resolver.GetEntityAsync (resolved, null, typeof (File));
\r
121 Assert.Fail ("#1");
\r
122 } catch (Exception ex) {
\r
123 if (ex is AggregateException)
\r
124 ex = ((AggregateException) ex).InnerException;
\r
125 Assert.IsTrue (ex is XmlException);
\r