@@ -4,62 +4,13 @@ namespace Reqnroll.VisualStudio.ReqnrollConnector.Tests;
44
55public class AssemblyLoadingTests
66{
7- private readonly List < Assembly > _assemblies =
8- AssembliesInDir ( "..\\ ..\\ ..\\ ..\\ ..\\ Reqnroll.VisualStudio.Specs\\ bin" , "Spec*.dll" )
9- . Union ( AssembliesInDir ( "." , "Spec*.dll" ) )
10- . Union ( new [ ] { typeof ( AssemblyLoadingTests ) . Assembly } )
11- . ToList ( ) ;
12-
137 private readonly ITestOutputHelper _testOutputHelper ;
148
159 public AssemblyLoadingTests ( ITestOutputHelper testOutputHelper )
1610 {
1711 _testOutputHelper = testOutputHelper ;
1812 }
1913
20- private static IEnumerable < Assembly > AssembliesInDir ( string path , string searchPattern ) =>
21- Directory
22- . EnumerateFiles ( path , searchPattern , SearchOption . AllDirectories )
23- . Select ( Path . GetFullPath )
24- . Select ( TryLoad )
25- . Where ( a => a != null )
26- . Cast < Assembly > ( ) ;
27-
28- private static Assembly ? TryLoad ( string path )
29- {
30- try
31- {
32- return Assembly . LoadFrom ( path ) ;
33- }
34- catch ( Exception )
35- {
36- return null ;
37- }
38- }
39-
40- [ Fact ]
41- public void Load_Assemblies ( )
42- {
43- //act
44- var log = new TestOutputHelperLogger ( _testOutputHelper ) ;
45- var loadContexts = _assemblies . Select ( assembly => new TestAssemblyLoadContext (
46- assembly . Location ,
47- ( assemblyLoadContext , path ) => assemblyLoadContext . LoadFromAssemblyPath ( path ) ,
48- log ) )
49- . ToList ( ) ;
50-
51- var loadedAssemblies = loadContexts
52- . SelectMany ( lc => _assemblies . Select ( a => lc . LoadFromAssemblyName ( a . GetName ( ) ) ) )
53- . ToList ( ) ;
54-
55- //assert
56- loadedAssemblies . Should ( ) . HaveCountGreaterThan ( 1 ) ;
57- loadContexts . Select ( lc => lc . TestAssembly . Location ) . Should ( )
58- . BeEquivalentTo ( _assemblies . Select ( a => a . Location ) , "same dlls are loaded" ) ;
59- loadContexts . Select ( lc => lc . TestAssembly ) . Should ( )
60- . NotBeEquivalentTo ( _assemblies , "assemblies re loaded into different context" ) ;
61- }
62-
6314 [ Fact ]
6415 public void Loads_From_AspNetCoreAssembly ( )
6516 {
0 commit comments