public void ItShouldBePossibleToWaitForATaskToCompleteWithinTimeout()
        {
            _taskStarted = false;
            _taskRun     = false;
            _completed   = false;
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(CoroutineWaitingHavingTimeoutNotExploding());

            var target = new CoroutinesManager();

            target.TestInitialize();
            var rft = new RunnerForTest(target);

            target.StartCoroutine(coroutine.Object);
            target.TestRun();
            rft.RunCycleFor(200);
            target.TestRun();

            Assert.IsTrue(_taskStarted);
            Assert.IsTrue(_taskRun);
            Assert.IsTrue(_completed);
            coroutine.Verify(a => a.OnError(It.IsAny <Exception>()), Times.Never);
        }
Ejemplo n.º 2
0
        public void ExceptionShouldNotTerminateCoroutineWhenOnErrorReturnFalse()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(ExecuteWithErrorAndContinue);

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            _shouldThrowExceptionOnExecuteWithErrorAndContinue = true;
            target.TestRun(2);
            _shouldThrowExceptionOnExecuteWithErrorAndContinue = false;
            target.TestRun(2);

            coroutine.Verify(a => a.OnError(It.IsAny <NotImplementedException>()), Times.Once);
            coroutine.Verify(a => a.OnDestroy(), Times.Never);
        }
Ejemplo n.º 3
0
        public void PausingRunnerShouldPauseAllCoroutines()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(Execute(10));

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            target.TestRun();
            target.Pause();
            target.TestRunWhenPaused(10);
            target.Restart();
            target.TestRun();

            Assert.AreEqual(_cyclesRunSimpleExecute, 2);
            coroutine.Verify(a => a.OnDestroy(), Times.Never);
        }
        public void WaitForTaskToComplete()
        {
            const int waitTime  = 100;
            var       coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(CoroutineWaitingForTask(waitTime));

            var target = new CoroutinesManager();

            target.TestInitialize();
            var rft = new RunnerForTest(target);

            target.StartCoroutine(coroutine.Object);
            target.TestRun();                   //Initialize
            rft.RunCycleFor(waitTime * 2);
            target.TestRun();                   //CleanUp

            Assert.IsTrue(_taskStarted);
            Assert.IsTrue(_taskRun);
            Assert.IsTrue(_completed);
        }
        public void ItShouldBePossibleToWaitForEnEntireForEach()
        {
            _completed = false;
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(CoroutineWaitingForSeveralItems(10));

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            target.TestRun(3);                  //Initialize the call
            target.TestRun(20);                 //Set results

            Assert.AreEqual(10, _partialCoroutineResultsCount);
            Assert.IsTrue(_completed);

            target.TestRun(2);                  //Copy the completed
            Assert.AreEqual(10, _coroutineResultsCount);
        }
Ejemplo n.º 6
0
        public void ExceptionInNestedCallShouldNotTerminateWithOnErforFalse()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(ExecuteNestedAndThrowInsideNested(10));

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            target.TestRun(6);

            Assert.AreEqual(6, _cyclesRunExecuteNested);

            coroutine.Verify(a => a.OnError(It.IsAny <NotImplementedException>()), Times.Once);
            coroutine.Verify(a => a.OnDestroy(), Times.Never);

            target.TestRun(6);
            coroutine.Verify(a => a.OnError(It.IsAny <NotImplementedException>()), Times.Exactly(2));
        }
Ejemplo n.º 7
0
        public void StoppingRunnerShouldSendManagerStoppedExceptionToAllCoroutinesDestroyingEvenIfNotRequired()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(Execute(3));
            coroutine.Setup(a => a.OnError(It.IsAny <Exception>()))
            .Returns(false);


            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            target.TestRun();
            target.Stop();
            target.TestRun();

            coroutine.Verify(a => a.OnError(It.IsAny <ManagerStoppedException>()), Times.Once);
            coroutine.Verify(a => a.OnDestroy(), Times.Once);
        }
Ejemplo n.º 8
0
        public void NotWaitingItShouldBePossibleToWaitForATaskToCompleteWithTimeout()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(NotWaitingCoroutineWaitingHavingTimeoutNotExploding());
            coroutine.Setup(o => o.OnError(It.IsAny <Exception>())).Returns(true);

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            Task.Factory.StartNew(() => target.TestRun(3));
            Thread.Sleep(300);
            target.TestRun();

            coroutine.Verify(a => a.OnError(It.IsAny <Exception>()), Times.Never);
            Assert.IsTrue(_taskStarted);
            Assert.IsTrue(_taskRun);
            Assert.IsTrue(_completed);
        }
Ejemplo n.º 9
0
        public void NestedCallsToCoroutinesShouldWork()
        {
            _cyclesRunSimpleExecute = 0;
            _cyclesRunExecuteNested = 0;
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(ExecuteNested(10));

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);

            target.TestRun(20);

            Assert.AreEqual(10, _cyclesRunSimpleExecute);
            Assert.AreEqual(10, _cyclesRunExecuteNested);
            coroutine.Verify(a => a.OnDestroy(), Times.Never);

            target.TestRun();
            coroutine.Verify(a => a.OnDestroy(), Times.Once);
        }
        public void ItShouldBePossibleToWaitForCoroutineCallingFunctionThatWait()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(CoroutineWaitingForSingleResult(10));

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            target.TestRun(20);

            Assert.AreEqual("RESULT", _coroutineSingleResult);
        }
Ejemplo n.º 11
0
        public void WhenTerminatingShouldBeCalledOnDestroy()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(ExecuteAndTerminate);

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);

            target.TestRun();

            coroutine.Verify(a => a.OnDestroy(), Times.Once);
        }
Ejemplo n.º 12
0
        public void RunnerShouldCallExecute()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(Execute());

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);

            target.TestRun();

            coroutine.Verify(a => a.Execute(), Times.Once);
        }
Ejemplo n.º 13
0
        public void ExceptionOnFirstyCycleShouldBeHandledAndRoutineTerminatedForcibly()
        {
            var coroutine = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(ExecuteAndThrowInstantly);

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);

            target.TestRun();

            coroutine.Verify(a => a.OnError(It.IsAny <NotImplementedException>()), Times.Once);
            coroutine.Verify(a => a.OnDestroy(), Times.Once);
        }
Ejemplo n.º 14
0
        public void NotWaitingItShouldBePossibleToWaitForCoroutineCallingFunctionThatWait()
        {
            const int items        = 10;
            const int itemsAndWait = items * 2;
            var       coroutine    = new Mock <ICoroutineThread>();

            coroutine.Setup(a => a.Execute())
            .Returns(NotWaitingCoroutineWaitingForSingleResult(items));

            var target = new CoroutinesManager();

            target.TestInitialize();

            target.StartCoroutine(coroutine.Object);
            target.TestRun(itemsAndWait);

            Assert.AreEqual("RESULT", _coroutineSingleResult);
        }
Ejemplo n.º 15
0
 public void RunCycle(int count = 1, bool considerPause = false)
 {
     _runner.TestRun(count, considerPause);
 }