XmlResolverTest.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // XmlResolverTest.cs - NUnit Test Cases for XmlResolver
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.IO;
  30. using System.Net;
  31. using System.Xml;
  32. using NUnit.Framework;
  33. namespace MonoTest.System.Xml {
  34. [TestFixture]
  35. public class XmlResolverTest {
  36. class ConcreteXmlResolver : XmlResolver {
  37. public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
  38. {
  39. throw new NotImplementedException ();
  40. }
  41. public override ICredentials Credentials {
  42. set { throw new NotImplementedException (); }
  43. }
  44. }
  45. bool isWin32 = false;
  46. [SetUp]
  47. public void SetUp ()
  48. {
  49. isWin32 = (Path.DirectorySeparatorChar == '\\');
  50. }
  51. [Test]
  52. [ExpectedException (typeof (ArgumentNullException))]
  53. public void ResolveUri_ ()
  54. {
  55. ConcreteXmlResolver xr = new ConcreteXmlResolver ();
  56. xr.ResolveUri (null, null);
  57. }
  58. #if NET_2_0
  59. [Test]
  60. public void ResolveUri ()
  61. {
  62. ConcreteXmlResolver xr = new ConcreteXmlResolver ();
  63. Uri uri = xr.ResolveUri (null, "/Moonlight");
  64. // note: this is *very* different from [silver|moon]light
  65. Assert.IsTrue (uri.IsAbsoluteUri, "null,string");
  66. if (isWin32) {
  67. string currentdir = Directory.GetCurrentDirectory ();
  68. string volume = currentdir.Substring (0, 2);
  69. Assert.AreEqual ("file:///" + volume + "/Moonlight", uri.ToString (), "ToString");
  70. } else
  71. Assert.AreEqual ("file:///Moonlight", uri.ToString (), "ToString");
  72. uri = new Uri ("http://www.mono-project.com");
  73. Uri u2 = xr.ResolveUri (uri, null);
  74. Assert.AreEqual (uri, u2, "Equals");
  75. Assert.IsTrue (Object.ReferenceEquals (uri, u2), "ReferenceEquals");
  76. u2 = xr.ResolveUri (uri, "/Moonlight");
  77. Assert.IsTrue (uri.IsAbsoluteUri, "abs,string");
  78. Assert.AreEqual ("http://www.mono-project.com/Moonlight", u2.ToString (), "ToString3");
  79. u2 = xr.ResolveUri (null, "http://www.mono-project.com");
  80. Assert.IsTrue (u2.IsAbsoluteUri, "null,absolute/http");
  81. Assert.AreEqual (uri, u2, "Equals-2");
  82. u2 = xr.ResolveUri (null, "https://www.mono-project.com");
  83. Assert.IsTrue (u2.IsAbsoluteUri, "null,absolute/https");
  84. u2 = xr.ResolveUri (null, "ftp://mono-project.com/download");
  85. Assert.IsTrue (u2.IsAbsoluteUri, "null,absolute/ftp");
  86. u2 = xr.ResolveUri (null, "file:///mystuff");
  87. Assert.IsTrue (u2.IsAbsoluteUri, "null,absolute/file");
  88. }
  89. #endif
  90. #if NET_4_5
  91. class AsyncXmlResolver : XmlResolver
  92. {
  93. public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
  94. {
  95. throw new AssertionException ("Should not be reached");
  96. }
  97. }
  98. [Test]
  99. [ExpectedException(typeof(NotImplementedException))]
  100. [Category("Async")]
  101. public void TestAsync ()
  102. {
  103. var ar = new AsyncXmlResolver ();
  104. var uri = new Uri ("http://www.mono-project.com");
  105. ar.GetEntityAsync (uri, null, typeof(string));
  106. }
  107. #endif
  108. }
  109. }