1

My issue is - I have a class that has a System.Threading.Thread dependancy, and it will Start() the Thread once a certain condition is met. I am having an issue Mocking a System.Threading.Thread.

I generally use Moq for mock objects, but I can't Mock a Thread (because it is sealed).

I do realize I could write some wrapper that contains a Thread, then mock that wrapper - but I would like to avoid that if possible.

Thanks in advance for any ideas!

MattW
  • 12,902
  • 5
  • 38
  • 65

1 Answers1

3

There's been a couple questions already posted attempting to cover this with a good answer, like this one here. For the TLDR; The problem space is really that your taking your code which is asynchronous and trying to adapt it to a mocking framework and unit test, which is synchronous. Long story short, there's not a good solution to this, but if you follow the link I believe there are some shady work-arounds. Good luck

Community
  • 1
  • 1
OnResolve
  • 4,016
  • 3
  • 28
  • 50
  • I really just trying to Mock the actual Thread object - not the asynchronous logic that will end up being called. The real crux of the issue is I want to mock `Thread` to I can call `myTrhead.Start()` – MattW Nov 09 '12 at 15:23