/mcs/class/corlib/Test/System/AppDomainTest.cs
https://bitbucket.org/danipen/mono · C# · 3559 lines · 2988 code · 361 blank · 210 comment · 85 complexity · 46dc4c6e0d9c93802ee7af4c254a5a7e MD5 · raw file
Large files are truncated click here to view the full file
- //
- // AppDomainTest.cs - NUnit Test Cases for AppDomain
- //
- // Author:
- // Sebastien Pouliot (sebastien@ximian.com)
- //
- // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
- // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- #if !MOBILE
- using NUnit.Framework;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Configuration.Assemblies;
- using System.Globalization;
- using System.IO;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Runtime.InteropServices;
- using System.Security;
- using System.Security.Permissions;
- using System.Security.Policy;
- using System.Security.Principal;
- namespace MonoTests.System
- {
- [TestFixture]
- public class AppDomainTest
- {
- private AppDomain ad;
- private ArrayList files = new ArrayList ();
- private string tempDir;
- [SetUp]
- public void SetUp ()
- {
- tempDir = Path.Combine (Path.GetTempPath (), Environment.UserName);
- tempDir = Path.Combine (tempDir, "MonoTests.System.AppDomainTest");
- if (!Directory.Exists (tempDir)) {
- Directory.CreateDirectory (tempDir);
- }
- }
- [TearDown]
- public void TearDown ()
- {
- if (ad != null) {
- try {
- AppDomain.Unload (ad);
- ad = null;
- } catch { } // do not affect unit test results in TearDown
- }
- foreach (string fname in files) {
- File.Delete (fname);
- }
- files.Clear ();
- }
- [Test] // bug #80934
- public void ConfigurationFile_Relative ()
- {
- // Note:
- // We use Environment.GetCommandLineArgs () to get the location of
- // the entry assembly in the default domain (since the default domain
- // is not exposed by any API)
- //
- // MS returns a lower-case path in Environment.GetCommandLineArgs ()
- // and hence we need to perform a case-insensitive comparison
- // if the Assert involves that path
- string configFile = "test.config";
- string appBase = null;
- string expectedConfigFile = null;
- string expectedAppBase = null;
- // do not set ApplicationBase
- appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
- expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
- appBase : appBase + Path.DirectorySeparatorChar;
- expectedConfigFile = Path.Combine (appBase, configFile);
- AppDomainSetup setup = new AppDomainSetup();
- setup.ConfigurationFile = configFile;
- ad = CreateTestDomain (setup, true);
- CrossDomainTester cdt = CreateCrossDomainTester (ad);
- if (RunningOnUnix) {
- Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
- Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
- } else {
- Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
- Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
- }
- AppDomain.Unload (ad);
- // set ApplicationBase
- appBase = Path.GetTempPath ();
- expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
- appBase : appBase + Path.DirectorySeparatorChar;
- expectedConfigFile = Path.Combine (appBase, configFile);
- setup = new AppDomainSetup ();
- setup.ApplicationBase = appBase;
- setup.ConfigurationFile = configFile;
- ad = CreateTestDomain (setup, true);
- cdt = CreateCrossDomainTester (ad);
- Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
- Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
- AppDomain.Unload (ad);
- }
- [Test] // bug #80934
- public void ConfigurationFile_Absolute ()
- {
- // Note:
- // We use Environment.GetCommandLineArgs () to get the location of
- // the entry assembly in the default domain (since the default domain
- // is not exposed by any API)
- //
- // MS returns a lower-case path in Environment.GetCommandLineArgs ()
- // and hence on Windows we need to perform a case-insensitive
- // comparison if the Assert involves that path
- string configFile = Path.Combine (tempDir, "test.config");
- string appBase = null;
- string expectedAppBase = null;
- // do not set ApplicationBase
- appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
- expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
- appBase : appBase + Path.DirectorySeparatorChar;
- AppDomainSetup setup = new AppDomainSetup ();
- setup.ConfigurationFile = configFile;
- ad = CreateTestDomain (setup, true);
- CrossDomainTester cdt = CreateCrossDomainTester (ad);
- Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#A1");
- if (RunningOnUnix) {
- Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
- } else {
- Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
- }
- AppDomain.Unload (ad);
- // set ApplicationBase
- appBase = Path.GetTempPath ();
- expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
- appBase : appBase + Path.DirectorySeparatorChar;
- setup = new AppDomainSetup ();
- setup.ApplicationBase = appBase;
- setup.ConfigurationFile = configFile;
- ad = CreateTestDomain (setup, true);
- cdt = CreateCrossDomainTester (ad);
- Assert.AreEqual (configFile, cdt.GetConfigurationFile (), "#B1");
- Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
- AppDomain.Unload (ad);
- }
- [Test] // bug #80934
- public void ConfigurationFile_Null ()
- {
- // Note:
- // We use Environment.GetCommandLineArgs () to get the location of
- // the entry assembly in the default domain (since the default domain
- // is not exposed by any API)
- //
- // MS returns a lower-case path in Environment.GetCommandLineArgs ()
- // and hence we need to perform a case-insensitive comparison
- // if the Assert involves that path
- string appBase = null;
- string expectedAppBase = null;
- string expectedConfigFile = null;
- // do not set ApplicationBase
- appBase = Path.GetDirectoryName (Environment.GetCommandLineArgs () [0]);
- expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
- appBase : appBase + Path.DirectorySeparatorChar;
- expectedConfigFile = Environment.GetCommandLineArgs () [0] + ".config";
- AppDomainSetup setup = new AppDomainSetup ();
- setup.ConfigurationFile = null;
- ad = CreateTestDomain (setup, true);
- CrossDomainTester cdt = CreateCrossDomainTester (ad);
- if (RunningOnUnix) {
- Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#A1");
- Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#A2");
- } else {
- Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#A1");
- Assert.IsTrue (string.Compare (expectedAppBase, cdt.GetApplicationBase (), true) == 0, "#A2");
- }
- AppDomain.Unload (ad);
- // set ApplicationBase
- appBase = Path.GetTempPath ();
- expectedAppBase = appBase [appBase.Length - 1] == Path.DirectorySeparatorChar ?
- appBase : appBase + Path.DirectorySeparatorChar;
- expectedConfigFile = Path.Combine (appBase, Path.GetFileName (Environment.GetCommandLineArgs () [0]) + ".config");
- setup = new AppDomainSetup ();
- setup.ApplicationBase = appBase;
- setup.ConfigurationFile = null;
- ad = CreateTestDomain (setup, true);
- cdt = CreateCrossDomainTester (ad);
- if (RunningOnUnix) {
- Assert.AreEqual (expectedConfigFile, cdt.GetConfigurationFile (), "#B1");
- } else {
- Assert.IsTrue (string.Compare (expectedConfigFile, cdt.GetConfigurationFile (), true) == 0, "#B1");
- }
- Assert.AreEqual (expectedAppBase, cdt.GetApplicationBase (), "#B2");
- AppDomain.Unload (ad);
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
- public void DefineDynamicAssembly1_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly1";
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
- public void DefineDynamicAssembly1_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess)
- public void DefineDynamicAssembly1_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
- public void DefineDynamicAssembly2_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly2";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- AppDomain.CurrentDomain.Evidence);
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
- public void DefineDynamicAssembly2_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence)
- public void DefineDynamicAssembly2_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
- public void DefineDynamicAssembly3_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly3";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath ());
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath ());
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
- public void DefineDynamicAssembly3_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath ());
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String)
- public void DefineDynamicAssembly3_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath ());
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath ());
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath ());
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
- public void DefineDynamicAssembly4_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly4";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence);
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
- public void DefineDynamicAssembly4_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence)
- public void DefineDynamicAssembly4_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly5_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly5";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly5_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly5_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly6_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly6";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly6_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly6_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly7_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly7";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly7_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly7_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly8_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly8";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly8_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)
- public void DefineDynamicAssembly8_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
- public void DefineDynamicAssembly9_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly9";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true);
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true);
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
- public void DefineDynamicAssembly9_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true);
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'\\'") != -1, "#6:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("':'") != -1, "#7:" + invalid_name);
- Assert.IsNull (ex.ParamName, "#8:" + invalid_name);
- }
- }
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)
- public void DefineDynamicAssembly9_Name_Null ()
- {
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- (AssemblyName) null,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true);
- Assert.Fail ("#A1");
- } catch (ArgumentNullException ex) {
- Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
- Assert.IsNull (ex.InnerException, "#A3");
- Assert.IsNotNull (ex.Message, "#A4");
- Assert.IsNotNull (ex.ParamName, "#A5");
- Assert.AreEqual ("name", ex.ParamName, "#A6");
- }
- AssemblyName name = new AssemblyName ();
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true);
- Assert.Fail ("#B1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
- Assert.IsNull (ex.InnerException, "#B3");
- Assert.IsNotNull (ex.Message, "#B4");
- Assert.IsNull (ex.ParamName, "#B5");
- }
- name.Name = string.Empty;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true);
- Assert.Fail ("#C1");
- } catch (ArgumentException ex) {
- // AssemblyName.Name cannot be null or an empty string
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
- Assert.IsNull (ex.InnerException, "#C3");
- Assert.IsNotNull (ex.Message, "#C4");
- Assert.IsNull (ex.ParamName, "#C5");
- }
- }
- #if NET_2_0
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
- public void DefineDynamicAssembly10_Access_Invalid ()
- {
- AssemblyName name = new AssemblyName ();
- name.Name = "DefineDynamicAssembly10";
- #if NET_2_0
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true,
- new List<CustomAttributeBuilder> ());
- Assert.Fail ("#1");
- } catch (ArgumentException ex) {
- // Illegal enum value: 667
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("667") != -1, "#5");
- Assert.IsNotNull (ex.ParamName, "#6");
- Assert.AreEqual ("access", ex.ParamName, "#7");
- }
- #else
- AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (
- name, AssemblyBuilderAccess.Run |
- (AssemblyBuilderAccess) 666,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true,
- new List<CustomAttributeBuilder> ());
- Assert.IsNotNull (ab, "#1");
- #endif
- }
- [Test] // DefineDynamicAssembly (AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)
- public void DefineDynamicAssembly10_Name_InvalidChars ()
- {
- string [] invalid_char_names = new string [] {
- "\tAB",
- " AB",
- "\rAB",
- "A/B",
- ":AB",
- "B:A",
- "B\\A",
- "BA\\"};
- AssemblyName name = new AssemblyName ();
- foreach (string invalid_name in invalid_char_names) {
- name.Name = invalid_name;
- try {
- AppDomain.CurrentDomain.DefineDynamicAssembly (
- name,
- AssemblyBuilderAccess.Run,
- Path.GetTempPath (),
- AppDomain.CurrentDomain.Evidence,
- (PermissionSet) null,
- (PermissionSet) null,
- (PermissionSet) null,
- true,
- new List<CustomAttributeBuilder> ());
- Assert.Fail ("#1:" + invalid_name);
- } catch (ArgumentException ex) {
- // Assembly names may not begin with whitespace
- // or contain the characters '/', '\' or ':'
- Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2:" + invalid_name);
- Assert.IsNull (ex.InnerException, "#3:" + invalid_name);
- Assert.IsNotNull (ex.Message, "#4:" + invalid_name);
- Assert.IsTrue (ex.Message.IndexOf ("'/'") != -1, "#5:" + invalid_name);…