sharee.bike-App/TestShareeLib/ViewModel/TestPollingUpdateTask.cs
2022-06-17 14:17:58 +02:00

45 lines
1.3 KiB
C#

using NUnit.Framework;
using System.Threading.Tasks;
using TINK.ViewModel;
namespace TestTINKLib.Fixtures.ObjectTests
{
[TestFixture]
public class TestPollingUpdateTask
{
/// <summary>
/// Verify that no exception is thrown when invoking Terminate.
/// </summary>
[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();
}
}
}