mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-02 22:35:00 +00:00
42 lines
867 B
C#
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);
|
|
}
|
|
}
|
|
}
|