XmlUrlResolverTests.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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
  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. Assert.AreEqual ("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. Assert.AreEqual (resolver.ResolveUri (new Uri ("file://usr/local/src"), null).ToString (), "file://usr/local/src");
  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. Assert.AreEqual (resolver.ResolveUri (new Uri ("file:///usr/local/src"), null).ToString (), "file:///usr/local/src");
  40. }
  41. [Test]
  42. public void HttpUri ()
  43. {
  44. Assert.AreEqual (resolver.ResolveUri (null, "http://test.xml").ToString (), "http://test.xml/");
  45. }
  46. [Test]
  47. public void HttpUri2 ()
  48. {
  49. Assert.AreEqual (resolver.ResolveUri (new Uri ("http://go-mono.com"), null).ToString (), "http://go-mono.com/");
  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. Assert.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. #if NET_2_0
  68. [Test]
  69. [ExpectedException (typeof (ArgumentException))]
  70. public void GetEntityWithRelativeFileUri ()
  71. {
  72. resolver.GetEntity (new Uri ("file.txt", UriKind.Relative), null, typeof (Stream));
  73. }
  74. #endif
  75. [Test]
  76. [ExpectedException (typeof (XmlException))]
  77. public void GetEntityWithNonStreamReturnType ()
  78. {
  79. resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));
  80. }
  81. }
  82. }