Пример #1
0
		public void ModuleScopeCanHandleSignedAndUnsignedInParallel()
		{
			var scope = new ModuleScope();
			Assert.IsNull(scope.StrongNamedModule);
			Assert.IsNull(scope.WeakNamedModule);

			var one = scope.ObtainDynamicModuleWithStrongName();
			Assert.IsNotNull(scope.StrongNamedModule);
			Assert.IsNull(scope.WeakNamedModule);
			Assert.AreSame(one, scope.StrongNamedModule);

			var two = scope.ObtainDynamicModuleWithWeakName();
			Assert.IsNotNull(scope.StrongNamedModule);
			Assert.IsNotNull(scope.WeakNamedModule);
			Assert.AreSame(two, scope.WeakNamedModule);

			Assert.AreNotSame(one, two);
			Assert.AreNotSame(one.Assembly, two.Assembly);

			var three = scope.ObtainDynamicModuleWithStrongName();
			var four = scope.ObtainDynamicModuleWithWeakName();

			Assert.AreSame(one, three);
			Assert.AreSame(two, four);
		}
Пример #2
0
        public void ModuleScopeCanHandleSignedAndUnsignedInParallel()
        {
            var scope = new ModuleScope();

            Assert.IsNull(scope.StrongNamedModule);
            Assert.IsNull(scope.WeakNamedModule);

            var one = scope.ObtainDynamicModuleWithStrongName();

            Assert.IsNotNull(scope.StrongNamedModule);
            Assert.IsNull(scope.WeakNamedModule);
            Assert.AreSame(one, scope.StrongNamedModule);

            var two = scope.ObtainDynamicModuleWithWeakName();

            Assert.IsNotNull(scope.StrongNamedModule);
            Assert.IsNotNull(scope.WeakNamedModule);
            Assert.AreSame(two, scope.WeakNamedModule);

            Assert.AreNotSame(one, two);
            Assert.AreNotSame(one.Assembly, two.Assembly);

            var three = scope.ObtainDynamicModuleWithStrongName();
            var four  = scope.ObtainDynamicModuleWithWeakName();

            Assert.AreSame(one, three);
            Assert.AreSame(two, four);
        }
        public void ModuleScopeDoesntTryToDeleteFromCurrentDirectory()
        {
            string moduleDirectory = Path.Combine(Environment.CurrentDirectory, "GeneratedDlls");

            if (Directory.Exists(moduleDirectory))
            {
                Directory.Delete(moduleDirectory, true);
            }

            string strongModulePath = Path.Combine(moduleDirectory, "Strong.dll");
            string weakModulePath   = Path.Combine(moduleDirectory, "Weak.dll");

            Directory.CreateDirectory(moduleDirectory);
            ModuleScope scope = new ModuleScope(true, "Strong", strongModulePath, "Weak", weakModulePath);

            using (File.Create(Path.Combine(Environment.CurrentDirectory, "Strong.dll")))
            {
                scope.ObtainDynamicModuleWithStrongName();
                scope.SaveAssembly(true);                 // this will throw if SaveAssembly tries to delete from the current directory
            }

            using (File.Create(Path.Combine(Environment.CurrentDirectory, "Weak.dll")))
            {
                scope.ObtainDynamicModuleWithWeakName();
                scope.SaveAssembly(false);                 // this will throw if SaveAssembly tries to delete from the current directory
            }

            // Clean up the generated DLLs because the FileStreams are now closed
            Directory.Delete(moduleDirectory, true);
            File.Delete(Path.Combine(Environment.CurrentDirectory, "Strong.dll"));
            File.Delete(Path.Combine(Environment.CurrentDirectory, "Weak.dll"));
        }
Пример #4
0
        public void SaveWithPath()
        {
            var strongModulePath = Path.GetTempFileName();
            var weakModulePath   = Path.GetTempFileName();

            File.Delete(strongModulePath);
            File.Delete(weakModulePath);

            Assert.IsFalse(File.Exists(strongModulePath));
            Assert.IsFalse(File.Exists(weakModulePath));

            var scope = new ModuleScope(
                true,
                false,
                "Strong",
                strongModulePath,
                "Weak",
                weakModulePath
                );

            scope.ObtainDynamicModuleWithStrongName();
            scope.ObtainDynamicModuleWithWeakName();

            scope.SaveAssembly(true);
            scope.SaveAssembly(false);

            Assert.IsTrue(File.Exists(strongModulePath));
            Assert.IsTrue(File.Exists(weakModulePath));

            File.Delete(strongModulePath);
            File.Delete(weakModulePath);
        }
