Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / System.Web / Test / System.Web.Hosting / ApplicationHostTest.cs
1 //
2 // System.Web.Hosting.ApplicationHost.cs 
3 // 
4 // Author:
5 //      Miguel de Icaza (miguel@novell.com)
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
36 namespace MonoTests.System.Web.Hosting {
37
38         public class MBR : MarshalByRefObject {
39
40                 public string GetDomainName ()
41                 {
42                         return AppDomain.CurrentDomain.FriendlyName;
43                 }
44
45                 public AppDomain GetDomain ()
46                 {
47                         return AppDomain.CurrentDomain;
48                 }
49         }
50
51         [Serializable]
52         public class MySerializable {
53                 public string GetDomainName ()
54                 {
55                         return AppDomain.CurrentDomain.FriendlyName;
56                 }
57         }
58         
59         [TestFixture]
60         public class ApplicationHostTest {
61
62                 [SetUp] 
63                 public void Setup ()
64                 {
65                         try {
66                                 //
67                                 // Only needed in Windows, where we need to have a bin/ASSEMBLY.DLL
68                                 //
69                                 string p = typeof (ApplicationHostTest).Assembly.Location;
70                                 try {
71                                         Directory.Delete ("bin", true);
72                                 } catch {}
73
74                                 try {
75                                         Directory.CreateDirectory ("bin");
76                                 } catch {}
77
78                                 string fn = Path.GetFileName (p);
79                                 File.Copy (p, Path.Combine ("bin", fn));
80                         } catch {}
81                 }
82
83                 [TearDown] public void Shutdown ()
84                 {
85                         try {
86                                 Directory.Delete ("bin", true);
87                         } catch {}
88                 }
89                 
90                 [Test][ExpectedException (typeof (NullReferenceException))]
91                 public void ConstructorTestNull ()
92                 {
93                         ApplicationHost.CreateApplicationHost (null, null, null);
94                 }
95
96                 [Test]
97         [ExpectedException (typeof (ArgumentException))]
98                 public void ConstructorTestNull2 ()
99                 {
100                         ApplicationHost.CreateApplicationHost (null, "/app", ".");
101                 }
102
103                 [Test]
104         [ExpectedException (typeof (ArgumentNullException))]
105                 public void ConstructorTestNull3 ()
106                 {
107                         ApplicationHost.CreateApplicationHost (typeof (MBR), null, ".");
108                 }
109
110                 [Test][ExpectedException (typeof (NullReferenceException))]
111                 public void ConstructorTestNull4 ()
112                 {
113                         ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", null);
114                 }
115
116                 [Test]
117                 [ExpectedException(typeof(SerializationException))]
118                 public void Constructor_PlainType ()
119                 {
120                         ApplicationHost.CreateApplicationHost (typeof (ApplicationHostTest), "/app", Environment.CurrentDirectory);
121                 }
122
123                 [Test]
124                 public void Constructor_SerializableType ()
125                 {
126                         object o = ApplicationHost.CreateApplicationHost (typeof (MySerializable), "/app", Environment.CurrentDirectory);
127                         Assert.AreEqual (typeof (MySerializable), o.GetType (), "C2");
128                         MySerializable m = (MySerializable) o;
129
130                         Assert.AreEqual (m.GetDomainName (), AppDomain.CurrentDomain.FriendlyName, "C4");
131                 }
132
133                 static void p (string s, object x)
134                 {
135                         Console.WriteLine ("{0} {1}", s, x);
136                 }
137                 
138                 [Test]
139                 [Category ("NotDotNet")] // D2 and D3 asserts will fail in windows on because file system environment 
140                 public void ConstructorTest ()
141                 {
142                         object o = ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", Environment.CurrentDirectory);
143                         Assert.AreEqual (typeof (MBR), o.GetType (), "C5");
144                         MBR m = (MBR) o;
145
146                         Assert.AreEqual (true, m.GetDomainName () != AppDomain.CurrentDomain.FriendlyName);
147
148                         AppDomain other = m.GetDomain ();
149                         AppDomainSetup setup = other.SetupInformation;
150
151                         string tb = Environment.CurrentDirectory;
152                         if (tb[tb.Length - 1] == Path.DirectorySeparatorChar)
153                                 tb = tb.Substring (0, tb.Length - 1);
154
155                         // Need to fix an issue in AppDomainSetup
156                         // Assert.AreEqual (tb + "/", setup.ApplicationBase, "D1");
157                         
158                         p ("AppDomain's Applicationname is: ", setup.ApplicationName);
159                         // IGNORE this test. We are setting CachePath to DynamicBase by now.
160                         // Assert.AreEqual (null, setup.CachePath, "D2");
161
162                         Assert.AreEqual (0, String.Compare (tb + Path.DirectorySeparatorChar + "Web.Config", setup.ConfigurationFile, StringComparison.OrdinalIgnoreCase), "D3");
163                         Assert.AreEqual (false, setup.DisallowBindingRedirects, "D4");
164                         Assert.AreEqual (true, setup.DisallowCodeDownload, "D5");
165                         Assert.AreEqual (false, setup.DisallowPublisherPolicy, "D6");
166                         // Disabling D7 test, as we set it there to avoid locking in sys.web.compilation
167                         // Assert.AreEqual (null, setup.DynamicBase, "D7");
168                         Assert.AreEqual (null, setup.LicenseFile, "D8");
169                         //Assert.AreEqual (LoaderOptimization.NotSpecified, setup.LoaderOptimization);
170                         p ("LoaderOptimization is: ", setup.LoaderOptimization);
171                         Assert.AreEqual (0, string.Compare (
172                                 String.Format ("{0}{1}bin", tb, Path.DirectorySeparatorChar),
173                                 setup.PrivateBinPath, true), "D9"
174                         );
175                         Assert.AreEqual (setup.PrivateBinPathProbe, "*", "D10");
176                         p ("ShadowCopyDirs: ", setup.ShadowCopyDirectories);
177                         Assert.AreEqual (true, setup.ShadowCopyDirectories.EndsWith ("bin") || setup.ShadowCopyDirectories.EndsWith ("Bin"), "D11");
178                         Assert.AreEqual (false, setup.ShadowCopyDirectories.StartsWith ("file:"), "D12");
179                         Assert.AreEqual ("true", setup.ShadowCopyFiles, "D13");
180
181                         p ("ApsInstal", HttpRuntime.AspInstallDirectory);
182                 }
183         }
184         
185 }