Progress Telerik JustMock

Mock Threadpool

Nasa, Visa, Microsoft Fox, Samsung, IBM World Bank Group, Volvo
  • 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
Background-NextSteps

Next Steps

See Plans & Pricing

Purchase individual products or any of the bundles

Download Free Trial

With dedicated technical support.