Begin adding tests for ThreadingUtils and SafeCriticalSection

This commit is contained in:
Chris Cameron
2017-10-01 19:14:25 -04:00
parent ab283cde4e
commit 206511b409
2 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
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(() => result = true);
Assert.IsFalse(result);
ThreadingUtils.Sleep(1000);
Assert.IsTrue(result);
}
[Test]
public void SafeInvokeParamTest()
{
bool result = false;
ThreadingUtils.SafeInvoke(p => result = p, true);
Assert.IsFalse(result);
ThreadingUtils.Sleep(1000);
Assert.IsTrue(result);
}
}
}