2009-06-12 Bill Holmes <billholmes54@gmail.com>
[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 \r
14 namespace MonoTests.System.Xml\r
15 {\r
16         [TestFixture]\r
17         public class XmlUrlResolverTests : Assertion\r
18         {\r
19                 XmlUrlResolver resolver;\r
20 \r
21                 [SetUp]\r
22                 public void GetReady ()\r
23                 {\r
24                         resolver = new XmlUrlResolver ();\r
25                 }\r
26 \r
27                 [Test]\r
28                 public void FileUri ()\r
29                 {\r
30                         Uri resolved = resolver.ResolveUri (null, "Test/XmlFiles/xsd/xml.xsd");\r
31                         AssertEquals ("file", resolved.Scheme);\r
32                         Stream s = resolver.GetEntity (resolved, null, typeof (Stream)) as Stream;\r
33                 }\r
34 \r
35                 [Test]\r
36                 [Category ("NotDotNet")]\r
37                 public void FileUri2 ()\r
38                 {\r
39                         AssertEquals ("file://usr/local/src", resolver.ResolveUri (new Uri ("file://usr/local/src"), null).ToString ());\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                         AssertEquals ("file:///usr/local/src", resolver.ResolveUri (new Uri ("file:///usr/local/src"), null).ToString ());\r
44                 }\r
45 \r
46                 [Test]\r
47                 public void HttpUri ()\r
48                 {\r
49                         AssertEquals ("http://test.xml/", resolver.ResolveUri (null, "http://test.xml").ToString ());\r
50                 }\r
51 \r
52                 [Test]\r
53                 public void HttpUri2 ()\r
54                 {\r
55                         AssertEquals ("http://go-mono.com/", resolver.ResolveUri (new Uri ("http://go-mono.com"), null).ToString ());\r
56                 }\r
57 \r
58                 [Test]\r
59 #if !NET_2_0\r
60                 [Category ("NotDotNet")] // It should throw ArgumentNullException.\r
61 #endif\r
62                 [ExpectedException (typeof (ArgumentNullException))]\r
63                 public void ResolveUriWithNullArgs ()\r
64                 {\r
65                         resolver.ResolveUri (null, null);\r
66                         Fail ("Should be error (MS.NET throws ArgumentException here).");\r
67                 }\r
68 \r
69 //              [Test] Uncomment if you want to test.\r
70                 public void GetEntityWithNullArgs ()\r
71                 {\r
72                         Uri uri = new Uri ("http://www.go-mono.com/index.rss");\r
73                         resolver.GetEntity (uri, null, null);\r
74                 }\r
75 \r
76 #if NET_2_0\r
77                 [Test]\r
78                 [ExpectedException (typeof (ArgumentException))]\r
79                 public void GetEntityWithRelativeFileUri ()\r
80                 {\r
81                         resolver.GetEntity (new Uri ("file.txt", UriKind.Relative), null, typeof (Stream));\r
82                 }\r
83 #endif\r
84 \r
85                 [Test]\r
86                 [ExpectedException (typeof (XmlException))]\r
87                 public void GetEntityWithNonStreamReturnType ()\r
88                 {\r
89                         resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));\r
90                 }\r
91         }\r
92 }\r