mirror of
https://github.com/Smaug123/unofficial-nunit-runner
synced 2025-10-12 20:18:41 +00:00
Split out AppContext and Args to lib (#93)
This commit is contained in:
34
WoofWare.NUnitTestRunner.Lib/AppContext.fs
Normal file
34
WoofWare.NUnitTestRunner.Lib/AppContext.fs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace WoofWare.NUnitTestRunner
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open System.Reflection
|
||||
|
||||
// Fix for https://github.com/Smaug123/unofficial-nunit-runner/issues/8
|
||||
// (This tells the DLL loader to look next to the test DLL for dependencies.)
|
||||
// TODO: do we actually need this when we move to the Hooks world?
|
||||
/// Context manager to set the AppContext.BaseDirectory of the executing DLL.
|
||||
type SetBaseDir (testDll : FileInfo) =
|
||||
let oldBaseDir = AppContext.BaseDirectory
|
||||
|
||||
let setData =
|
||||
let appContext = Type.GetType "System.AppContext"
|
||||
|
||||
if Object.ReferenceEquals (appContext, (null : obj)) then
|
||||
ignore<string * string>
|
||||
else
|
||||
|
||||
let setDataMethod =
|
||||
appContext.GetMethod ("SetData", BindingFlags.Static ||| BindingFlags.Public)
|
||||
|
||||
if Object.ReferenceEquals (setDataMethod, (null : obj)) then
|
||||
ignore<string * string>
|
||||
else
|
||||
|
||||
fun (k, v) -> setDataMethod.Invoke ((null : obj), [| k ; v |]) |> unbox<unit>
|
||||
|
||||
do setData ("APP_CONTEXT_BASE_DIRECTORY", testDll.Directory.FullName)
|
||||
|
||||
interface IDisposable with
|
||||
member _.Dispose () =
|
||||
setData ("APP_CONTEXT_BASE_DIRECTORY", oldBaseDir)
|
Reference in New Issue
Block a user