ApplicationHostTest.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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] public void Setup ()
  56. {
  57. try {
  58. //
  59. // Only needed in Windows, where we need to have a bin/ASSEMBLY.DLL
  60. //
  61. string p = typeof (ApplicationHostTest).Assembly.Location;
  62. try {
  63. Directory.Delete ("bin", true);
  64. } catch {}
  65. try {
  66. Directory.CreateDirectory ("bin");
  67. } catch {}
  68. string fn = Path.GetFileName (p);
  69. File.Copy (p, Path.Combine ("bin", fn));
  70. } catch {}
  71. }
  72. [TearDown] public void Shutdown ()
  73. {
  74. try {
  75. Directory.Delete ("bin", true);
  76. } catch {}
  77. }
  78. [Test][ExpectedException (typeof (NullReferenceException))]
  79. public void ConstructorTestNull ()
  80. {
  81. ApplicationHost.CreateApplicationHost (null, null, null);
  82. }
  83. [Test][ExpectedException (typeof (UriFormatException))]
  84. public void ConstructorTestNull2 ()
  85. {
  86. //
  87. // Throws an Uri exception from Uri.Parse
  88. //
  89. ApplicationHost.CreateApplicationHost (null, "/app", ".");
  90. }
  91. [Test][ExpectedException (typeof (UriFormatException))]
  92. public void ConstructorTestNull3 ()
  93. {
  94. //
  95. // Throws an Uri exception from Uri.Parse
  96. //
  97. ApplicationHost.CreateApplicationHost (typeof (MBR), null, ".");
  98. }
  99. [Test][ExpectedException (typeof (NullReferenceException))]
  100. public void ConstructorTestNull4 ()
  101. {
  102. //
  103. // Throws an Uri exception from Uri.Parse
  104. //
  105. ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", null);
  106. }
  107. [Test][ExpectedException(typeof(SerializationException))]
  108. public void Constructor_PlainType ()
  109. {
  110. ApplicationHost.CreateApplicationHost (typeof (ApplicationHostTest), "/app", Environment.CurrentDirectory);
  111. }
  112. [Test]
  113. public void Constructor_SerializableType ()
  114. {
  115. object o = ApplicationHost.CreateApplicationHost (typeof (MySerializable), "/app", Environment.CurrentDirectory);
  116. Assert.AreEqual (typeof (MySerializable), o.GetType (), "C2");
  117. MySerializable m = (MySerializable) o;
  118. Assert.AreEqual (m.GetDomainName (), AppDomain.CurrentDomain.FriendlyName, "C4");
  119. }
  120. static void p (string s, object x)
  121. {
  122. Console.WriteLine ("{0} {1}", s, x);
  123. }
  124. [Test]
  125. public void ConstructorTest ()
  126. {
  127. object o = ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", Environment.CurrentDirectory);
  128. Assert.AreEqual (typeof (MBR), o.GetType (), "C5");
  129. MBR m = (MBR) o;
  130. Assert.AreEqual (true, m.GetDomainName () != AppDomain.CurrentDomain.FriendlyName);
  131. AppDomain other = m.GetDomain ();
  132. AppDomainSetup setup = other.SetupInformation;
  133. string tb = Environment.CurrentDirectory.Replace ("\\","/");
  134. if (tb.EndsWith ("/"))
  135. tb = tb.Substring (0, tb.Length - 1);
  136. // Need to fix an issue in AppDomainSetup
  137. // Assert.AreEqual (tb + "/", setup.ApplicationBase, "D1");
  138. p ("AppDomain's Applicationname is: ", setup.ApplicationName);
  139. Assert.AreEqual (null, setup.CachePath, "D2");
  140. Assert.AreEqual (tb + "/web.config", setup.ConfigurationFile, "D3");
  141. Assert.AreEqual (false, setup.DisallowBindingRedirects, "D4");
  142. Assert.AreEqual (true, setup.DisallowCodeDownload, "D5");
  143. Assert.AreEqual (false, setup.DisallowPublisherPolicy, "D6");
  144. // Disabling D7 test, as we set it there to avoid locking in sys.web.compilation
  145. // Assert.AreEqual (null, setup.DynamicBase, "D7");
  146. Assert.AreEqual (null, setup.LicenseFile, "D8");
  147. //Assert.AreEqual (LoaderOptimization.NotSpecified, setup.LoaderOptimization);
  148. p ("LoaderOptimization is: ", setup.LoaderOptimization);
  149. string expected = Path.Combine (Environment.CurrentDirectory, "bin");
  150. Assert.AreEqual (expected, setup.PrivateBinPath, "D9");
  151. Assert.AreEqual (setup.PrivateBinPathProbe, "*", "D10");
  152. p ("ShadowCopyDirs: ", setup.ShadowCopyDirectories);
  153. Assert.AreEqual (true, setup.ShadowCopyDirectories.EndsWith ("bin"), "D11");
  154. Assert.AreEqual (false, setup.ShadowCopyDirectories.StartsWith ("file:"), "D12");
  155. Assert.AreEqual ("true", setup.ShadowCopyFiles, "D13");
  156. p ("ApsInstal", HttpRuntime.AspInstallDirectory);
  157. }
  158. }
  159. }