From 649da28140e12b8f8849eae5e3597795f1471c4f Mon Sep 17 00:00:00 2001 From: Arnaud Declercq Date: Thu, 24 Sep 2026 14:02:44 +0100 Subject: [PATCH] Get teh TestRunner to work from local build folder --- TestRunner/Program.cs | 25 ++++++++++++++++++++++++- TestRunner/TestRunner.csproj | 3 --- Test_Engine/Compute/DummyObject.cs | 5 +++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/TestRunner/Program.cs b/TestRunner/Program.cs index 61323463..6440b253 100644 --- a/TestRunner/Program.cs +++ b/TestRunner/Program.cs @@ -27,6 +27,8 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.Loader; using System.Text; using System.Threading.Tasks; using BH.oM.Test; @@ -36,6 +38,25 @@ namespace TestRunner { class Program { + /*************************************/ + /**** Module Initialiser ****/ + /*************************************/ + + // Registered as a module initialiser so it runs before Main is JIT-compiled, i.e. before the runtime + // needs to resolve BHoM/Test_oM types referenced by Main's own locals. This lets TestRunner run + // without bundling its own copies of the BHoM DLLs, always resolving them from the Assemblies folder + // so it tests the actual DLLs used by the BHoM UI rather than a stale local copy. + [ModuleInitializer] + internal static void RegisterAssemblyResolution() + { + AssemblyLoadContext.Default.Resolving += (context, assemblyName) => + { + string path = Path.Combine(m_AssembliesFolder, assemblyName.Name + ".dll"); + return File.Exists(path) ? context.LoadFromAssemblyPath(path) : null; + }; + } + + /*************************************/ /**** Main ****/ /*************************************/ @@ -92,7 +113,7 @@ static void Main(string[] args) static void LoadAllTestAssemblies() { - foreach (string file in Directory.GetFiles(@"C:\ProgramData\BHoM\Assemblies")) + foreach (string file in Directory.GetFiles(m_AssembliesFolder)) { if (file.EndsWith("_Test.dll")) { @@ -136,6 +157,8 @@ static void RegisterTestMethod(MethodInfo method) static Dictionary> m_TestMethods = new Dictionary>(); + static readonly string m_AssembliesFolder = @"C:\ProgramData\BHoM\Assemblies"; + /*************************************/ } } diff --git a/TestRunner/TestRunner.csproj b/TestRunner/TestRunner.csproj index dd91bb58..adac88c5 100644 --- a/TestRunner/TestRunner.csproj +++ b/TestRunner/TestRunner.csproj @@ -32,7 +32,4 @@ - - - diff --git a/Test_Engine/Compute/DummyObject.cs b/Test_Engine/Compute/DummyObject.cs index 34f126cc..2313d851 100644 --- a/Test_Engine/Compute/DummyObject.cs +++ b/Test_Engine/Compute/DummyObject.cs @@ -437,14 +437,15 @@ private static void LinkInterfaces(List types) { if (!type.IsAbstract && !type.IsInterface && !type.IsEnum) { + List propertyTypes = type.GetProperties().Select(x => x.PropertyType).Distinct().ToList(); foreach (Type inter in type.GetInterfaces()) { - if (!m_ImplementingTypes.ContainsKey(inter)) + if (!m_ImplementingTypes.ContainsKey(inter) && !propertyTypes.Contains(inter)) m_ImplementingTypes[inter] = type; } Type baseType = type.BaseType; - if (baseType != null && !m_ImplementingTypes.ContainsKey(baseType)) + if (baseType != null && !m_ImplementingTypes.ContainsKey(baseType) && !propertyTypes.Contains(baseType)) m_ImplementingTypes[baseType] = type; } }