public void when_type_load_exception() { var directory = MakeTempDirForTest(); Action <string> testMethod1 = directoryPath => { var interfaceAssemblyPath = Path.Combine(directoryPath, "IDoSomething.dll"); var interfaceAssembly = GenerateAssembly(@"public interface IDoSomething : IInterface { }", interfaceAssemblyPath); var concreteAssemblyPath = Path.Combine(directoryPath, "DoNothing.dll"); GenerateAssembly(@"public class DoNothing : IDoSomething { }", concreteAssemblyPath, additionalAssemblyReferences: new[] { interfaceAssembly }); }; AppDomainExtensions.IsolateMethodInAppDomain(testMethod1, directory.FullName); Action <string> testMethod2 = directoryPath => { // Add a method to IDoSomething so that our DoNothing class is no longer a valid implementation and will throw a TypeLoadException when loaded var interfaceAssemblyPath = Path.Combine(directoryPath, "IDoSomething.dll"); GenerateAssembly(@"public interface IDoSomething : IInterface { void DoSomething(); }", interfaceAssemblyPath); var files = Directory.GetFiles(directoryPath); var result = TypeInstantiator.ExportedInstancesFromAssemblyPaths <IInterface>(files); Assert.AreEqual(0, result.Instances.Count()); Assert.AreEqual(1, result.Exceptions.Count()); }; AppDomainExtensions.IsolateMethodInAppDomain(testMethod2, directory.FullName); directory.Delete(true); }
public void when_invalid_file_on_disk() { var directory = MakeTempDirForTest(); Action <string> testMethod = directoryPath => { var filePath1 = Path.Combine(directoryPath, "foo.dll"); File.CreateText(filePath1); var result = TypeInstantiator.ExportedInstancesFromAssemblyPaths <IInterface>(filePath1); Assert.AreEqual(0, result.Instances.Count()); Assert.AreEqual(0, result.Exceptions.Count()); }; AppDomainExtensions.IsolateMethodInAppDomain(testMethod, directory.FullName); directory.Delete(true); }
public void when_finds_files_on_disk() { var directory = MakeTempDirForTest(); Action <string> testMethod = directoryPath => { var filePath1 = Path.Combine(directoryPath, "foo.dll"); var filePath2 = Path.Combine(directoryPath, "bar.dll"); GenerateAssembly(@"public class Foo : IInterface {}", filePath1); GenerateAssembly(@"public class Bar : IInterface {}", filePath2); var result = TypeInstantiator.ExportedInstancesFromAssemblyPaths <IInterface>(filePath1, filePath2); Assert.AreEqual(2, result.Instances.Count()); Assert.AreEqual(0, result.Exceptions.Count()); }; AppDomainExtensions.IsolateMethodInAppDomain(testMethod, directory.FullName); directory.Delete(true); }