Hi All,
I am using Rhino.Inside to run my unit tests and I am not sure why I am getting this error System.EntryPointNotFoundException : Unable to find an entry point named 'Rdk_RenderContent_RdkDocumentRegisteredId' in DLL 'rhcommonrdk_c'.
and how I can respond to it.
The error happens in the second test PurgeMaterials_WhenCalledWithDifferentNumberOfRenderMaterials_ReturnsSpecificString
and at the line where I am creating renderMaterial
This is how my unit test project is setup
I have only two modules in this project:
- TestSetup
- Tests
Here’s my TestSetup
using Microsoft.Win32;
using System;
using System.IO;
using NUnit.Framework;
namespace Space.UnitTests
{
[SetUpFixture]
public class SetupFixture
{
private bool _initialized;
private static string _rhinoDir = "";
private Rhino.Runtime.InProcess.RhinoCore? _rhinoCore;
[OneTimeSetUp]
public void Initialize()
{
//get the correct rhino 7 installation directory
_rhinoDir = Registry.GetValue(
@"HKEY_LOCAL_MACHINE\SOFTWARE\McNeel\Rhinoceros\7.0\Install",
"Path",
null) as string ?? string.Empty;
Assert.IsTrue(Directory.Exists(_rhinoDir), $"Rhino system dir not found: {_rhinoDir}");
// Make sure we are running the tests as 64x
Assert.IsTrue(Environment.Is64BitProcess, "Tests must be run as x64");
if (_initialized)
{
throw new InvalidOperationException("Initialize Rhino.Inside once");
}
RhinoInside.Resolver.Initialize();
_initialized = true;
// Set path to rhino system directory
string envPath = Environment.GetEnvironmentVariable("path")?? String.Empty ;
Environment.SetEnvironmentVariable("path", envPath + ";" + _rhinoDir);
StartRhino();
}
/// <summary>
/// Start a headless Rhino instance using Rhino.Inside
/// </summary>
public void StartRhino()
{
_rhinoCore = new Rhino.Runtime.InProcess.RhinoCore(null,
Rhino.Runtime.InProcess.WindowStyle.NoWindow);
}
[OneTimeTearDown]
public void Cleanup()
{
_rhinoCore?.Dispose();
_rhinoCore = null;
}
}
}
And here’s my tests
using Rhino;
using NUnit.Framework;
using Rhino.DocObjects;
using Rhino.Render;
using Space.Commands;
using Rhino.Geometry;
using Rhino.UI;
namespace Space.UnitTests
{
[TestFixture]
public class SpacePurgeMaterialsTests
{
private RhinoDoc? _doc;
[SetUp]
public void Setup()
{
_doc = RhinoDoc.CreateHeadless(null);
}
[TestCase(0, "No materials found in this file to purge.")]
[TestCase(1, "Purged 1 material from the file.")]
[TestCase(2, "Purged 2 materials from the file.")]
public void PurgeMaterials_WhenCalledWithDifferentNumberOfMaterials_ReturnsSpecificString(
int materialCount, string expected)
{
// Arrange
for (int i = 0; i < materialCount; i++)
{
_doc?.Materials.Add();
}
// Act
string result = SpacePurgeMaterials.PurgeMaterials(_doc);
// Assert
Assert.AreEqual(expected, result);
}
[Test]
public void PurgeMaterials_WhenCalledWithDifferentNumberOfRenderMaterials_ReturnsSpecificString()
{
// Arrange
// Create a new material
var rhinoMaterial = new Material();
// Use the Rhino material to create a Render material
var renderMaterial = RenderMaterial.CreateBasicMaterial(rhinoMaterial, _doc);
_doc.RenderMaterials.Add(renderMaterial);
// Create a box
var box = new Box(Plane.WorldXY, new Interval(-5, 5), new Interval(-5, 5), new Interval(-5, 5));
var id = _doc.Objects.AddBox(box);
// Assign the render material to the box object
var obj = _doc.Objects.FindId(id);
if (obj != null)
{
obj.RenderMaterial = renderMaterial;
obj.CommitChanges();
}
string expected = "Purged 1 material from the file.";
// Act
string result = SpacePurgeMaterials.PurgeMaterials(_doc);
// Assert
Assert.AreEqual(expected, result);
}
[TearDown]
public void TearDown()
{
_doc?.Dispose();
}
}
}