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.