This is a migrated thread and some comments may be shown as answers.

Mock.Arrange doesn't work in another thread

1 Answer 147 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Guanwei
Top achievements
Rank 1
Guanwei asked on 14 Feb 2014, 07:23 AM
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.

1 Answer, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 18 Feb 2014, 02:44 PM
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.
Tags
General Discussions
Asked by
Guanwei
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or