background

Telerik JustMock

Mock Threadpool

  • With JustMock, you could mock every required member with ease and test your code in isolation from its dependencies.
  • Part of the fastest, most flexible and complete mocking tool for crafting unit tests.
  • Our award-winning support team is available to assist you with any issues.
Mock everything
  • Mocking Threadpool Overview

    Threadpool is a class that provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I/O, wait on behalf of other threads and process timers.

    With JustMock, you could mock every required member with ease and test your code in isolation from its dependencies.

    [TestMethod]
    public void ShouldInvokeMockInsideAChildThreadFromThreadPool()
    {
        var mockable = Mock.Create<Mockable>();
        Mock.Arrange(() => mockable.IsMocked).Returns(true);
      
        bool mocked = false;
      
        var latch = new WaitLatch();
      
        ThreadPool.QueueUserWorkItem((cookie) =>
        {
            try
            {
                mocked = mockable.IsMocked;
            }
            finally
            {
                latch.Signal();
            }
        });
      
        latch.Wait();
      
        Assert.IsTrue(mocked);
    }

    Mock Threadpool documentation
Next Steps