2 // AppDomainSetupTest.cs - NUnit Test Cases for the System.AppDomainSetup class
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2003 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
12 using NUnit.Framework;
16 namespace MonoTests.System
19 public class AppDomainSetupTest {
21 static readonly string tmpPath = Path.GetTempPath ();
22 static readonly string curDir = Directory.GetCurrentDirectory ();
24 private bool RunningOnWindows {
26 int os = (int)Environment.OSVersion.Platform;
36 public void ConfigurationFile_Relative_ApplicationBase ()
38 string fileName = "blar.config";
39 AppDomainSetup setup = new AppDomainSetup();
40 string dir = "app_base";
41 setup.ApplicationBase = dir;
42 setup.ConfigurationFile = fileName;
43 string baseDir = Path.GetFullPath(dir);
44 string configFile = Path.Combine(baseDir, fileName);
45 Assert.AreEqual(configFile, setup.ConfigurationFile, "Check relative to ApplicationBase");
49 public void ConfigurationFile_Null ()
51 AppDomainSetup setup = new AppDomainSetup();
52 Assert.IsNull(setup.ConfigurationFile);
56 [ExpectedException (typeof (MemberAccessException))] // The ApplicationBase must be set before retrieving this property
57 public void ConfigurationFile_Relative_NoApplicationBase ()
59 AppDomainSetup setup = new AppDomainSetup();
60 setup.ConfigurationFile = "blar.config";
61 string configFile = setup.ConfigurationFile;
62 if (configFile == null) {
63 // avoid compiler warning
68 public void ConfigurationFile_Absolute_NoApplicationBase ()
70 AppDomainSetup setup = new AppDomainSetup();
71 string configFile = Path.GetFullPath("blar.config");
72 setup.ConfigurationFile = configFile;
73 Assert.AreEqual(configFile, setup.ConfigurationFile);
77 public void ApplicationBase1 ()
79 string expected_path = tmpPath.Replace(@"\", @"/");
80 AppDomainSetup setup = new AppDomainSetup ();
81 string fileUri = "file://" + expected_path;
82 setup.ApplicationBase = fileUri;
83 // with MS 1.1 SP1 the expected_path starts with "//" but this make
84 // sense only under Windows (i.e. reversed \\ for local files)
86 expected_path = "//" + expected_path;
89 // under 2.0 the NotSupportedException is throw when getting
90 // (and not setting) the ApplicationBase property
91 Assert.AreEqual (expected_path, setup.ApplicationBase);
93 catch (NotSupportedException) {
94 // however the path is invalid only on Windows
95 if (!RunningOnWindows)
99 Assert.AreEqual (expected_path, setup.ApplicationBase);
104 public void ApplicationBase2 ()
106 AppDomainSetup setup = new AppDomainSetup ();
107 setup.ApplicationBase = curDir;
108 Assert.AreEqual (curDir, setup.ApplicationBase);
112 public void ApplicationBase3 ()
114 AppDomainSetup setup = new AppDomainSetup ();
115 string expected = Path.Combine (Environment.CurrentDirectory, "lalala");
116 setup.ApplicationBase = "lalala";
117 Assert.AreEqual (expected, setup.ApplicationBase);
121 public void ApplicationBase4 ()
123 AppDomainSetup setup = new AppDomainSetup ();
124 setup.ApplicationBase = "lala:la";
127 // under 2.0 the NotSupportedException is throw when getting
128 // (and not setting) the ApplicationBase property
129 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
131 catch (NotSupportedException) {
132 // however the path is invalid only on Windows
133 // (same exceptions as Path.GetFullPath)
134 if (!RunningOnWindows)
138 // under 1.x a "bad" path containing ":" will be returned "as-is"
139 // but the name is legal for linux so we return a full path
140 if (RunningOnWindows)
141 Assert.AreEqual ("lala:la", setup.ApplicationBase);
143 Assert.AreEqual (Path.GetFullPath ("lala:la"), setup.ApplicationBase);
148 public void ApplicationBase5 ()
150 // This is failing because of (probably) a windows-ism, so don't worry
151 AppDomainSetup setup = new AppDomainSetup ();
152 setup.ApplicationBase = "file:///lala:la";
155 // under 2.0 the NotSupportedException is throw when getting
156 // (and not setting) the ApplicationBase property
157 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
159 catch (NotSupportedException) {
160 // however the path is invalid only on Windows
161 // (same exceptions as Path.GetFullPath)
162 if (!RunningOnWindows)
166 // under 1.x a "bad" path containing ":" will be returned "as-is"
167 // but the name is legal for linux so we return a full path
168 if (RunningOnWindows)
169 Assert.AreEqual ("lala:la", setup.ApplicationBase);
171 Assert.AreEqual ("/lala:la", setup.ApplicationBase);
176 public void ApplicationBase6 ()
178 AppDomainSetup setup = new AppDomainSetup ();
179 setup.ApplicationBase = "la?lala";
180 // paths containing "?" are *always* bad on Windows
181 // but are legal for linux so we return a full path
182 if (RunningOnWindows) {
184 // ArgumentException is throw when getting
185 // (and not setting) the ApplicationBase property
186 Assert.Fail ("setup.ApplicationBase returned :" + setup.ApplicationBase);
188 catch (ArgumentException) {
190 catch (Exception e) {
191 Assert.Fail ("Unexpected exception: " + e.ToString ());
194 Assert.AreEqual (Path.GetFullPath ("la?lala"), setup.ApplicationBase);