using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Falcon.SugarApi.Test
{
///
/// 任务防抖测试
///
[TestClass()]
public class ShakingTests
{
///
/// 任务防抖测试
///
[TestMethod()]
public void RunTest() {
var showMsg = () => Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")} show message!");
var reMsg = () => $"{DateTime.Now.ToString("HH:mm:ss")} show message!";
var task = new Task(reMsg);
int span = 5;
var shaking = new Shaking(span);
//showMsg();
//await Task.Delay(5 * 1000);
//shaking.Run(showMsg);
Console.WriteLine($"以下方法调用3次,应该有两个输出,相隔{span}秒");
Console.WriteLine(reMsg());
shaking.Run(task);
task = new Task(reMsg);
shaking.Run(task);
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")} {span}秒后记录第二个输出");
Console.WriteLine(task.Result);
Console.WriteLine("任务完成!");
}
}
}