public void ShouldResolveTypeFromAbsoluteUriToAssembly() { string assemblyPath = CompilerHelper.GenerateDynamicModule("ModuleInLoadedFromContext1", "Module", ModulesDirectory1 + @"\ModuleInLoadedFromContext1.dll"); var uriBuilder = new UriBuilder { Host = String.Empty, Scheme = Uri.UriSchemeFile, Path = Path.GetFullPath(assemblyPath) }; var assemblyUri = uriBuilder.Uri; using (var resolver = new AssemblyResolver()) { Type resolvedType = Type.GetType( "TestModules.ModuleInLoadedFromContext1Class, ModuleInLoadedFromContext1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); Assert.IsNull(resolvedType); resolver.LoadAssemblyFrom(assemblyUri.ToString()); resolvedType = Type.GetType( "TestModules.ModuleInLoadedFromContext1Class, ModuleInLoadedFromContext1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); Assert.IsNotNull(resolvedType); } }
public void ShouldThrowOnInvalidAssemblyFilePath() { bool exceptionThrown = false; using (var resolver = new AssemblyResolver()) { try { resolver.LoadAssemblyFrom(null); } catch (ArgumentException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); try { resolver.LoadAssemblyFrom("file://InexistentFile.dll"); exceptionThrown = false; } catch (FileNotFoundException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); try { resolver.LoadAssemblyFrom("InvalidUri.dll"); exceptionThrown = false; } catch (ArgumentException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown); } }