Пример #5
0
        public void ExplicitSaveThrowsWhenSpecifiedAssemblyNotGeneratedStrongName()
        {
            var scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithWeakName();

            Assert.Throws <InvalidOperationException>(() => scope.SaveAssembly(true));
        }
        public void ExplicitSaveThrowsWhenSpecifiedAssemblyNotGeneratedStrongName()
        {
            ModuleScope scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithWeakName();

            scope.SaveAssembly(true);
        }
        public void GeneratedAssembliesWithCustomName()
        {
            ModuleScope   scope  = new ModuleScope(false, "Strong", "Module1.dll", "Weak", "Module2,dll");
            ModuleBuilder strong = scope.ObtainDynamicModuleWithStrongName();
            ModuleBuilder weak   = scope.ObtainDynamicModuleWithWeakName();

            Assert.AreEqual("Strong", strong.Assembly.GetName().Name);
            Assert.AreEqual("Weak", weak.Assembly.GetName().Name);
        }
Пример #8
0
        public void SaveThrowsWhenMultipleAssembliesGenerated()
        {
            var scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithStrongName();
            scope.ObtainDynamicModuleWithWeakName();

            Assert.Throws <InvalidOperationException>(() => scope.SaveAssembly());
        }
Пример #9
0
        public void SaveWithFlagFalseDoesntThrowsWhenMultipleAssembliesGenerated()
        {
            var scope = new ModuleScope(false);

            scope.ObtainDynamicModuleWithStrongName();
            scope.ObtainDynamicModuleWithWeakName();

            scope.SaveAssembly();
        }
Пример #10
0
        public void GeneratedAssembliesDefaultName()
        {
            var scope  = new ModuleScope();
            var strong = scope.ObtainDynamicModuleWithStrongName();
            var weak   = scope.ObtainDynamicModuleWithWeakName();

            Assert.AreEqual(ModuleScope.DEFAULT_ASSEMBLY_NAME, strong.Assembly.GetName().Name);
            Assert.AreEqual(ModuleScope.DEFAULT_ASSEMBLY_NAME, weak.Assembly.GetName().Name);
        }
        public void SaveThrowsWhenMultipleAssembliesGenerated()
        {
            ModuleScope scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithStrongName();
            scope.ObtainDynamicModuleWithWeakName();

            scope.SaveAssembly();
        }
Пример #12
0
		public void ImplicitModulePaths()
		{
			var scope = new ModuleScope(true);
			Assert.AreEqual(ModuleScope.DEFAULT_FILE_NAME, scope.StrongNamedModuleName);
			Assert.AreEqual(Path.Combine(Directory.GetCurrentDirectory(), ModuleScope.DEFAULT_FILE_NAME),
			                scope.ObtainDynamicModuleWithStrongName().FullyQualifiedName);
			Assert.IsNull(scope.StrongNamedModuleDirectory);

			Assert.AreEqual(ModuleScope.DEFAULT_FILE_NAME, scope.WeakNamedModuleName);
			Assert.AreEqual(Path.Combine(Directory.GetCurrentDirectory(), ModuleScope.DEFAULT_FILE_NAME),
			                scope.ObtainDynamicModuleWithWeakName().FullyQualifiedName);
			Assert.IsNull(scope.WeakNamedModuleDirectory);
		}
        public void ImplicitModulePaths()
        {
            ModuleScope scope = new ModuleScope(true);

            Assert.AreEqual(ModuleScope.DEFAULT_FILE_NAME, scope.StrongNamedModuleName);
            Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, ModuleScope.DEFAULT_FILE_NAME),
                            scope.ObtainDynamicModuleWithStrongName().FullyQualifiedName);
            Assert.IsNull(scope.StrongNamedModuleDirectory);

            Assert.AreEqual(ModuleScope.DEFAULT_FILE_NAME, scope.WeakNamedModuleName);
            Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, ModuleScope.DEFAULT_FILE_NAME),
                            scope.ObtainDynamicModuleWithWeakName().FullyQualifiedName);
            Assert.IsNull(scope.WeakNamedModuleDirectory);
        }
