mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-22 23:26:31 +01:00
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
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();
|
|
}
|
|
}
|
|
}
|