2 // System.Web.Hosting.ApplicationHost.cs
5 // Miguel de Icaza (miguel@novell.com)
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using System.Runtime.Serialization;
32 using System.Web.Hosting;
33 using NUnit.Framework;
36 namespace MonoTests.System.Web.Hosting {
38 public class MBR : MarshalByRefObject {
40 public string GetDomainName ()
42 return AppDomain.CurrentDomain.FriendlyName;
45 public AppDomain GetDomain ()
47 return AppDomain.CurrentDomain;
52 public class MySerializable {
53 public string GetDomainName ()
55 return AppDomain.CurrentDomain.FriendlyName;
60 public class ApplicationHostTest {
67 // Only needed in Windows, where we need to have a bin/ASSEMBLY.DLL
69 string p = typeof (ApplicationHostTest).Assembly.Location;
71 Directory.Delete ("bin", true);
75 Directory.CreateDirectory ("bin");
78 string fn = Path.GetFileName (p);
79 File.Copy (p, Path.Combine ("bin", fn));
83 [TearDown] public void Shutdown ()
86 Directory.Delete ("bin", true);
90 [Test][ExpectedException (typeof (NullReferenceException))]
91 public void ConstructorTestNull ()
93 ApplicationHost.CreateApplicationHost (null, null, null);
97 [ExpectedException (typeof (ArgumentException))]
98 public void ConstructorTestNull2 ()
100 ApplicationHost.CreateApplicationHost (null, "/app", ".");
104 [ExpectedException (typeof (ArgumentNullException))]
105 public void ConstructorTestNull3 ()
107 ApplicationHost.CreateApplicationHost (typeof (MBR), null, ".");
110 [Test][ExpectedException (typeof (NullReferenceException))]
111 public void ConstructorTestNull4 ()
113 ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", null);
117 [ExpectedException(typeof(SerializationException))]
118 #if TARGET_JVM //System.Security.Policy.Evidence not implemented
119 [Category ("NotWorking")]
121 public void Constructor_PlainType ()
123 ApplicationHost.CreateApplicationHost (typeof (ApplicationHostTest), "/app", Environment.CurrentDirectory);
127 public void Constructor_SerializableType ()
129 object o = ApplicationHost.CreateApplicationHost (typeof (MySerializable), "/app", Environment.CurrentDirectory);
130 Assert.AreEqual (typeof (MySerializable), o.GetType (), "C2");
131 MySerializable m = (MySerializable) o;
133 Assert.AreEqual (m.GetDomainName (), AppDomain.CurrentDomain.FriendlyName, "C4");
136 static void p (string s, object x)
138 Console.WriteLine ("{0} {1}", s, x);
142 [Category ("NotDotNet")] // D2 and D3 asserts will fail in windows on because file system environment
143 public void ConstructorTest ()
145 object o = ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", Environment.CurrentDirectory);
146 Assert.AreEqual (typeof (MBR), o.GetType (), "C5");
149 Assert.AreEqual (true, m.GetDomainName () != AppDomain.CurrentDomain.FriendlyName);
151 AppDomain other = m.GetDomain ();
152 AppDomainSetup setup = other.SetupInformation;
154 string tb = Environment.CurrentDirectory;
155 if (tb[tb.Length - 1] == Path.DirectorySeparatorChar)
156 tb = tb.Substring (0, tb.Length - 1);
158 // Need to fix an issue in AppDomainSetup
159 // Assert.AreEqual (tb + "/", setup.ApplicationBase, "D1");
161 p ("AppDomain's Applicationname is: ", setup.ApplicationName);
162 // IGNORE this test. We are setting CachePath to DynamicBase by now.
163 // Assert.AreEqual (null, setup.CachePath, "D2");
165 Assert.AreEqual (0, String.Compare (tb + Path.DirectorySeparatorChar + "Web.Config", setup.ConfigurationFile, StringComparison.OrdinalIgnoreCase), "D3");
166 Assert.AreEqual (false, setup.DisallowBindingRedirects, "D4");
167 Assert.AreEqual (true, setup.DisallowCodeDownload, "D5");
168 Assert.AreEqual (false, setup.DisallowPublisherPolicy, "D6");
169 // Disabling D7 test, as we set it there to avoid locking in sys.web.compilation
170 // Assert.AreEqual (null, setup.DynamicBase, "D7");
171 Assert.AreEqual (null, setup.LicenseFile, "D8");
172 //Assert.AreEqual (LoaderOptimization.NotSpecified, setup.LoaderOptimization);
173 p ("LoaderOptimization is: ", setup.LoaderOptimization);
174 Assert.AreEqual (0, string.Compare (
176 String.Format ("{0}{1}bin", tb, Path.DirectorySeparatorChar),
180 setup.PrivateBinPath, true), "D9"
182 Assert.AreEqual (setup.PrivateBinPathProbe, "*", "D10");
183 p ("ShadowCopyDirs: ", setup.ShadowCopyDirectories);
184 Assert.AreEqual (true, setup.ShadowCopyDirectories.EndsWith ("bin") || setup.ShadowCopyDirectories.EndsWith ("Bin"), "D11");
185 Assert.AreEqual (false, setup.ShadowCopyDirectories.StartsWith ("file:"), "D12");
186 Assert.AreEqual ("true", setup.ShadowCopyFiles, "D13");
188 p ("ApsInstal", HttpRuntime.AspInstallDirectory);