Files
ICD.Common.Utils/ICD.Common.Utils.Tests/ThreadingUtilsTest.cs
2017-10-02 09:46:17 -04:00

42 lines
867 B
C#

using System;
using NUnit.Framework;
namespace ICD.Common.Utils.Tests
{
[TestFixture]
public sealed class ThreadingUtilsTest
{
[Test]
public void Sleep()
{
DateTime now = IcdEnvironment.GetLocalTime();
ThreadingUtils.Sleep(1000);
DateTime now2 = IcdEnvironment.GetLocalTime();
Assert.AreEqual(1000, (now2 - now).TotalMilliseconds, 100);
}
[Test]
public void SafeInvokeTest()
{
bool result = false;
ThreadingUtils.SafeInvoke(() => { ThreadingUtils.Sleep(100); result = true; });
Assert.IsFalse(result);
ThreadingUtils.Sleep(1000);
Assert.IsTrue(result);
}
[Test]
public void SafeInvokeParamTest()
{
bool result = false;
ThreadingUtils.SafeInvoke(p => { ThreadingUtils.Sleep(100); result = p; }, true);
Assert.IsFalse(result);
ThreadingUtils.Sleep(1000);
Assert.IsTrue(result);
}
}
}