mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
Initial commit of SafeTimerTest, fixing bug where Trigger() was not behaving properly in net standard
This commit is contained in:
89
ICD.Common.Utils.Tests/Timers/SafeTimerTest.cs
Normal file
89
ICD.Common.Utils.Tests/Timers/SafeTimerTest.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using ICD.Common.Utils.Timers;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ICD.Common.Utils.Tests.Timers
|
||||
{
|
||||
[TestFixture]
|
||||
public sealed class SafeTimerTest
|
||||
{
|
||||
[Test]
|
||||
public void DisposeTest()
|
||||
{
|
||||
bool called = false;
|
||||
SafeTimer timer = SafeTimer.Stopped(() => called = true);
|
||||
|
||||
// Crestron timer tends to execute the callback on stop.
|
||||
timer.Dispose();
|
||||
Assert.IsFalse(called);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StoppedTest()
|
||||
{
|
||||
bool called = false;
|
||||
SafeTimer timer = SafeTimer.Stopped(() => called = true);
|
||||
|
||||
Assert.IsFalse(called);
|
||||
|
||||
timer.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StopTest()
|
||||
{
|
||||
bool called = false;
|
||||
SafeTimer timer = SafeTimer.Stopped(() => called = true);
|
||||
timer.Reset(100);
|
||||
timer.Stop();
|
||||
|
||||
ThreadingUtils.Sleep(200);
|
||||
|
||||
Assert.IsFalse(called);
|
||||
|
||||
timer.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TriggerTest()
|
||||
{
|
||||
bool called = false;
|
||||
SafeTimer timer = SafeTimer.Stopped(() => called = true);
|
||||
|
||||
timer.Trigger();
|
||||
|
||||
Assert.IsTrue(called);
|
||||
|
||||
timer.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResetTest()
|
||||
{
|
||||
int called = 0;
|
||||
SafeTimer timer = SafeTimer.Stopped(() => called++);
|
||||
|
||||
timer.Reset(10);
|
||||
|
||||
ThreadingUtils.Sleep(50);
|
||||
|
||||
Assert.AreEqual(1, called);
|
||||
|
||||
timer.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResetRepeatTest()
|
||||
{
|
||||
int called = 0;
|
||||
SafeTimer timer = SafeTimer.Stopped(() => called++);
|
||||
|
||||
timer.Reset(10, 10);
|
||||
|
||||
ThreadingUtils.Sleep(50);
|
||||
|
||||
Assert.AreEqual(4, called, 1);
|
||||
|
||||
timer.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user