Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion TestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ****/
/*************************************/
Expand Down Expand Up @@ -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"))
{
Expand Down Expand Up @@ -136,6 +157,8 @@ static void RegisterTestMethod(MethodInfo method)

static Dictionary<string, List<MethodInfo>> m_TestMethods = new Dictionary<string, List<MethodInfo>>();

static readonly string m_AssembliesFolder = @"C:\ProgramData\BHoM\Assemblies";

/*************************************/
}
}
Expand Down
3 changes: 0 additions & 3 deletions TestRunner/TestRunner.csproj
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down Expand Up @@ -32,7 +32,4 @@
<ItemGroup>
<ProjectReference Include="..\Test_Engine\Test_Engine.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
</Target>
</Project>
5 changes: 3 additions & 2 deletions Test_Engine/Compute/DummyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
//Returning the bitmap below is causing issues at arbitrary times with the serialisation check. Commenting this out for now and returning null until it can be properly investigated.
//Issue raised for this to be resolved: https://github.com/BHoM/Test_Toolkit/issues/526
return null;
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(20, 20, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

Check warning on line 184 in Test_Engine/Compute/DummyObject.cs

View workflow job for this annotation

GitHub Actions / ci-build

Unreachable code detected

Check warning on line 184 in Test_Engine/Compute/DummyObject.cs

View workflow job for this annotation

GitHub Actions / ci-build

Unreachable code detected

// 2. Get access to the raw bitmap data
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat);
Expand Down Expand Up @@ -437,14 +437,15 @@
{
if (!type.IsAbstract && !type.IsInterface && !type.IsEnum)
{
List<Type> 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;
}
}
Expand Down
Loading