File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1010 <PackageReference Include =" Microsoft.Build" Version =" 16.5.0" >
1111 <ExcludeAssets >runtime</ExcludeAssets >
1212 </PackageReference >
13- <PackageReference Include =" xunit.core" Version =" 2.4.1" />
1413 <PackageReference Include =" xunit.runner.utility" Version =" 2.4.1" />
1514 </ItemGroup >
1615
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Reflection ;
5+ using System . Runtime . CompilerServices ;
46using System . Text ;
57using System . Threading ;
68using TestMyCode . CSharp . Core . Data ;
@@ -34,6 +36,8 @@ public void RunAssemblyTests(Assembly assembly)
3436 using ManualResetEvent testsCompled = new ManualResetEvent ( false ) ;
3537 using AssemblyRunner runner = AssemblyRunner . WithoutAppDomain ( assembly . Location ) ;
3638
39+ AppDomain . CurrentDomain . AssemblyResolve += this . CreateTestAssemblyResolver ( assembly ) ;
40+
3741 runner . OnTestFailed += info =>
3842 {
3943 this . AddTestResult ( MethodTestResult . FromFail ( info ) ) ;
@@ -62,6 +66,25 @@ public void RunAssemblyTests(Assembly assembly)
6266 SpinWait . SpinUntil ( ( ) => runner . Status == AssemblyRunnerStatus . Idle ) ;
6367 }
6468
69+ private ResolveEventHandler CreateTestAssemblyResolver ( Assembly assembly )
70+ {
71+ return ( sender , args ) =>
72+ {
73+ AssemblyName name = new AssemblyName ( args . Name ! ) ;
74+
75+ string assemblyName = $ "{ name . Name } .dll";
76+ string dir = Path . GetDirectoryName ( assembly . Location ) ! ;
77+
78+ string assemblyFile = Path . Combine ( dir , assemblyName ) ;
79+ if ( File . Exists ( assemblyFile ) )
80+ {
81+ return Assembly . LoadFile ( assemblyFile ) ;
82+ }
83+
84+ return null ;
85+ } ;
86+ }
87+
6588 private void AddTestResult ( MethodTestResult result )
6689 {
6790 //We lock here to ensure that we don't have any race conditions
You can’t perform that action at this time.
0 commit comments