XmlUrlResolverTests.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. public void FileUri2 ()
  33. {
  34. AssertEquals ("file://usr/local/src", resolver.ResolveUri (new Uri ("file://usr/local/src"), null).ToString ());
  35. // MS.NET returns the Uri.ToString() as
  36. // file://usr/local/src, but it is apparently
  37. // incorrect in the context of Unix path.
  38. AssertEquals ("file:///usr/local/src", resolver.ResolveUri (new Uri ("file:///usr/local/src"), null).ToString ());
  39. }
  40. [Test]
  41. public void HttpUri ()
  42. {
  43. AssertEquals ("http://test.xml/", resolver.ResolveUri (null, "http://test.xml").ToString ());
  44. }
  45. [Test]
  46. public void HttpUri2 ()
  47. {
  48. AssertEquals ("http://go-mono.com/", resolver.ResolveUri (new Uri ("http://go-mono.com"), null).ToString ());
  49. }
  50. [Test]
  51. [ExpectedException (typeof (NullReferenceException))]
  52. public void ResolveUriWithNullArgs ()
  53. {
  54. resolver.ResolveUri (null, null);
  55. Fail ("Should be error (MS.NET throws ArgumentException here).");
  56. }
  57. // [Test] Uncomment if you want to test.
  58. public void GetEntityWithNullArgs ()
  59. {
  60. Uri uri = new Uri ("http://www.go-mono.com/index.rss");
  61. resolver.GetEntity (uri, null, null);
  62. }
  63. [Test]
  64. [ExpectedException (typeof (ArgumentException))]
  65. public void GetEntityWithRelativeFileUri ()
  66. {
  67. resolver.GetEntity (new Uri ("file://file.txt"), null, typeof (Stream));
  68. }
  69. [Test]
  70. [ExpectedException (typeof (XmlException))]
  71. public void GetEntityWithNonStreamReturnType ()
  72. {
  73. resolver.GetEntity (new Uri ("http://www.go-mono.com/"), null, typeof (File));
  74. }
  75. }
  76. }