public void TestFixtureSetUp() { var searchPathForDlls = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reflection.AssemblyFinderIntegrationTest.Dlls"); var searchPathForExes = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reflection.AssemblyFinderIntegrationTest.Exes"); var dynamicBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reflection.AssemblyFinderIntegrationTest.Dynamic"); _baseDirectoryBuildOutputManager = CreateAssemblyCompilerBuildOutputManager(AppDomain.CurrentDomain.BaseDirectory); _dynamicDirectoryBuildOutputManager = CreateAssemblyCompilerBuildOutputManager(dynamicBase); _searchPathForDllsBuildOutputManager = CreateAssemblyCompilerBuildOutputManager(searchPathForDlls); _searchPathForExesBuildOutputManager = CreateAssemblyCompilerBuildOutputManager(searchPathForExes); _markedReferencedAssemblyPath = _baseDirectoryBuildOutputManager.CompileInSeparateAppDomain("MarkedReferencedAssembly.dll"); _markedAssemblyPath = _baseDirectoryBuildOutputManager.CompileInSeparateAppDomain("MarkedAssembly.dll", _markedReferencedAssemblyPath); _markedExeAssemblyPath = _baseDirectoryBuildOutputManager.CompileInSeparateAppDomain("MarkedExeAssembly.dll"); _markedAssemblyWithDerivedAttributePath = _baseDirectoryBuildOutputManager.CompileInSeparateAppDomain("MarkedAssemblyWithDerivedAttribute.dll"); _baseDirectoryBuildOutputManager.CompileInSeparateAppDomain("UnmarkedAssembly.dll"); _markedAssemblyInSearchPathPath = _searchPathForDllsBuildOutputManager.CompileInSeparateAppDomain("MarkedAssemblyInRelativeSearchPath.dll"); _markedExeAssemblyInSearchPathPath = _searchPathForExesBuildOutputManager.CompileInSeparateAppDomain("MarkedExeAssemblyInRelativeSearchPath.exe"); _markedAssemblyInSearchPathWithNameMismatchPath = _searchPathForDllsBuildOutputManager.CompileInSeparateAppDomain("MarkedAssemblyWithOtherFilenameInRelativeSearchPath.dll"); _markedAssemblyInSearchPathWithNameMismatchPath = _searchPathForDllsBuildOutputManager.RenameGeneratedAssembly( "MarkedAssemblyWithOtherFilenameInRelativeSearchPath.dll", "_MarkedAssemblyWithOtherFilenameInRelativeSearchPath.dll"); _markedAssemblyInDynamicDirectoryPath = _dynamicDirectoryBuildOutputManager.CompileInSeparateAppDomain("MarkedAssemblyInDynamicDirectory.dll"); _markedExeAssemblyInDynamicDirectoryPath = _dynamicDirectoryBuildOutputManager.CompileInSeparateAppDomain( "MarkedExeAssemblyInDynamicDirectory.exe"); }
private static Assembly CompileReferencingAssembly(AssemblyCompilerBuildOutputManager outputManager, Assembly remotionAssembly) { var referencingAssemblyRelativePath = outputManager.CompileInSeparateAppDomain("RemotionCoreReferencingAssembly.dll", remotionAssembly.Location); var referencingAssemblyFullPath = Path.GetFullPath(referencingAssemblyRelativePath); return(Assembly.LoadFile(referencingAssemblyFullPath)); }
public void FindAssemblies_FindsReferencedAssemblies_Transitive() { const string buildOutputDirectory = "Reflection.AssemblyFinderTest.FindAssemblies_FindsReferencedAssemblies_Transitive"; const string sourceDirectoryRoot = @"Reflection\TypeDiscovery\AssemblyFinding\TestAssemblies\AssemblyFinderTest"; Action <object[]> testAction = delegate(object[] args) { var outputManagerWithoutClosure = (AssemblyCompilerBuildOutputManager)args[0]; // dependency chain: mixinSamples -> remotion -> log4net var log4NetAssembly = typeof(log4net.LogManager).Assembly; var remotionAssembly = typeof(AssemblyFinder).Assembly; var referencingAssembly = CompileReferencingAssembly(outputManagerWithoutClosure, remotionAssembly); var loaderMock = MockRepository.GenerateMock <IAssemblyLoader>(); loaderMock .Expect(mock => mock.TryLoadAssembly(ArgReferenceMatchesDefinition(remotionAssembly), Arg.Is(referencingAssembly.FullName))) // load re-motion via samples .Return(remotionAssembly); loaderMock .Expect(mock => mock.TryLoadAssembly(ArgReferenceMatchesDefinition(log4NetAssembly), Arg.Is(remotionAssembly.FullName))) // load log4net via re-motion .Return(log4NetAssembly); loaderMock.Replay(); var rootAssemblyFinderStub = MockRepository.GenerateMock <IRootAssemblyFinder>(); rootAssemblyFinderStub.Stub(stub => stub.FindRootAssemblies()).Return( new[] { new RootAssembly(referencingAssembly, true) }); rootAssemblyFinderStub.Replay(); var finder = new AssemblyFinder(rootAssemblyFinderStub, loaderMock); var result = finder.FindAssemblies(); loaderMock.VerifyAllExpectations(); Assert.That(result, Is.EquivalentTo(new[] { referencingAssembly, remotionAssembly, log4NetAssembly })); }; // Run test action in separate AppDomain using (var outputManager = new AssemblyCompilerBuildOutputManager(buildOutputDirectory, true, sourceDirectoryRoot)) { AppDomainRunner.Run(testAction, outputManager); } }