mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using ShareeBike.ViewModel;
|
|
|
|
namespace SharedBusinessLogic.Tests.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();
|
|
}
|
|
}
|
|
}
|