Added event based test.

This commit is contained in:
Zaafar 2021-03-18 09:37:15 -04:00
parent bda1e21ea3
commit 1c97d17ef7
2 changed files with 38 additions and 4 deletions

View file

@ -0,0 +1,34 @@
using Coroutine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace CoroutineTests
{
[TestClass]
public class EventBasedCoroutineTests
{
[TestMethod]
public void TestEventBasedCoroutine()
{
int counter = 0;
var myEvent = new Event();
IEnumerator<Wait> OnEventTriggered()
{
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.");
}
}
}

View file

@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Coroutine;
namespace CoroutineTests
{
using Coroutine;
using System.Collections.Generic;
using System.Threading;
[TestClass]
public class TimeBasedCoroutineTests
{