Пример #14
0
        public void ExplicitSaveWorksEvenWhenMultipleAssembliesGenerated()
        {
            var scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithStrongName();
            scope.ObtainDynamicModuleWithWeakName();

            scope.SaveAssembly(true);
            CheckSignedSavedAssembly(ModuleScope.DEFAULT_FILE_NAME);

            scope.SaveAssembly(false);
            CheckUnsignedSavedAssembly(ModuleScope.DEFAULT_FILE_NAME);

            File.Delete(ModuleScope.DEFAULT_FILE_NAME);
        }
Пример #15
0
        public void ExplicitModulePaths()
        {
            var scope = new ModuleScope(
                true,
                false,
                "Strong",
                "StrongModule.dll",
                "Weak",
                "WeakModule.dll"
                );

            Assert.AreEqual("StrongModule.dll", scope.StrongNamedModuleName);
            Assert.AreEqual(
                Path.Combine(Directory.GetCurrentDirectory(), "StrongModule.dll"),
                scope.ObtainDynamicModuleWithStrongName().FullyQualifiedName
                );
            Assert.IsNull(scope.StrongNamedModuleDirectory);

            Assert.AreEqual("WeakModule.dll", scope.WeakNamedModuleName);
            Assert.AreEqual(
                Path.Combine(Directory.GetCurrentDirectory(), "WeakModule.dll"),
                scope.ObtainDynamicModuleWithWeakName().FullyQualifiedName
                );
            Assert.IsNull(scope.WeakNamedModuleDirectory);

            scope = new ModuleScope(
                true,
                false,
                "Strong",
                @"c:\Foo\StrongModule.dll",
                "Weak",
                @"d:\Bar\WeakModule.dll"
                );
            Assert.AreEqual("StrongModule.dll", scope.StrongNamedModuleName);
            Assert.AreEqual(
                @"c:\Foo\StrongModule.dll",
                scope.ObtainDynamicModuleWithStrongName().FullyQualifiedName
                );
            Assert.AreEqual(@"c:\Foo", scope.StrongNamedModuleDirectory);

            Assert.AreEqual("WeakModule.dll", scope.WeakNamedModuleName);
            Assert.AreEqual(
                @"d:\Bar\WeakModule.dll",
                scope.ObtainDynamicModuleWithWeakName().FullyQualifiedName
                );
            Assert.AreEqual(@"d:\Bar", scope.WeakNamedModuleDirectory);
        }
        public void SavedAssemblyHasCacheMappings()
        {
            ModuleScope scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithWeakName();

            string savedPath = scope.SaveAssembly();

            CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args)
            {
                Assembly assembly = Assembly.LoadFrom((string)args[0]);
                Assert.IsTrue(assembly.IsDefined(typeof(CacheMappingsAttribute), false));
            },
                                                     savedPath);

            File.Delete(savedPath);
        }
Пример #17
0
        public void SaveUnsigned()
        {
            var scope = new ModuleScope(true);

            scope.ObtainDynamicModuleWithWeakName();

            var path = ModuleScope.DEFAULT_FILE_NAME;

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Assert.IsFalse(File.Exists(path));
            var savedPath = scope.SaveAssembly();

            Assert.AreEqual(savedPath, Path.GetFullPath(path));

            CheckUnsignedSavedAssembly(path);
            File.Delete(path);
        }
Пример #18
0
		public void SaveWithFlagFalseDoesntThrowsWhenMultipleAssembliesGenerated()
		{
			var scope = new ModuleScope(false);
			scope.ObtainDynamicModuleWithStrongName();
			scope.ObtainDynamicModuleWithWeakName();

			scope.SaveAssembly();
		}
Пример #19
0
		public void ExplicitSaveWorksEvenWhenMultipleAssembliesGenerated()
		{
			var scope = new ModuleScope(true);
			scope.ObtainDynamicModuleWithStrongName();
			scope.ObtainDynamicModuleWithWeakName();

			scope.SaveAssembly(true);
			CheckSignedSavedAssembly(ModuleScope.DEFAULT_FILE_NAME);

			scope.SaveAssembly(false);
			CheckUnsignedSavedAssembly(ModuleScope.DEFAULT_FILE_NAME);

			File.Delete(ModuleScope.DEFAULT_FILE_NAME);
		}
Пример #20
0
		public void SaveThrowsWhenMultipleAssembliesGenerated()
		{
			ModuleScope scope = new ModuleScope(true);
			scope.ObtainDynamicModuleWithStrongName();
			scope.ObtainDynamicModuleWithWeakName();

			scope.SaveAssembly();
		}
