XmlUrlResolverTests.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // System.Xml.XmlUrlResolver.cs
  3. //
  4. // Authors:
  5. // Atsushi Enomoto ([email protected])
  6. //
  7. // (C) 2003 Atsushi Enomoto
  8. //
  9. using System;
  10. using System.IO;
  11. using System.Xml;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Xml
  14. {
  15. [TestFixture]
  16. public class XmlUrlResolverTests : Assertion
  17. {
  18. XmlUrlResolver resolver;
  19. [SetUp]
  20. public void GetReady ()
  21. {
  22. resolver = new XmlUrlResolver ();
  23. }
  24. [Test]
  25. public void FileUri ()
  26. {
  27. Uri resolved = resolver.ResolveUri (null, "Test/XmlFiles/xsd/xml.xsd");
  28. AssertEquals ("file", resolved.Scheme);
  29. Stream s = resolver.GetEntity (resolved, null, typeof (Stream)) as Stream;
  30. }
  31. [Test]
  32. [Category ("NotDotNet")]
  33. public void FileUri2 ()
  34. {
  35. AssertEquals ("file://usr/local/src", resolver.ResolveUri (new Uri ("file://usr/local/src"), null).ToString ());
  36. // MS.NET returns the Uri.ToString() as
  37. // file://usr/local/src, but it is apparently
  38. // incorrect in the context of Unix path.
  39. AssertEquals ("file:///usr/local/src", resolver.ResolveUri (new Uri ("file:///usr/local/src"), null).ToString ());
  40. }
  41. [Test]
  42. public void HttpUri ()
  43. {
  44. AssertEquals ("http://test.xml/", resolver.ResolveUri (null, "http://test.xml").ToString ());
  45. }
  46. [Test]
  47. public void HttpUri2 ()
  48. {
  49. AssertEquals ("http://go-mono.com/", resolver.ResolveUri (new Uri ("http://go-mono.com"), null).ToString ());
  50. }
  51. [Test]
  52. #if !NET_2_0
  53. [Category ("NotDotNet")] // It should throw ArgumentNullException.
  54. #endif
  55. [ExpectedException (typeof (ArgumentNullException))]
  56. public void ResolveUriWithNullArgs ()
  57. {
  58. resolver.ResolveUri (null, null);
  59. Fail ("Should be error (MS.NET throws ArgumentException here).");
  60. }
  61. // [Test] Uncomment if you want to test.
  62. public void GetEntityWithNullArgs ()
  63. {
  64. Uri uri = new Uri ("http://www.go-mono.com/index.rss");
  65. resolver.GetEntity (uri, null, null);
  66. }
  67. [Test]
  68. [ExpectedException (typeof (ArgumentException))]
  69. public void GetEntityWithRelativeFileUri ()
  70. {
  71. resolver.GetEntity (new Uri ("file://file.txt"), null, typeof (Stream));
  72. }
  73. [Test]
  74. [ExpectedException (typeof (XmlException))]
  75. public void GetEntityWithNonStreamReturnType ()
  76. {
  77. resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));
  78. }
  79. }
  80. }