Revert "Merge pull request #5330 from alexanderkyte/dedup_mkbundle"
[mono.git] / mcs / class / System.XML / Test / System.Xml / XmlUrlResolverTests.cs
1 //\r
2 // System.Xml.XmlUrlResolver.cs\r
3 //\r
4 // Authors:\r
5 //      Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)\r
6 //\r
7 // (C) 2003 Atsushi Enomoto\r
8 //\r
9 using System;\r
10 using System.IO;\r
11 using System.Xml;\r
12 using NUnit.Framework;\r
13 using System.Reflection;\r
14 \r
15 namespace MonoTests.System.Xml\r
16 {\r
17         [TestFixture]\r
18         public class XmlUrlResolverTests\r
19         {\r
20                 XmlUrlResolver resolver;\r
21 \r
22                 [SetUp]\r
23                 public void GetReady ()\r
24                 {\r
25                         resolver = new XmlUrlResolver ();\r
26                 }\r
27 \r
28                 [Test]\r
29                 public void FileUri ()\r
30                 {\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
34                 }\r
35 \r
36                 [Test]\r
37                 public void FileUri2 ()\r
38                 {\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
44                 }\r
45 \r
46                 [Test]\r
47                 public void HttpUri ()\r
48                 {\r
49                         Assert.AreEqual (resolver.ResolveUri (null, "http://test.xml").ToString (), "http://test.xml/");\r
50                 }\r
51 \r
52                 [Test]\r
53                 public void HttpUri2 ()\r
54                 {\r
55                         Assert.AreEqual (resolver.ResolveUri (new Uri ("http://go-mono.com"), null).ToString (), "http://go-mono.com/");\r
56                 }\r
57 \r
58                 [Test]\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
63                 {\r
64                         resolver.ResolveUri (null, null);\r
65                         Assert.Fail ("Should be error (MS.NET throws ArgumentException here).");\r
66                 }\r
67 \r
68 //              [Test] Uncomment if you want to test.\r
69                 public void GetEntityWithNullArgs ()\r
70                 {\r
71                         Uri uri = new Uri ("http://www.go-mono.com/index.rss");\r
72                         resolver.GetEntity (uri, null, null);\r
73                 }\r
74 \r
75                 [Test]\r
76                 [ExpectedException (typeof (InvalidOperationException))]\r
77                 public void GetEntityWithRelativeFileUri ()\r
78                 {\r
79                         resolver.GetEntity (new Uri ("file.txt", UriKind.Relative), null, typeof (Stream));\r
80                 }\r
81 \r
82                 [Test]\r
83                 [ExpectedException (typeof (XmlException))]\r
84                 public void GetEntityWithNonStreamReturnType ()\r
85                 {\r
86                         resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));\r
87                 }\r
88 \r
89                 [Test] // bug #998\r
90                 public void NullAbsoluteUriWithCustomSchemedRelativeUri ()\r
91                 {\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
97                 }\r
98 \r
99                 [Test]\r
100                 public void TestAsync ()\r
101                 {\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
108                 }\r
109 \r
110                 [Test]\r
111                 public void TestAsyncError ()\r
112                 {\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
117                         try {\r
118                                 task.Wait (3000);\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
124                         }\r
125                 }\r
126         }\r
127 }\r