I am trying to test my application that uses Tasks. I have arranged a static method, if I call that method right after arranging it, I get the Mocked return value. But, if I call the method from a task, the method is not mocked.
I am running on version 2011.2.713.2 as my subscription has run out, and since this is a static method, I cannot use the free edition.
I do have JustMock enabled in the VS menu Telerik->JustMock->Enable JustMock
I managed to reproduce the problem with a simple example:
Any help would be great,
Todd
I am running on version 2011.2.713.2 as my subscription has run out, and since this is a static method, I cannot use the free edition.
I do have JustMock enabled in the VS menu Telerik->JustMock->Enable JustMock
I managed to reproduce the problem with a simple example:
using System; using System.Threading; using System.Threading.Tasks; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Telerik.JustMock; namespace TestMockingStatic { public class ClassWithStatic { public static int NumGot = 0; public static int GetANumber(int foo, int bar) { throw new NotImplementedException(); } } [TestClass] public class UnitTest1 { public void GetValue() { Task.Factory.StartNew(() => { ClassWithStatic.NumGot = ClassWithStatic.GetANumber(5, 10); }); } [TestMethod] public void TestMethod1() { Mock.SetupStatic<ClassWithStatic>(Behavior.Strict); Mock.Arrange(() => ClassWithStatic.GetANumber(Arg.AnyInt, Arg.AnyInt)).Returns(42); Assert.AreEqual(42, ClassWithStatic.GetANumber(5, 10), "Mocked Method did not return expected result"); GetValue(); SpinWait.SpinUntil(() => ClassWithStatic.NumGot > 0, 20000); Assert.AreEqual(42, ClassWithStatic.NumGot, "Mocked method called via TASK, did not return correct value"); } } } Any help would be great,
Todd
