We have a home-made COM component written in C++. We now want to test its functions and events in a C# Test Project. The function tests are pretty straight-forward. However, the events are never triggered.
MyLib.MyClass m = new MyLib.MyClass();
Assert.IsTrue(m.doStuff()); // Works
// This does not work. OnMyEvent is never called!
m.MyEvent += new MyLib.IMyClassEvents_MyEventHandler(OnMyEvent);
m.triggerEvent();
I've googled this and read about similar issues here on StackOverflow. I've tried all proposed methods but can't get it working!
So far I've tried running my test with an active dispatcher but with no success. I also tried manually pumping messages in the main thread using Dispatcher.PushFrame()
. Nothing. My events never trigger. I created a simple WinForms project and verified that my events work in a normal setup. Hence, this issue only applies to Unit Tests.
Q: How do I make a regular C# Unit Test that can successfully trigger active event handlers?
Somebody out there ought to have a working sample! Please help.