Mock.Arrange doesn't work in another thread

2 posts, 0 answers
  1. Guanwei
    Guanwei avatar
    1 posts
    Member since:
    Jan 2013

    Posted 14 Feb 2014 Link to this post

    using System;
    using System.Threading.Tasks;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Telerik.JustMock;
     
    namespace JustMockThreadIssue
    {
        public class Helper
        {
            public static void DoSomething()
            {
                Console.WriteLine("DoSomething");
            }
        }
     
        public class Worker
        {
            public void Do()
            {
                Task.Factory.StartNew(DoMyJob);
                //DoMyJob();
            }
     
            private void DoMyJob()
            {
                Helper.DoSomething();
            }
        }
     
        [TestClass]
        public class JustMockThreadIssueTest
        {
            [TestMethod]
            public void Worker_Do()
            {
                var called = false;
                Mock.Arrange(() => Helper.DoSomething()).DoInstead(() => called = true);
     
                var worker = new Worker();
                worker.Do();
                Assert.IsTrue(called);
            }
        }
    }

    I mocked Hepler.DoSomething() method, but if it is called in another thread, Mock.Arrange doesn't work. How can i resolve it?
    JustMock dll version is 2014.1.1317.4.
  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 18 Feb 2014 Link to this post

    Hi Guanwei,

    Thank you for contacting us.

    Unfortunately, this is a limitation in JustMock. The good news is we are working on it in order to have it fixed for the future releases. For more information and a possible workaround, please check this forum thread.

    I hope this helps.

    Regards,
    Kaloyan
    Telerik
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
  3. DevCraft R3 2016 release webinar banner
Back to Top