Пример #21
0
		public void ModuleScopeDoesntTryToDeleteFromCurrentDirectory()
		{
			var moduleDirectory = Path.Combine(Directory.GetCurrentDirectory(), "GeneratedDlls");
			if (Directory.Exists(moduleDirectory))
				Directory.Delete(moduleDirectory, true);

			var strongModulePath = Path.Combine(moduleDirectory, "Strong.dll");
			var weakModulePath = Path.Combine(moduleDirectory, "Weak.dll");

			Directory.CreateDirectory(moduleDirectory);
			var scope = new ModuleScope(true, false, "Strong", strongModulePath, "Weak", weakModulePath);

			using (File.Create(Path.Combine(Directory.GetCurrentDirectory(), "Strong.dll")))
			{
				scope.ObtainDynamicModuleWithStrongName();
				scope.SaveAssembly(true); // this will throw if SaveAssembly tries to delete from the current directory
			}

			using (File.Create(Path.Combine(Directory.GetCurrentDirectory(), "Weak.dll")))
			{
				scope.ObtainDynamicModuleWithWeakName();
				scope.SaveAssembly(false); // this will throw if SaveAssembly tries to delete from the current directory
			}

			// Clean up the generated DLLs because the FileStreams are now closed
			Directory.Delete(moduleDirectory, true);
			File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "Strong.dll"));
			File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "Weak.dll"));
		}
Пример #22
0
		public void ExplicitSaveThrowsWhenSpecifiedAssemblyNotGeneratedStrongName()
		{
			var scope = new ModuleScope(true);
			scope.ObtainDynamicModuleWithWeakName();

			Assert.Throws<InvalidOperationException>(() => scope.SaveAssembly(true));
		}
Пример #23
0
		public void SavedAssemblyHasCacheMappings()
		{
			var scope = new ModuleScope(true);
			scope.ObtainDynamicModuleWithWeakName();

			var savedPath = scope.SaveAssembly();

			CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args)
			                                         	{
			                                         		var assembly = Assembly.LoadFrom((string) args[0]);
			                                         		Assert.IsTrue(assembly.IsDefined(typeof (CacheMappingsAttribute), false));
			                                         	},
			                                         savedPath);

			File.Delete(savedPath);
		}
Пример #24
0
		public void SaveThrowsWhenMultipleAssembliesGenerated()
		{
			var scope = new ModuleScope(true);
			scope.ObtainDynamicModuleWithStrongName();
			scope.ObtainDynamicModuleWithWeakName();

			Assert.Throws<InvalidOperationException>(() => scope.SaveAssembly());
		}
Пример #25
0
    public void ModuleScopeDoesntTryToDeleteFromCurrentDirectory ()
    {
      string moduleDirectory = Path.Combine (Environment.CurrentDirectory, "GeneratedDlls");
      if (Directory.Exists (moduleDirectory))
        Directory.Delete (moduleDirectory, true);

      string strongModulePath = Path.Combine (moduleDirectory, "Strong.dll");
      string weakModulePath = Path.Combine (moduleDirectory, "Weak.dll");
      
      Directory.CreateDirectory(moduleDirectory);
      ModuleScope scope = new ModuleScope (true, "Strong", strongModulePath, "Weak", weakModulePath);

      using (File.Create (Path.Combine (Environment.CurrentDirectory, "Strong.dll")))
      {
        scope.ObtainDynamicModuleWithStrongName ();
        scope.SaveAssembly (true); // this will throw if SaveAssembly tries to delete from the current directory
      }

      using (File.Create (Path.Combine (Environment.CurrentDirectory, "Weak.dll")))
      {
        scope.ObtainDynamicModuleWithWeakName ();
        scope.SaveAssembly (false);  // this will throw if SaveAssembly tries to delete from the current directory
      }
    }
Пример #26
0
		public void GeneratedAssembliesDefaultName()
		{
			var scope = new ModuleScope();
			var strong = scope.ObtainDynamicModuleWithStrongName();
			var weak = scope.ObtainDynamicModuleWithWeakName();

			Assert.AreEqual(ModuleScope.DEFAULT_ASSEMBLY_NAME, strong.Assembly.GetName().Name);
			Assert.AreEqual(ModuleScope.DEFAULT_ASSEMBLY_NAME, weak.Assembly.GetName().Name);
		}
