using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;
namespace ClassLibrary1
{
[TestClass]
public class AsyncTests
{
[ClassInitialize]
public static void ClassIntialization(TestContext t)
{
Mock.SetupStatic(typeof(StaticClass), StaticConstructor.Mocked);
Mock.Arrange(() => StaticClass.Get1()).Returns(1);
}
[TestMethod]
public async Task SecondTest()
{
var svc = new TestAsync();
var r = await svc.DoSomethingAsync();
Assert.AreEqual(1, r);
Assert.AreEqual(1, StaticClass.Get1());
}
}
public class TestAsync
{
public Task<int> DoSomethingAsync()
// public int DoSomethingAsync()
{
return Task<int>.Factory.StartNew(() => {
var i = Get();
var j = StaticClass.Get1();
return j;
});
}
public int Get()
{
return 2;
}
}
public static class StaticClass
{
public static int Get1()
{
return 20;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;
namespace ClassLibrary1
{
[TestClass]
public class AsyncTests
{
[ClassInitialize]
public static void ClassIntialization(TestContext t)
{
Mock.SetupStatic(typeof(StaticClass), StaticConstructor.Mocked);
Mock.Arrange(() => StaticClass.Get1()).Returns(1);
}
[TestMethod]
public async Task SecondTest()
{
var svc = new TestAsync();
var r = await svc.DoSomethingAsync();
Assert.AreEqual(1, r);
Assert.AreEqual(1, StaticClass.Get1());
}
}
public class TestAsync
{
public Task<int> DoSomethingAsync()
// public int DoSomethingAsync()
{
return Task<int>.Factory.StartNew(() => {
var i = Get();
var j = StaticClass.Get1();
return j;
});
}
public int Get()
{
return 2;
}
}
public static class StaticClass
{
public static int Get1()
{
return 20;
}
}
}