using NUnit.Framework; using System.Threading.Tasks; using TINK.ViewModel; namespace TestTINKLib.Fixtures.ObjectTests { [TestFixture] public class TestPollingUpdateTask { /// /// Verify that no exception is thrown when invoking Terminate. /// [Test] public async Task TestCtorPollingOff() { var task = new PollingUpdateTask(() => throw new System.Exception("This must not be called."), null); await task.Terminate(); } [Test] public async Task TestCtorPollingOn() { int index = 0; var task = new PollingUpdateTask(() => index++, new System.TimeSpan(10)); System.Threading.SpinWait.SpinUntil(() => index > 2); await task.Terminate(); Assert.That(index, Is.AtLeast(3), "Delegate which increments index must be called."); } [Test] public void TestTerminateRepeated() { var tasks = new PollingUpdateTask(async () => await Task.Delay(1000), new System.TimeSpan(0, 0, 2)); tasks.Terminate().Wait(); // Verify that calling terminate twice does not lead to hang of call. tasks.Terminate().Wait(); } } }