ApplicationHostTest.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // System.Web.Hosting.ApplicationHost.cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Runtime.Serialization;
  31. using System.IO;
  32. using System.Web.Hosting;
  33. using NUnit.Framework;
  34. using System.Web;
  35. namespace MonoTests.System.Web.Hosting {
  36. public class MBR : MarshalByRefObject {
  37. public string GetDomainName ()
  38. {
  39. return AppDomain.CurrentDomain.FriendlyName;
  40. }
  41. public AppDomain GetDomain ()
  42. {
  43. return AppDomain.CurrentDomain;
  44. }
  45. }
  46. [Serializable]
  47. public class MySerializable {
  48. public string GetDomainName ()
  49. {
  50. return AppDomain.CurrentDomain.FriendlyName;
  51. }
  52. }
  53. [TestFixture]
  54. public class ApplicationHostTest {
  55. [SetUp]
  56. public void Setup ()
  57. {
  58. try {
  59. //
  60. // Only needed in Windows, where we need to have a bin/ASSEMBLY.DLL
  61. //
  62. string p = typeof (ApplicationHostTest).Assembly.Location;
  63. try {
  64. Directory.Delete ("bin", true);
  65. } catch {}
  66. try {
  67. Directory.CreateDirectory ("bin");
  68. } catch {}
  69. string fn = Path.GetFileName (p);
  70. File.Copy (p, Path.Combine ("bin", fn));
  71. } catch {}
  72. }
  73. [TearDown] public void Shutdown ()
  74. {
  75. try {
  76. Directory.Delete ("bin", true);
  77. } catch {}
  78. }
  79. [Test][ExpectedException (typeof (NullReferenceException))]
  80. public void ConstructorTestNull ()
  81. {
  82. ApplicationHost.CreateApplicationHost (null, null, null);
  83. }
  84. [Test]
  85. [Category ("NotWorking")]
  86. [ExpectedException (typeof (ArgumentException))]
  87. public void ConstructorTestNull2 ()
  88. {
  89. //
  90. // Throws an Uri exception from Uri.Parse
  91. //
  92. ApplicationHost.CreateApplicationHost (null, "/app", ".");
  93. }
  94. [Test]
  95. [Category("NotWorking")]
  96. [ExpectedException (typeof (ArgumentNullException))]
  97. public void ConstructorTestNull3 ()
  98. {
  99. //
  100. // Throws an Uri exception from Uri.Parse
  101. //
  102. ApplicationHost.CreateApplicationHost (typeof (MBR), null, ".");
  103. }
  104. [Test][ExpectedException (typeof (NullReferenceException))]
  105. public void ConstructorTestNull4 ()
  106. {
  107. //
  108. // Throws an Uri exception from Uri.Parse
  109. //
  110. ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", null);
  111. }
  112. [Test]
  113. [ExpectedException(typeof(SerializationException))]
  114. #if TARGET_JVM //System.Security.Policy.Evidence not implemented
  115. [Category ("NotWorking")]
  116. #endif
  117. public void Constructor_PlainType ()
  118. {
  119. ApplicationHost.CreateApplicationHost (typeof (ApplicationHostTest), "/app", Environment.CurrentDirectory);
  120. }
  121. [Test]
  122. public void Constructor_SerializableType ()
  123. {
  124. object o = ApplicationHost.CreateApplicationHost (typeof (MySerializable), "/app", Environment.CurrentDirectory);
  125. Assert.AreEqual (typeof (MySerializable), o.GetType (), "C2");
  126. MySerializable m = (MySerializable) o;
  127. Assert.AreEqual (m.GetDomainName (), AppDomain.CurrentDomain.FriendlyName, "C4");
  128. }
  129. static void p (string s, object x)
  130. {
  131. Console.WriteLine ("{0} {1}", s, x);
  132. }
  133. [Test]
  134. [Category ("NotDotNet")] // D2 and D3 asserts will fail in windows on because file system environment
  135. public void ConstructorTest ()
  136. {
  137. object o = ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", Environment.CurrentDirectory);
  138. Assert.AreEqual (typeof (MBR), o.GetType (), "C5");
  139. MBR m = (MBR) o;
  140. Assert.AreEqual (true, m.GetDomainName () != AppDomain.CurrentDomain.FriendlyName);
  141. AppDomain other = m.GetDomain ();
  142. AppDomainSetup setup = other.SetupInformation;
  143. string tb = Environment.CurrentDirectory.Replace ("\\","/");
  144. if (tb.EndsWith ("/"))
  145. tb = tb.Substring (0, tb.Length - 1);
  146. // Need to fix an issue in AppDomainSetup
  147. // Assert.AreEqual (tb + "/", setup.ApplicationBase, "D1");
  148. p ("AppDomain's Applicationname is: ", setup.ApplicationName);
  149. Assert.AreEqual (null, setup.CachePath, "D2");
  150. Assert.AreEqual (tb + "/web.config", setup.ConfigurationFile, "D3");
  151. Assert.AreEqual (false, setup.DisallowBindingRedirects, "D4");
  152. Assert.AreEqual (true, setup.DisallowCodeDownload, "D5");
  153. Assert.AreEqual (false, setup.DisallowPublisherPolicy, "D6");
  154. // Disabling D7 test, as we set it there to avoid locking in sys.web.compilation
  155. // Assert.AreEqual (null, setup.DynamicBase, "D7");
  156. Assert.AreEqual (null, setup.LicenseFile, "D8");
  157. //Assert.AreEqual (LoaderOptimization.NotSpecified, setup.LoaderOptimization);
  158. p ("LoaderOptimization is: ", setup.LoaderOptimization);
  159. string expected = Path.Combine (Environment.CurrentDirectory, "bin");
  160. Assert.AreEqual (expected, setup.PrivateBinPath, "D9");
  161. Assert.AreEqual (setup.PrivateBinPathProbe, "*", "D10");
  162. p ("ShadowCopyDirs: ", setup.ShadowCopyDirectories);
  163. Assert.AreEqual (true, setup.ShadowCopyDirectories.EndsWith ("bin"), "D11");
  164. Assert.AreEqual (false, setup.ShadowCopyDirectories.StartsWith ("file:"), "D12");
  165. Assert.AreEqual ("true", setup.ShadowCopyFiles, "D13");
  166. p ("ApsInstal", HttpRuntime.AspInstallDirectory);
  167. }
  168. }
  169. }