// AssemblyNameTest.cs - NUnit Test Cases for AssemblyName
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
+using System.Runtime.Serialization;
using System.Threading;
using System.Globalization;
using System.Runtime.Serialization.Formatters.Binary;
static byte[] token = { 0xFF, 0xEF, 0x94, 0x53, 0x67, 0x69, 0xDA, 0x06 };
[SetUp]
- protected void SetUp () {
+ public void SetUp ()
+ {
try {
if (Directory.Exists (tempDir))
Directory.Delete (tempDir, true);
}
[TearDown]
- protected void TearDown () {
+ public void TearDown ()
+ {
try {
if (Directory.Exists (tempDir))
Directory.Delete (tempDir, true);
}
}
- public void TestEmptyAssembly ()
+ [Test]
+ public void EmptyAssembly ()
{
an = new AssemblyName ();
Assert.IsNull (an.CodeBase, "CodeBase");
an.VersionCompatibility, "VersionCompatibility");
}
- public void TestPublicKey ()
+ [Test]
+ public void PublicKey ()
{
an = new AssemblyName ();
Assert.IsNull (an.GetPublicKey (), "PublicKey(empty)");
AssertEqualsByteArrays ("PublicKeyToken", token, an.GetPublicKeyToken ());
}
- public void TestPublicKeyToken ()
+ [Test]
+ public void PublicKeyToken ()
{
an = new AssemblyName ();
an.SetPublicKeyToken (token);
AssertEqualsByteArrays ("PublicKeyToken", token, an.GetPublicKeyToken ());
}
- public void TestKeyPair ()
+ [Test]
+ public void KeyPair ()
{
an = new AssemblyName ();
an.KeyPair = new StrongNameKeyPair (publicKey);
}
// !!! this assembly MUST NOT use a StrongName !!!
- public void TestSelf ()
+ [Test]
+ public void Self ()
{
Assembly a = Assembly.GetExecutingAssembly ();
AssemblyName an = a.GetName ();
}
[Test]
- public void TestFullName1 ()
+ public void FullName1 ()
{
// !!! we assume the mscorlib has a strong name !!!
AssemblyName an = typeof(int).Assembly.GetName ();
}
[Test]
- public void TestFullName2 ()
+ public void FullName2 ()
{
const string assemblyName = "TestAssembly";
}
[Test]
- public void TestFullName3 ()
+ public void FullName3 ()
{
const string assemblyName = "TestAssembly";
const string assemblyVersion = "1.2";
}
[Test]
- public void TestFullName4 ()
+ public void FullName4 ()
{
const string assemblyName = "TestAssembly";
}
[Test]
- public void TestFullName5 ()
+ public void FullName5 ()
{
const string assemblyName = "TestAssembly";
}
[Test]
- public void TestFullName6 ()
+ public void FullName6 ()
{
const string assemblyName = "TestAssembly";
const string assemblyVersion = "1.2";
}
[Test]
- public void TestFullName7 ()
+ public void FullName7 ()
{
const string assemblyName = "TestAssembly";
const string assemblyVersion = "1.2";
}
[Test]
- public void TestFullName8 ()
+ public void FullName8 ()
{
const string assemblyName = "TestAssembly";
static int nameIndex = 0;
- private AssemblyName GenAssemblyName () {
+ private AssemblyName GenAssemblyName ()
+ {
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "MonoTests.System.Reflection.AssemblyNameTest" + (nameIndex ++);
return assemblyName;
}
- private Assembly GenerateAssembly (AssemblyName name) {
+ private Assembly GenerateAssembly (AssemblyName name)
+ {
AssemblyBuilder ab = domain.DefineDynamicAssembly (
name,
AssemblyBuilderAccess.RunAndSave,
return Assembly.LoadFrom (Path.Combine (tempDir, name.Name + ".dll"));
}
+ [Test]
public void TestCultureInfo ()
{
AssemblyName name = GenAssemblyName ();
Assert.AreEqual (a.GetName ().CultureInfo.Name, "ar-DZ");
}
- public void TestVersion ()
+ [Test]
+ public void Version ()
{
AssemblyName name = GenAssemblyName ();
name.Version = new Version (1, 2, 3, 4);
Assert.AreEqual ("1.2.0.0", a.GetName ().Version.ToString ());
}
- public void TestHashAlgorithm ()
+ [Test]
+ public void HashAlgorithm ()
{
Assert.AreEqual (AssemblyHashAlgorithm.SHA1,
typeof (int).Assembly.GetName ().HashAlgorithm);
}
- public void TestSerialization ()
+ [Test]
+ public void Serialization ()
{
AssemblyName an = new AssemblyName ();
an.CodeBase = "http://www.test.com/test.dll";
AssertEqualsByteArrays ("PublicToken", an.GetPublicKeyToken (), dsAssemblyName.GetPublicKeyToken ());
}
-
- private AssemblyName GetAssemblyName (string assemblyFile)
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void GetObjectData_Null ()
{
- Assembly a = Assembly.LoadFrom (assemblyFile);
- return a.GetName ();
- }
+ AssemblyName an = new AssemblyName ();
+ an.GetObjectData (null, new StreamingContext (StreamingContextStates.All));\r
+ }\r
+
+ // helpers
private string GetTokenString (byte[] value)
{
}
return tokenString;
}
-
- public void TestStatic ()
- {
- /*an = GetAssemblyName ("System.Reflection.dll");*/
- }
}
}
public class ModuleCas {
private MonoTests.System.Reflection.ModuleTest mt;
+ private Module main;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
mt = new MonoTests.System.Reflection.ModuleTest ();
+ main = typeof (int).Module;
}
[SetUp]
mt.TearDown ();
}
- // Partial Trust Tests - i.e. call "normal" unit with reduced privileges
+ // Partial Trust Tests
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void PartialTrust_DenyUnrestricted ()
{
+ // call "normal" unit with reduced privileges
mt.FindTypes ();
#if NET_2_0
mt.ResolveType ();
mt.ResolveField ();
mt.ResolveMember ();
#endif
+ // properties
+ Assert.IsNotNull (main.Assembly, "Assembly");
+ Assert.IsNotNull (main.ScopeName, "ScopeName");
+
+ // methods (incomplete)
+ Assert.IsNotNull (main.ToString (), "ToString");
+ }
+
+ [Test]
+ [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
+ [ExpectedException (typeof (SecurityException))]
+ public void FullyQualifiedName_Deny_FileIOPermission ()
+ {
+ Assert.IsNotNull (main.FullyQualifiedName, "FullyQualifiedName");
+ }
+
+ [Test]
+ [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
+ public void FullyQualifiedName_PermitOnly_FileIOPermission ()
+ {
+ Assert.IsNotNull (main.FullyQualifiedName, "FullyQualifiedName");
+ }
+
+ // Note: we do not ask for PathDiscovery because no path is returned here.
+ // However MS Fx requires it (see FDBK23572 for details).
+ [Category ("NotWorking")] // on purpose ;-)
+ [Test]
+ [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
+ [ExpectedException (typeof (SecurityException))]
+ public void Name_Deny_FileIOPermission ()
+ {
+ Assert.IsNotNull (main.Name, "Name");
+ }
+
+ [Test]
+ [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
+ public void Name_PermitOnly_FileIOPermission ()
+ {
+ Assert.IsNotNull (main.Name, "Name");
}
// we use reflection to call Module as the GetObjectData method is protected