Пример #27
0
		public void SaveUnsigned()
		{
			var scope = new ModuleScope(true);
			scope.ObtainDynamicModuleWithWeakName();

			var path = ModuleScope.DEFAULT_FILE_NAME;
			if (File.Exists(path))
				File.Delete(path);

			Assert.IsFalse(File.Exists(path));
			var savedPath = scope.SaveAssembly();

			Assert.AreEqual(savedPath, Path.GetFullPath(path));

			CheckUnsignedSavedAssembly(path);
			File.Delete(path);
		}
Пример #28
0
		public void ExplicitSaveThrowsWhenSpecifiedAssemblyNotGeneratedStrongName()
		{
			var scope = new ModuleScope(true);
			scope.ObtainDynamicModuleWithWeakName();

			scope.SaveAssembly(true);
		}
Пример #29
0
		public void SaveWithPath()
		{
			var strongModulePath = Path.GetTempFileName();
			var weakModulePath = Path.GetTempFileName();

			File.Delete(strongModulePath);
			File.Delete(weakModulePath);

			Assert.IsFalse(File.Exists(strongModulePath));
			Assert.IsFalse(File.Exists(weakModulePath));

			var scope = new ModuleScope(true,false, "Strong", strongModulePath, "Weak", weakModulePath);
			scope.ObtainDynamicModuleWithStrongName();
			scope.ObtainDynamicModuleWithWeakName();

			scope.SaveAssembly(true);
			scope.SaveAssembly(false);

			Assert.IsTrue(File.Exists(strongModulePath));
			Assert.IsTrue(File.Exists(weakModulePath));

			File.Delete(strongModulePath);
			File.Delete(weakModulePath);
		}
Пример #30
0
		public void GeneratedAssembliesWithCustomName()
		{
			var scope = new ModuleScope(false,false, "Strong", "Module1.dll", "Weak", "Module2,dll");
			var strong = scope.ObtainDynamicModuleWithStrongName();
			var weak = scope.ObtainDynamicModuleWithWeakName();

			Assert.AreEqual("Strong", strong.Assembly.GetName().Name);
			Assert.AreEqual("Weak", weak.Assembly.GetName().Name);
		}
Пример #31
0
		public void ExplicitModulePaths()
		{
			var scope = new ModuleScope(true, false, "Strong", "StrongModule.dll", "Weak", "WeakModule.dll");
			Assert.AreEqual("StrongModule.dll", scope.StrongNamedModuleName);
			Assert.AreEqual(Path.Combine(Directory.GetCurrentDirectory(), "StrongModule.dll"),
			                scope.ObtainDynamicModuleWithStrongName().FullyQualifiedName);
			Assert.IsNull(scope.StrongNamedModuleDirectory);

			Assert.AreEqual("WeakModule.dll", scope.WeakNamedModuleName);
			Assert.AreEqual(Path.Combine(Directory.GetCurrentDirectory(), "WeakModule.dll"),
			                scope.ObtainDynamicModuleWithWeakName().FullyQualifiedName);
			Assert.IsNull(scope.WeakNamedModuleDirectory);

			scope = new ModuleScope(true, false, "Strong", @"c:\Foo\StrongModule.dll", "Weak", @"d:\Bar\WeakModule.dll");
			Assert.AreEqual("StrongModule.dll", scope.StrongNamedModuleName);
			Assert.AreEqual(@"c:\Foo\StrongModule.dll", scope.ObtainDynamicModuleWithStrongName().FullyQualifiedName);
			Assert.AreEqual(@"c:\Foo", scope.StrongNamedModuleDirectory);

			Assert.AreEqual("WeakModule.dll", scope.WeakNamedModuleName);
			Assert.AreEqual(@"d:\Bar\WeakModule.dll", scope.ObtainDynamicModuleWithWeakName().FullyQualifiedName);
			Assert.AreEqual(@"d:\Bar", scope.WeakNamedModuleDirectory);
		}
Пример #32
0
		public void SaveUnsigned ()
		{
			ModuleScope scope = new ModuleScope (true);
			scope.ObtainDynamicModuleWithWeakName ();

			string path = ModuleScope.DEFAULT_FILE_NAME;
			if (File.Exists (path))
				File.Delete (path);

			Assert.IsFalse (File.Exists (path));
			scope.SaveAssembly ();

			CheckUnsignedSavedAssembly(path);
			File.Delete (path);
		}