2
0

XmlUrlResolverTests.cs 2.1 KB

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