2021-03-18 16:38:34 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Coroutine;
|
|
|
|
|
using NUnit.Framework;
|
2021-03-18 14:37:15 +01:00
|
|
|
|
|
2021-03-18 16:38:34 +01:00
|
|
|
|
namespace Tests {
|
|
|
|
|
public class EventBasedCoroutineTests {
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestEventBasedCoroutine() {
|
|
|
|
|
var counter = 0;
|
2021-03-18 14:37:15 +01:00
|
|
|
|
var myEvent = new Event();
|
2021-03-18 16:38:34 +01:00
|
|
|
|
|
|
|
|
|
IEnumerator<Wait> OnEventTriggered() {
|
2021-03-18 14:37:15 +01:00
|
|
|
|
counter++;
|
|
|
|
|
yield return new Wait(myEvent);
|
|
|
|
|
counter++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cr = CoroutineHandler.Start(OnEventTriggered());
|
|
|
|
|
Assert.AreEqual(1, counter, "instruction before yield is not executed.");
|
|
|
|
|
CoroutineHandler.RaiseEvent(myEvent);
|
|
|
|
|
Assert.AreEqual(2, counter, "instruction after yield is not executed.");
|
|
|
|
|
CoroutineHandler.RaiseEvent(myEvent);
|
|
|
|
|
Assert.AreEqual(2, counter, "instruction after yield is not executed.");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(true, cr.IsFinished, "Incorrect IsFinished value.");
|
|
|
|
|
Assert.AreEqual(false, cr.WasCanceled, "Incorrect IsCanceled value.");
|
|
|
|
|
Assert.AreEqual(cr.MoveNextCount, 2, "Incorrect MoveNextCount value.");
|
|
|
|
|
}
|
2021-03-18 16:38:34 +01:00
|
|
|
|
|
2021-03-18 14:37:15 +01:00
|
|
|
|
}
|
2021-03-18 16:38:34 +01:00
|
|
|
|
}
|