❔ Unit Test | Mocking class with unsafe methods
Hi, I am having trouble writing unit tests, because I dont know how to mock/setup the underlying instance/its methods.
The class
Silk.NET.OpenCL.CL
(https://github.com/dotnet/Silk.NET/blob/main/src/OpenCL/Silk.NET.OpenCL/CL.gen.cs) does not implement an interface and the methods are unsafe and non virtual.
This would be one of the methods I need to mock:
(instead of out uint num_platforms
I could also use uint* num_platforms
, if that matters)
I tried using Moq, but I run into errors for the null pointer and count parameter:
CS1944: An expression tree may not contain an unsafe pointer operation CS8198: An expression tree may not contain an out argument variable declaration( I tried also other libraries like Pose, but they all use
System.Linq.Expressions.Expression
so I always ran into the same errors)
Any idea how to do that?3 Replies
Use some non-unsafe helper method to do that, and use that one in the test expression?
I would like to write a test for this method:
guess that would mean i would have to use the mentioned non-unsafe helper method in
GetPlatforms()
then as well right?Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.